🎨 Reorganize back-end code
This commit is contained in:
34
backend/api/routers/line.py
Normal file
34
backend/api/routers/line.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi_cache.decorator import cache
|
||||
|
||||
from models import Line
|
||||
from schemas import Line as LineSchema, TransportMode
|
||||
|
||||
|
||||
router = APIRouter(prefix="/line", tags=["line"])
|
||||
|
||||
|
||||
@router.get("/{line_id}", response_model=LineSchema)
|
||||
@cache(namespace="line")
|
||||
async def get_line(line_id: int) -> LineSchema:
|
||||
line: Line | None = await Line.get_by_id(line_id)
|
||||
|
||||
if line is None:
|
||||
raise HTTPException(status_code=404, detail=f'Line "{line_id}" not found')
|
||||
|
||||
return LineSchema(
|
||||
id=line.id,
|
||||
shortName=line.short_name,
|
||||
name=line.name,
|
||||
status=line.status,
|
||||
transportMode=TransportMode.from_idfm_transport_mode(
|
||||
line.transport_mode, line.transport_submode
|
||||
),
|
||||
backColorHexa=line.colour_web_hexa,
|
||||
foreColorHexa=line.text_colour_hexa,
|
||||
operatorId=line.operator_id,
|
||||
accessibility=line.accessibility,
|
||||
visualSignsAvailable=line.visual_signs_available,
|
||||
audibleSignsAvailable=line.audible_signs_available,
|
||||
stopIds=[stop.id for stop in line.stops],
|
||||
)
|
Reference in New Issue
Block a user