Files
rail-game/backend/app/repositories/stations.py
zwitschi fc1e874309
Some checks failed
Backend CI / lint-and-test (push) Failing after 2m15s
Frontend CI / lint-and-build (push) Successful in 1m1s
feat: Initialize frontend and backend structure with essential configurations
- Added TypeScript build info for frontend.
- Created Vite configuration for React application.
- Implemented pre-commit hook to run checks before commits.
- Set up PostgreSQL Dockerfile with PostGIS support and initialization scripts.
- Added database creation script for PostgreSQL with necessary extensions.
- Established Python project configuration with dependencies and development tools.
- Developed pre-commit script to enforce code quality checks for backend and frontend.
- Created PowerShell script to set up Git hooks path.
2025-10-11 15:25:32 +02:00

38 lines
1.1 KiB
Python

from __future__ import annotations
import sqlalchemy as sa
from sqlalchemy.orm import Session
from geoalchemy2.elements import WKTElement
from backend.app.db.models import Station
from backend.app.repositories.base import BaseRepository
from backend.app.models import StationCreate
class StationRepository(BaseRepository[Station]):
model = Station
def __init__(self, session: Session) -> None:
super().__init__(session)
def list_active(self) -> list[Station]:
statement = sa.select(self.model).where(self.model.is_active.is_(True))
return list(self.session.scalars(statement))
@staticmethod
def _point(latitude: float, longitude: float) -> WKTElement:
return WKTElement(f"POINT({longitude} {latitude})", srid=4326)
def create(self, data: StationCreate) -> Station:
station = Station(
name=data.name,
osm_id=data.osm_id,
code=data.code,
location=self._point(data.latitude, data.longitude),
elevation_m=data.elevation_m,
is_active=data.is_active,
)
self.session.add(station)
return station