import functools from fastapi import FastAPI, Depends from sqlmodel import Session from db import get_session from models.station import StationCreateRequest, StationCreateResponse, Station, StationListResponse, \ StationUpdateResponse, StationUpdateRequest from services import stationService app = FastAPI() @app.get("/stations/list") async def list_stations(session: Session = Depends(get_session)): result = stationService.list_stations(session) return [StationListResponse.model_validate(station) for station in result] @app.post("/stations/create", response_model=StationCreateResponse, status_code=200) async def create_station(station_data: StationCreateRequest, session: Session = Depends(get_session)) -> StationCreateResponse: station = stationService.create_station(session, station_data) return StationCreateResponse.model_validate(station) @app.patch("/stations/update", response_model=StationUpdateResponse, status_code=200) async def update_station(station_data: StationUpdateRequest, session: Session = Depends(get_session)): station = stationService.update_station(session, station_data) return StationUpdateResponse.model_validate(station) @app.delete("/stations/{station_id}", status_code=204) async def delete_station(station_id: int, session: Session = Depends(get_session)): stationService.delete_station(session, station_id) @app.get("/hello/{name}") async def say_hello(name: str): return {"message": f"Hello {name}"}