fids/gateway/src/api/schemas/flight.py

46 lines
1021 B
Python

from datetime import datetime
from typing import Optional
from pydantic import BaseModel, validator
class Flight(BaseModel):
id: int
flight_code: str
status: str
origin: str
destination: str
departure_time: str
arrival_time: str
gate: str = None
@validator("departure_time", "arrival_time", pre=True, always=True)
def parse_datetime(cls, value):
if isinstance(value, datetime):
return value.strftime("%Y-%m-%d %I:%M %p")
return value
class FlightCreate(BaseModel):
flight_code: str
status: str
origin: str
destination: str
departure_time: str
arrival_time: str
gate: str = None
class FlightStatusUpdate(BaseModel):
status: str
class FlightUpdate(BaseModel):
flight_code: Optional[str] = None
status: Optional[str] = None
origin: Optional[str] = None
destination: Optional[str] = None
departure_time: Optional[str] = None
arrival_time: Optional[str] = None
gate: Optional[str] = None