124 lines
4.1 KiB
Python
124 lines
4.1 KiB
Python
from typing import List
|
|
from fastapi import APIRouter, Depends
|
|
from sqlalchemy.orm import Session
|
|
from app.api.deps import get_db
|
|
from app.crud.crud_ppr import ppr as crud_ppr
|
|
from app.crud.crud_local_flight import local_flight as crud_local_flight
|
|
from app.crud.crud_departure import departure as crud_departure
|
|
from app.crud.crud_arrival import arrival as crud_arrival
|
|
from app.schemas.ppr import PPRPublic
|
|
from app.models.local_flight import LocalFlightStatus
|
|
from app.models.departure import DepartureStatus
|
|
from app.models.arrival import ArrivalStatus
|
|
from datetime import date
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/arrivals")
|
|
async def get_public_arrivals(db: Session = Depends(get_db)):
|
|
"""Get today's arrivals for public display (PPR and local flights)"""
|
|
arrivals = crud_ppr.get_arrivals_today(db)
|
|
|
|
# Convert PPR arrivals to dictionaries
|
|
arrivals_list = []
|
|
for arrival in arrivals:
|
|
arrivals_list.append({
|
|
'ac_call': arrival.ac_call,
|
|
'ac_reg': arrival.ac_reg,
|
|
'ac_type': arrival.ac_type,
|
|
'in_from': arrival.in_from,
|
|
'eta': arrival.eta,
|
|
'landed_dt': arrival.landed_dt,
|
|
'status': arrival.status.value,
|
|
'isLocalFlight': False
|
|
})
|
|
|
|
# Add local flights with DEPARTED status
|
|
local_flights = crud_local_flight.get_multi(
|
|
db,
|
|
status=LocalFlightStatus.DEPARTED,
|
|
limit=1000
|
|
)
|
|
|
|
# Convert local flights to match the PPR format for display
|
|
for flight in local_flights:
|
|
arrivals_list.append({
|
|
'ac_call': flight.callsign or flight.registration,
|
|
'ac_reg': flight.registration,
|
|
'ac_type': flight.type,
|
|
'in_from': None,
|
|
'eta': flight.departure_dt,
|
|
'landed_dt': None,
|
|
'status': 'DEPARTED',
|
|
'isLocalFlight': True,
|
|
'flight_type': flight.flight_type.value
|
|
})
|
|
|
|
return arrivals_list
|
|
|
|
|
|
@router.get("/departures")
|
|
async def get_public_departures(db: Session = Depends(get_db)):
|
|
"""Get today's departures for public display (PPR, local flights, and departures to other airports)"""
|
|
departures = crud_ppr.get_departures_today(db)
|
|
|
|
# Convert PPR departures to dictionaries
|
|
departures_list = []
|
|
for departure in departures:
|
|
departures_list.append({
|
|
'ac_call': departure.ac_call,
|
|
'ac_reg': departure.ac_reg,
|
|
'ac_type': departure.ac_type,
|
|
'out_to': departure.out_to,
|
|
'etd': departure.etd,
|
|
'departed_dt': departure.departed_dt,
|
|
'status': departure.status.value,
|
|
'isLocalFlight': False,
|
|
'isDeparture': False
|
|
})
|
|
|
|
# Add local flights with BOOKED_OUT status
|
|
local_flights = crud_local_flight.get_multi(
|
|
db,
|
|
status=LocalFlightStatus.BOOKED_OUT,
|
|
limit=1000
|
|
)
|
|
|
|
# Convert local flights to match the PPR format for display
|
|
for flight in local_flights:
|
|
departures_list.append({
|
|
'ac_call': flight.callsign or flight.registration,
|
|
'ac_reg': flight.registration,
|
|
'ac_type': flight.type,
|
|
'out_to': None,
|
|
'etd': flight.booked_out_dt,
|
|
'departed_dt': None,
|
|
'status': 'BOOKED_OUT',
|
|
'isLocalFlight': True,
|
|
'flight_type': flight.flight_type.value,
|
|
'isDeparture': False
|
|
})
|
|
|
|
# Add departures to other airports with BOOKED_OUT status
|
|
departures_to_airports = crud_departure.get_multi(
|
|
db,
|
|
status=DepartureStatus.BOOKED_OUT,
|
|
limit=1000
|
|
)
|
|
|
|
# Convert departures to match the format for display
|
|
for dep in departures_to_airports:
|
|
departures_list.append({
|
|
'ac_call': dep.callsign or dep.registration,
|
|
'ac_reg': dep.registration,
|
|
'ac_type': dep.type,
|
|
'out_to': dep.out_to,
|
|
'etd': dep.booked_out_dt,
|
|
'departed_dt': None,
|
|
'status': 'BOOKED_OUT',
|
|
'isLocalFlight': False,
|
|
'isDeparture': True
|
|
})
|
|
|
|
return departures_list |