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.
This commit is contained in:
37
backend/app/repositories/stations.py
Normal file
37
backend/app/repositories/stations.py
Normal file
@@ -0,0 +1,37 @@
|
||||
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
|
||||
Reference in New Issue
Block a user