- 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.
38 lines
1.1 KiB
Python
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
|