👽️ Take the last IDFM format into account
This commit is contained in:
@@ -5,11 +5,7 @@ from typing import Sequence
|
||||
from fastapi import APIRouter, HTTPException
|
||||
from fastapi_cache.decorator import cache
|
||||
|
||||
from backend.idfm_interface import (
|
||||
Destinations as IdfmDestinations,
|
||||
IdfmInterface,
|
||||
TrainStatus,
|
||||
)
|
||||
from backend.idfm_interface import Destinations as IdfmDestinations, TrainStatus
|
||||
from backend.models import Stop, StopArea, StopShape
|
||||
from backend.schemas import (
|
||||
NextPassage as NextPassageSchema,
|
||||
@@ -106,7 +102,7 @@ async def get_next_passages(stop_id: int) -> NextPassagesSchema | None:
|
||||
|
||||
# re.match will return None if the given journey.LineRef.value is not valid.
|
||||
try:
|
||||
line_id_match = IdfmInterface.LINE_RE.match(journey.LineRef.value)
|
||||
line_id_match = idfm_interface.LINE_RE.match(journey.LineRef.value)
|
||||
line_id = int(line_id_match.group(1)) # type: ignore
|
||||
except (AttributeError, TypeError, ValueError) as err:
|
||||
raise HTTPException(
|
||||
@@ -163,32 +159,18 @@ async def get_stop_destinations(
|
||||
@router.get("/{stop_id}/shape")
|
||||
@cache(namespace="stop-shape")
|
||||
async def get_stop_shape(stop_id: int) -> StopShapeSchema | None:
|
||||
connection_area = None
|
||||
if (await Stop.get_by_id(stop_id)) is not None or (
|
||||
await StopArea.get_by_id(stop_id)
|
||||
) is not None:
|
||||
shape_id = stop_id
|
||||
|
||||
if (stop := await Stop.get_by_id(stop_id)) is not None:
|
||||
connection_area = stop.connection_area
|
||||
|
||||
elif (stop_area := await StopArea.get_by_id(stop_id)) is not None:
|
||||
connection_areas = {stop.connection_area for stop in stop_area.stops}
|
||||
connection_areas_len = len(connection_areas)
|
||||
if connection_areas_len == 1:
|
||||
connection_area = connection_areas.pop()
|
||||
|
||||
else:
|
||||
prefix = "More than one" if connection_areas_len else "No"
|
||||
msg = f"{prefix} connection area has been found for stop area #{stop_id}"
|
||||
raise HTTPException(status_code=500, detail=msg)
|
||||
|
||||
if (
|
||||
connection_area is not None
|
||||
and (shape := await StopShape.get_by_id(connection_area.id)) is not None
|
||||
):
|
||||
return StopShapeSchema(
|
||||
id=shape.id,
|
||||
type=shape.type,
|
||||
epsg3857_bbox=shape.epsg3857_bbox,
|
||||
epsg3857_points=shape.epsg3857_points,
|
||||
)
|
||||
if (shape := await StopShape.get_by_id(shape_id)) is not None:
|
||||
return StopShapeSchema(
|
||||
id=shape.id,
|
||||
type=shape.type,
|
||||
epsg3857_bbox=shape.epsg3857_bbox,
|
||||
epsg3857_points=shape.epsg3857_points,
|
||||
)
|
||||
|
||||
msg = f"No shape found for stop {stop_id}"
|
||||
raise HTTPException(status_code=404, detail=msg)
|
||||
|
Reference in New Issue
Block a user