🏷️ Fix some type issues (mypy)
This commit is contained in:
@@ -4,7 +4,11 @@ from typing import Sequence
|
||||
|
||||
from fastapi import APIRouter, HTTPException
|
||||
|
||||
from backend.idfm_interface import Destinations as IdfmDestinations, IdfmInterface
|
||||
from backend.idfm_interface import (
|
||||
Destinations as IdfmDestinations,
|
||||
IdfmInterface,
|
||||
TrainStatus,
|
||||
)
|
||||
from backend.models import Stop, StopArea, StopShape
|
||||
from backend.schemas import (
|
||||
NextPassage as NextPassageSchema,
|
||||
@@ -38,16 +42,20 @@ def optional_datetime_to_ts(dt: datetime | None) -> int | None:
|
||||
@router.get("/")
|
||||
async def get_stop(
|
||||
name: str = "", limit: int = 10
|
||||
) -> Sequence[StopAreaSchema | StopSchema]:
|
||||
) -> Sequence[StopAreaSchema | StopSchema] | None:
|
||||
|
||||
matching_stops = await Stop.get_by_name(name)
|
||||
if matching_stops is None:
|
||||
return None
|
||||
|
||||
formatted: list[StopAreaSchema | StopSchema] = []
|
||||
matching_stops = await Stop.get_by_name(name)
|
||||
|
||||
stop_areas: dict[int, StopArea] = {}
|
||||
stops: dict[int, Stop] = {}
|
||||
for stop in matching_stops:
|
||||
dst = stop_areas if isinstance(stop, StopArea) else stops
|
||||
dst[stop.id] = stop
|
||||
if isinstance(stop, StopArea):
|
||||
stop_areas[stop.id] = stop
|
||||
elif isinstance(stop, Stop):
|
||||
stops[stop.id] = stop
|
||||
|
||||
for stop_area in stop_areas.values():
|
||||
|
||||
@@ -121,8 +129,12 @@ async def get_next_passages(stop_id: int) -> NextPassagesSchema | None:
|
||||
arrivalPlatformName=arrivalPlatformName,
|
||||
aimedDepartTs=optional_datetime_to_ts(call.AimedDepartureTime),
|
||||
expectedDepartTs=optional_datetime_to_ts(call.ExpectedDepartureTime),
|
||||
arrivalStatus=call.ArrivalStatus.value,
|
||||
departStatus=call.DepartureStatus.value,
|
||||
arrivalStatus=call.ArrivalStatus
|
||||
if call.ArrivalStatus is not None
|
||||
else TrainStatus.unknown,
|
||||
departStatus=call.DepartureStatus
|
||||
if call.DepartureStatus is not None
|
||||
else TrainStatus.unknown,
|
||||
)
|
||||
|
||||
by_line_passages = by_line_by_dst_passages[line_id]
|
||||
@@ -131,7 +143,7 @@ async def get_next_passages(stop_id: int) -> NextPassagesSchema | None:
|
||||
by_line_passages[dst].append(next_passage)
|
||||
|
||||
return NextPassagesSchema(
|
||||
ts=service_delivery.ResponseTimestamp.timestamp(),
|
||||
ts=int(service_delivery.ResponseTimestamp.timestamp()),
|
||||
passages=by_line_by_dst_passages,
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user