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:
40
backend/app/repositories/trains.py
Normal file
40
backend/app/repositories/trains.py
Normal file
@@ -0,0 +1,40 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import sqlalchemy as sa
|
||||
from uuid import UUID
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from backend.app.db.models import Train
|
||||
from backend.app.repositories.base import BaseRepository
|
||||
from backend.app.models import TrainCreate
|
||||
|
||||
|
||||
class TrainRepository(BaseRepository[Train]):
|
||||
model = Train
|
||||
|
||||
def __init__(self, session: Session) -> None:
|
||||
super().__init__(session)
|
||||
|
||||
def list_all(self) -> list[Train]:
|
||||
statement = sa.select(self.model)
|
||||
return list(self.session.scalars(statement))
|
||||
|
||||
@staticmethod
|
||||
def _optional_uuid(value: UUID | str | None) -> UUID | None:
|
||||
if value is None:
|
||||
return None
|
||||
if isinstance(value, UUID):
|
||||
return value
|
||||
return UUID(str(value))
|
||||
|
||||
def create(self, data: TrainCreate) -> Train:
|
||||
train = Train(
|
||||
designation=data.designation,
|
||||
operator_id=self._optional_uuid(data.operator_id),
|
||||
home_station_id=self._optional_uuid(data.home_station_id),
|
||||
capacity=data.capacity,
|
||||
max_speed_kph=data.max_speed_kph,
|
||||
consist=data.consist,
|
||||
)
|
||||
self.session.add(train)
|
||||
return train
|
||||
Reference in New Issue
Block a user