Major refactor WIP
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
from fastapi import APIRouter
|
||||
from app.api.endpoints import auth, pprs, public, aircraft, airport, local_flights, departures, arrivals, circuits, journal, overflights, public_book
|
||||
from app.api.endpoints import auth, pprs, public, aircraft, airport, local_flights, departures, arrivals, circuits, journal, overflights, public_book, movements
|
||||
|
||||
api_router = APIRouter()
|
||||
|
||||
@@ -11,6 +11,7 @@ api_router.include_router(arrivals.router, prefix="/arrivals", tags=["arrivals"]
|
||||
api_router.include_router(overflights.router, prefix="/overflights", tags=["overflights"])
|
||||
api_router.include_router(circuits.router, prefix="/circuits", tags=["circuits"])
|
||||
api_router.include_router(journal.router, prefix="/journal", tags=["journal"])
|
||||
api_router.include_router(movements.router, prefix="/movements", tags=["movements"])
|
||||
api_router.include_router(public.router, prefix="/public", tags=["public"])
|
||||
api_router.include_router(public_book.router, prefix="/public-book", tags=["public_booking"])
|
||||
api_router.include_router(aircraft.router, prefix="/aircraft", tags=["aircraft"])
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
from typing import List, Optional
|
||||
from fastapi import APIRouter, Depends, HTTPException, status
|
||||
from sqlalchemy.orm import Session
|
||||
from datetime import date
|
||||
from app.api.deps import get_db, get_current_read_user
|
||||
from app.crud.crud_movement import movement as crud_movement
|
||||
from app.schemas.movement import Movement
|
||||
from app.models.ppr import User
|
||||
from app.models.movement import MovementType
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.get("/", response_model=List[Movement])
|
||||
async def get_movements(
|
||||
skip: int = 0,
|
||||
limit: int = 100,
|
||||
movement_type: Optional[MovementType] = None,
|
||||
aircraft_registration: Optional[str] = None,
|
||||
date_from: Optional[date] = None,
|
||||
date_to: Optional[date] = None,
|
||||
entity_type: Optional[str] = None,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_read_user)
|
||||
):
|
||||
"""Get movement records with optional filtering"""
|
||||
movements = crud_movement.get_multi(
|
||||
db, skip=skip, limit=limit, movement_type=movement_type,
|
||||
aircraft_registration=aircraft_registration, date_from=date_from,
|
||||
date_to=date_to, entity_type=entity_type
|
||||
)
|
||||
return movements
|
||||
|
||||
|
||||
@router.get("/{movement_id}", response_model=Movement)
|
||||
async def get_movement(
|
||||
movement_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_read_user)
|
||||
):
|
||||
"""Get a specific movement record"""
|
||||
movement = crud_movement.get(db, movement_id=movement_id)
|
||||
if not movement:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND,
|
||||
detail="Movement record not found"
|
||||
)
|
||||
return movement
|
||||
@@ -5,7 +5,11 @@ from datetime import date
|
||||
from app.api.deps import get_db, get_current_read_user, get_current_operator_user
|
||||
from app.crud.crud_ppr import ppr as crud_ppr
|
||||
from app.crud.crud_journal import journal as crud_journal
|
||||
from app.crud.crud_arrival import arrival as crud_arrival
|
||||
from app.crud.crud_departure import departure as crud_departure
|
||||
from app.schemas.ppr import PPR, PPRCreate, PPRUpdate, PPRStatus, PPRStatusUpdate, Journal
|
||||
from app.schemas.arrival import ArrivalCreate
|
||||
from app.schemas.departure import DepartureCreate
|
||||
from app.models.ppr import User
|
||||
from app.core.utils import get_client_ip
|
||||
from app.core.email import email_service
|
||||
@@ -373,4 +377,78 @@ async def get_ppr_journal(
|
||||
detail="PPR record not found"
|
||||
)
|
||||
|
||||
return crud_journal.get_by_ppr_id(db, ppr_id=ppr_id)
|
||||
return crud_journal.get_by_ppr_id(db, ppr_id=ppr_id)
|
||||
|
||||
|
||||
@router.post("/{ppr_id}/activate")
|
||||
async def activate_ppr(
|
||||
request: Request,
|
||||
ppr_id: int,
|
||||
db: Session = Depends(get_db),
|
||||
current_user: User = Depends(get_current_operator_user)
|
||||
):
|
||||
"""Activate a PPR by creating BOOKED_IN arrival and (if out_to set) BOOKED_OUT departure records."""
|
||||
db_ppr = crud_ppr.get(db, ppr_id=ppr_id)
|
||||
if not db_ppr:
|
||||
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="PPR record not found")
|
||||
|
||||
if db_ppr.status not in (PPRStatus.NEW, PPRStatus.CONFIRMED):
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_400_BAD_REQUEST,
|
||||
detail=f"PPR cannot be activated in its current state ({db_ppr.status.value})"
|
||||
)
|
||||
|
||||
client_ip = get_client_ip(request)
|
||||
username = current_user.username
|
||||
|
||||
# Create INBOUND arrival (ADMIN submitted_via sets status to INBOUND)
|
||||
in_from = (db_ppr.in_from or "ZZZZ")[:4].upper()
|
||||
arrival_in = ArrivalCreate(
|
||||
registration=db_ppr.ac_reg,
|
||||
type=db_ppr.ac_type,
|
||||
callsign=db_ppr.ac_call,
|
||||
pob=db_ppr.pob_in,
|
||||
in_from=in_from,
|
||||
eta=db_ppr.eta,
|
||||
notes=db_ppr.notes,
|
||||
submitted_via="ADMIN"
|
||||
)
|
||||
new_arrival = crud_arrival.create(db, obj_in=arrival_in, created_by=username, submitted_via="ADMIN", user_ip=client_ip)
|
||||
|
||||
# Create PENDING departure linked to this arrival (only visible once arrival lands)
|
||||
new_departure = None
|
||||
if db_ppr.out_to:
|
||||
departure_in = DepartureCreate(
|
||||
registration=db_ppr.ac_reg,
|
||||
type=db_ppr.ac_type,
|
||||
callsign=db_ppr.ac_call,
|
||||
pob=db_ppr.pob_out if db_ppr.pob_out else db_ppr.pob_in,
|
||||
out_to=db_ppr.out_to,
|
||||
etd=db_ppr.etd,
|
||||
notes=db_ppr.notes,
|
||||
arrival_id=new_arrival.id,
|
||||
)
|
||||
new_departure = crud_departure.create(db, obj_in=departure_in, created_by=username, submitted_via="ADMIN", user_ip=client_ip)
|
||||
|
||||
# Mark PPR as ACTIVATED — removes it from Today's PPR and pending arrivals displays
|
||||
crud_ppr.update_status(db, ppr_id=ppr_id, status=PPRStatus.ACTIVATED, user=username, user_ip=client_ip)
|
||||
|
||||
# Broadcast WebSocket update
|
||||
if hasattr(request.app.state, 'connection_manager'):
|
||||
await request.app.state.connection_manager.broadcast({
|
||||
"type": "ppr_activated",
|
||||
"data": {
|
||||
"ppr_id": ppr_id,
|
||||
"arrival_id": new_arrival.id,
|
||||
"departure_id": new_departure.id if new_departure else None
|
||||
}
|
||||
})
|
||||
|
||||
return {
|
||||
"arrival_id": new_arrival.id,
|
||||
"departure_id": new_departure.id if new_departure else None,
|
||||
"message": (
|
||||
f"PPR activated: arrival #{new_arrival.id} created"
|
||||
+ (f", departure #{new_departure.id} queued (will appear when aircraft lands)" if new_departure else "")
|
||||
)
|
||||
}
|
||||
@@ -6,6 +6,9 @@ from app.models.arrival import Arrival, ArrivalStatus
|
||||
from app.schemas.arrival import ArrivalCreate, ArrivalUpdate, ArrivalStatusUpdate
|
||||
from app.models.journal import EntityType
|
||||
from app.crud.crud_journal import journal
|
||||
from app.crud.crud_movement import movement as movement_crud
|
||||
from app.schemas.movement import MovementCreate
|
||||
from app.models.movement import MovementType
|
||||
|
||||
|
||||
class CRUDArrival:
|
||||
@@ -155,6 +158,41 @@ class CRUDArrival:
|
||||
db.commit()
|
||||
db.refresh(db_obj)
|
||||
|
||||
# Create movement record if applicable
|
||||
if status == ArrivalStatus.LANDED and db_obj.landed_dt:
|
||||
movement_data = MovementCreate(
|
||||
movement_type=MovementType.LANDING,
|
||||
aircraft_registration=db_obj.registration,
|
||||
aircraft_type=db_obj.type,
|
||||
callsign=db_obj.callsign,
|
||||
timestamp=db_obj.landed_dt,
|
||||
entity_type="ARRIVAL",
|
||||
entity_id=arrival_id,
|
||||
from_location=db_obj.in_from,
|
||||
created_by=user,
|
||||
ip_address=user_ip
|
||||
)
|
||||
movement_crud.create(db, movement_data)
|
||||
|
||||
# Promote any PENDING departure linked to this arrival to BOOKED_OUT
|
||||
from app.models.departure import Departure as DepartureModel, DepartureStatus as DepStatus
|
||||
pending_dep = db.query(DepartureModel).filter(
|
||||
DepartureModel.arrival_id == arrival_id,
|
||||
DepartureModel.status == DepStatus.PENDING
|
||||
).first()
|
||||
if pending_dep:
|
||||
pending_dep.status = DepStatus.BOOKED_OUT
|
||||
db.add(pending_dep)
|
||||
db.commit()
|
||||
journal.log_change(
|
||||
db,
|
||||
EntityType.ARRIVAL,
|
||||
arrival_id,
|
||||
f"Linked departure #{pending_dep.id} promoted to BOOKED_OUT on landing",
|
||||
user,
|
||||
user_ip
|
||||
)
|
||||
|
||||
# Log status change in journal
|
||||
journal.log_change(
|
||||
db,
|
||||
|
||||
@@ -6,6 +6,11 @@ from app.models.circuit import Circuit
|
||||
from app.schemas.circuit import CircuitCreate, CircuitUpdate
|
||||
from app.models.journal import EntityType
|
||||
from app.crud.crud_journal import journal
|
||||
from app.crud.crud_movement import movement as movement_crud
|
||||
from app.schemas.movement import MovementCreate
|
||||
from app.models.movement import MovementType
|
||||
from app.crud.crud_local_flight import local_flight as crud_local_flight
|
||||
from app.crud.crud_arrival import arrival as crud_arrival
|
||||
|
||||
|
||||
class CRUDCircuit:
|
||||
@@ -56,6 +61,39 @@ class CRUDCircuit:
|
||||
user_ip
|
||||
)
|
||||
|
||||
# Create TOUCH_AND_GO movement
|
||||
if obj_in.local_flight_id:
|
||||
flight = crud_local_flight.get(db, obj_in.local_flight_id)
|
||||
if flight:
|
||||
movement_data = MovementCreate(
|
||||
movement_type=MovementType.TOUCH_AND_GO,
|
||||
aircraft_registration=flight.registration,
|
||||
aircraft_type=flight.type,
|
||||
callsign=flight.callsign,
|
||||
timestamp=obj_in.circuit_timestamp,
|
||||
entity_type="LOCAL_FLIGHT",
|
||||
entity_id=obj_in.local_flight_id,
|
||||
created_by=user,
|
||||
ip_address=user_ip
|
||||
)
|
||||
movement_crud.create(db, movement_data)
|
||||
elif obj_in.arrival_id:
|
||||
arrival = crud_arrival.get(db, obj_in.arrival_id)
|
||||
if arrival:
|
||||
movement_data = MovementCreate(
|
||||
movement_type=MovementType.TOUCH_AND_GO,
|
||||
aircraft_registration=arrival.registration,
|
||||
aircraft_type=arrival.type,
|
||||
callsign=arrival.callsign,
|
||||
timestamp=obj_in.circuit_timestamp,
|
||||
entity_type="ARRIVAL",
|
||||
entity_id=obj_in.arrival_id,
|
||||
from_location=arrival.in_from,
|
||||
created_by=user,
|
||||
ip_address=user_ip
|
||||
)
|
||||
movement_crud.create(db, movement_data)
|
||||
|
||||
return db_obj
|
||||
|
||||
def update(self, db: Session, db_obj: Circuit, obj_in: CircuitUpdate, user: str = "system", user_ip: Optional[str] = None) -> Circuit:
|
||||
|
||||
@@ -6,6 +6,9 @@ from app.models.departure import Departure, DepartureStatus
|
||||
from app.schemas.departure import DepartureCreate, DepartureUpdate, DepartureStatusUpdate
|
||||
from app.models.journal import EntityType
|
||||
from app.crud.crud_journal import journal
|
||||
from app.crud.crud_movement import movement as movement_crud
|
||||
from app.schemas.movement import MovementCreate
|
||||
from app.models.movement import MovementType
|
||||
|
||||
|
||||
class CRUDDeparture:
|
||||
@@ -57,9 +60,18 @@ class CRUDDeparture:
|
||||
if submitted_via == SubmissionSource.ADMIN:
|
||||
initial_status = DepartureStatus.GROUND
|
||||
contact_dt = func.now() # Set contact_dt to creation time for admin submissions
|
||||
|
||||
|
||||
obj_data = obj_in.dict()
|
||||
arrival_id = obj_data.pop('arrival_id', None)
|
||||
|
||||
# If arrival_id is provided this is a PPR-linked departure — stay PENDING until arrival lands
|
||||
if arrival_id is not None:
|
||||
initial_status = DepartureStatus.PENDING
|
||||
contact_dt = None
|
||||
|
||||
db_obj = Departure(
|
||||
**obj_in.dict(),
|
||||
**obj_data,
|
||||
arrival_id=arrival_id,
|
||||
created_by=created_by,
|
||||
status=initial_status,
|
||||
contact_dt=contact_dt,
|
||||
@@ -149,6 +161,22 @@ class CRUDDeparture:
|
||||
db.commit()
|
||||
db.refresh(db_obj)
|
||||
|
||||
# Create movement record if applicable
|
||||
if db_obj.takeoff_dt and status == DepartureStatus.LOCAL:
|
||||
movement_data = MovementCreate(
|
||||
movement_type=MovementType.TAKEOFF,
|
||||
aircraft_registration=db_obj.registration,
|
||||
aircraft_type=db_obj.type,
|
||||
callsign=db_obj.callsign,
|
||||
timestamp=db_obj.takeoff_dt,
|
||||
entity_type="DEPARTURE",
|
||||
entity_id=departure_id,
|
||||
to_location=db_obj.out_to,
|
||||
created_by=user,
|
||||
ip_address=user_ip
|
||||
)
|
||||
movement_crud.create(db, movement_data)
|
||||
|
||||
# Log status change in journal
|
||||
journal.log_change(
|
||||
db,
|
||||
|
||||
@@ -7,6 +7,9 @@ from app.schemas.local_flight import LocalFlightCreate, LocalFlightUpdate, Local
|
||||
from app.models.journal import EntityType
|
||||
from app.models.circuit import Circuit
|
||||
from app.crud.crud_journal import journal
|
||||
from app.crud.crud_movement import movement as movement_crud
|
||||
from app.schemas.movement import MovementCreate
|
||||
from app.models.movement import MovementType
|
||||
|
||||
|
||||
class CRUDLocalFlight:
|
||||
@@ -186,9 +189,7 @@ class CRUDLocalFlight:
|
||||
db_obj.contact_dt = current_time
|
||||
elif status == LocalFlightStatus.DEPARTED:
|
||||
db_obj.departed_dt = current_time
|
||||
elif status == LocalFlightStatus.LOCAL:
|
||||
db_obj.takeoff_dt = current_time
|
||||
elif status == LocalFlightStatus.LANDED:
|
||||
elif status == LocalFlightStatus.LANDED and not db_obj.landed_dt:
|
||||
db_obj.landed_dt = current_time
|
||||
# Count circuits from the circuits table and populate the circuits column
|
||||
circuit_count = db.query(func.count(Circuit.id)).filter(
|
||||
@@ -196,10 +197,42 @@ class CRUDLocalFlight:
|
||||
).scalar()
|
||||
db_obj.circuits = circuit_count
|
||||
|
||||
# Takeoff: happens once when transitioning away from GROUND
|
||||
if old_status == LocalFlightStatus.GROUND and status in (LocalFlightStatus.DEPARTED, LocalFlightStatus.LOCAL, LocalFlightStatus.CIRCUIT) and not db_obj.takeoff_dt:
|
||||
db_obj.takeoff_dt = current_time
|
||||
|
||||
db.add(db_obj)
|
||||
db.commit()
|
||||
db.refresh(db_obj)
|
||||
|
||||
# Create movement record if applicable
|
||||
if db_obj.takeoff_dt and old_status == LocalFlightStatus.GROUND and status in (LocalFlightStatus.DEPARTED, LocalFlightStatus.LOCAL, LocalFlightStatus.CIRCUIT):
|
||||
movement_data = MovementCreate(
|
||||
movement_type=MovementType.TAKEOFF,
|
||||
aircraft_registration=db_obj.registration,
|
||||
aircraft_type=db_obj.type,
|
||||
callsign=db_obj.callsign,
|
||||
timestamp=db_obj.takeoff_dt,
|
||||
entity_type="LOCAL_FLIGHT",
|
||||
entity_id=flight_id,
|
||||
created_by=user,
|
||||
ip_address=user_ip
|
||||
)
|
||||
movement_crud.create(db, movement_data)
|
||||
if db_obj.landed_dt and status == LocalFlightStatus.LANDED:
|
||||
movement_data = MovementCreate(
|
||||
movement_type=MovementType.LANDING,
|
||||
aircraft_registration=db_obj.registration,
|
||||
aircraft_type=db_obj.type,
|
||||
callsign=db_obj.callsign,
|
||||
timestamp=db_obj.landed_dt,
|
||||
entity_type="LOCAL_FLIGHT",
|
||||
entity_id=flight_id,
|
||||
created_by=user,
|
||||
ip_address=user_ip
|
||||
)
|
||||
movement_crud.create(db, movement_data)
|
||||
|
||||
# Log status change in journal
|
||||
journal.log_change(
|
||||
db,
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
from typing import List, Optional
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import and_, func
|
||||
from datetime import date, datetime
|
||||
from app.models.movement import Movement, MovementType
|
||||
from app.schemas.movement import MovementCreate
|
||||
|
||||
|
||||
class CRUDMovement:
|
||||
def get(self, db: Session, movement_id: int) -> Optional[Movement]:
|
||||
return db.query(Movement).filter(Movement.id == movement_id).first()
|
||||
|
||||
def get_multi(
|
||||
self,
|
||||
db: Session,
|
||||
skip: int = 0,
|
||||
limit: int = 100,
|
||||
movement_type: Optional[MovementType] = None,
|
||||
aircraft_registration: Optional[str] = None,
|
||||
date_from: Optional[date] = None,
|
||||
date_to: Optional[date] = None,
|
||||
entity_type: Optional[str] = None
|
||||
) -> List[Movement]:
|
||||
query = db.query(Movement)
|
||||
|
||||
if movement_type:
|
||||
query = query.filter(Movement.movement_type == movement_type)
|
||||
|
||||
if aircraft_registration:
|
||||
query = query.filter(Movement.aircraft_registration.ilike(f"%{aircraft_registration}%"))
|
||||
|
||||
if date_from:
|
||||
query = query.filter(func.date(Movement.timestamp) >= date_from)
|
||||
|
||||
if date_to:
|
||||
query = query.filter(func.date(Movement.timestamp) <= date_to)
|
||||
|
||||
if entity_type:
|
||||
query = query.filter(Movement.entity_type == entity_type)
|
||||
|
||||
return query.order_by(Movement.timestamp.desc()).offset(skip).limit(limit).all()
|
||||
|
||||
def create(self, db: Session, obj_in: MovementCreate) -> Movement:
|
||||
db_obj = Movement(**obj_in.dict())
|
||||
db.add(db_obj)
|
||||
db.commit()
|
||||
db.refresh(db_obj)
|
||||
return db_obj
|
||||
|
||||
def get_movements_by_entity(self, db: Session, entity_type: str, entity_id: int) -> List[Movement]:
|
||||
return db.query(Movement).filter(
|
||||
and_(Movement.entity_type == entity_type, Movement.entity_id == entity_id)
|
||||
).order_by(Movement.timestamp).all()
|
||||
|
||||
def get_daily_movements(self, db: Session, target_date: date) -> List[Movement]:
|
||||
return db.query(Movement).filter(
|
||||
func.date(Movement.timestamp) == target_date
|
||||
).order_by(Movement.timestamp).all()
|
||||
|
||||
|
||||
movement = CRUDMovement()
|
||||
@@ -6,6 +6,9 @@ from app.models.overflight import Overflight, OverflightStatus
|
||||
from app.schemas.overflight import OverflightCreate, OverflightUpdate, OverflightStatusUpdate
|
||||
from app.models.journal import EntityType
|
||||
from app.crud.crud_journal import journal
|
||||
from app.crud.crud_movement import movement as movement_crud
|
||||
from app.schemas.movement import MovementCreate
|
||||
from app.models.movement import MovementType
|
||||
|
||||
|
||||
class CRUDOverflight:
|
||||
@@ -57,6 +60,21 @@ class CRUDOverflight:
|
||||
db.commit()
|
||||
db.refresh(db_obj)
|
||||
|
||||
# Create OVERFLIGHT movement if call_dt is set
|
||||
if db_obj.call_dt:
|
||||
movement_data = MovementCreate(
|
||||
movement_type=MovementType.OVERFLIGHT,
|
||||
aircraft_registration=db_obj.registration,
|
||||
aircraft_type=db_obj.type,
|
||||
timestamp=db_obj.call_dt,
|
||||
entity_type="OVERFLIGHT",
|
||||
entity_id=db_obj.id,
|
||||
from_location=db_obj.departure_airfield,
|
||||
to_location=db_obj.destination_airfield,
|
||||
created_by=created_by
|
||||
)
|
||||
movement_crud.create(db, movement_data)
|
||||
|
||||
# Log creation in journal
|
||||
journal.log_change(
|
||||
db,
|
||||
|
||||
@@ -15,6 +15,7 @@ from app.models.local_flight import LocalFlight
|
||||
from app.models.departure import Departure
|
||||
from app.models.arrival import Arrival
|
||||
from app.models.circuit import Circuit
|
||||
from app.models.movement import Movement
|
||||
|
||||
# Set up logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
@@ -17,6 +17,7 @@ class DepartureStatus(str, Enum):
|
||||
DEPARTED = "DEPARTED"
|
||||
LOCAL = "LOCAL"
|
||||
CANCELLED = "CANCELLED"
|
||||
PENDING = "PENDING"
|
||||
|
||||
|
||||
class Departure(Base):
|
||||
@@ -38,4 +39,5 @@ class Departure(Base):
|
||||
created_by = Column(String(16), nullable=True, index=True)
|
||||
submitted_via = Column(SQLEnum(SubmissionSource), nullable=False, default=SubmissionSource.ADMIN, index=True)
|
||||
pilot_email = Column(String(128), nullable=True) # For public submissions
|
||||
arrival_id = Column(BigInteger, nullable=True) # Linked arrival for PPR-activated departures
|
||||
updated_at = Column(DateTime, server_default=func.now(), onupdate=func.now(), nullable=False)
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
from sqlalchemy import Column, BigInteger, String, DateTime, Enum as SQLEnum, func, Index
|
||||
from enum import Enum
|
||||
from app.db.session import Base
|
||||
|
||||
class MovementType(str, Enum):
|
||||
TAKEOFF = "TAKEOFF" # Aircraft becomes airborne
|
||||
LANDING = "LANDING" # Aircraft touches down
|
||||
OVERFLIGHT = "OVERFLIGHT" # Aircraft passes through airspace (e.g., on call or QSY)
|
||||
GO_AROUND = "GO_AROUND" # Aircraft aborts landing and goes around
|
||||
TOUCH_AND_GO = "TOUCH_AND_GO" # Aircraft lands and immediately takes off again
|
||||
|
||||
class Movement(Base):
|
||||
__tablename__ = "movements"
|
||||
|
||||
id = Column(BigInteger, primary_key=True, autoincrement=True)
|
||||
movement_type = Column(SQLEnum(MovementType), nullable=False, index=True)
|
||||
aircraft_registration = Column(String(16), nullable=False, index=True)
|
||||
aircraft_type = Column(String(32), nullable=True)
|
||||
callsign = Column(String(16), nullable=True)
|
||||
timestamp = Column(DateTime, nullable=False, index=True) # Exact time of movement
|
||||
entity_type = Column(String(50), nullable=False, index=True) # PPR, LOCAL_FLIGHT, ARRIVAL, DEPARTURE, OVERFLIGHT
|
||||
entity_id = Column(BigInteger, nullable=False, index=True) # ID of the associated flight record
|
||||
to_location = Column(String(64), nullable=True) # Destination (TO) - populated based on movement type
|
||||
from_location = Column(String(64), nullable=True) # Origin (FROM) - populated based on movement type
|
||||
runway = Column(String(10), nullable=True) # Runway used (e.g., "10", "28", "04", "22")
|
||||
wind = Column(String(20), nullable=True) # Wind speed/direction (e.g., "280/25")
|
||||
pressure_setting = Column(String(20), nullable=True) # Pressure setting (e.g., "QNH1024", "QFE1013")
|
||||
created_by = Column(String(16), nullable=True, index=True) # User who triggered the movement
|
||||
ip_address = Column(String(45), nullable=True) # For audit
|
||||
notes = Column(String(255), nullable=True) # Optional context (e.g., runway used)
|
||||
created_at = Column(DateTime, nullable=False, server_default=func.current_timestamp())
|
||||
|
||||
# Composite index for efficient queries
|
||||
__table_args__ = (
|
||||
Index('idx_movement_lookup', 'entity_type', 'entity_id'),
|
||||
Index('idx_movement_time', 'timestamp', 'movement_type'),
|
||||
)
|
||||
@@ -11,6 +11,7 @@ class PPRStatus(str, Enum):
|
||||
LANDED = "LANDED"
|
||||
DELETED = "DELETED"
|
||||
DEPARTED = "DEPARTED"
|
||||
ACTIVATED = "ACTIVATED"
|
||||
|
||||
|
||||
class UserRole(str, Enum):
|
||||
|
||||
@@ -10,6 +10,7 @@ class DepartureStatus(str, Enum):
|
||||
DEPARTED = "DEPARTED"
|
||||
LOCAL = "LOCAL"
|
||||
CANCELLED = "CANCELLED"
|
||||
PENDING = "PENDING"
|
||||
|
||||
|
||||
class SubmissionSource(str, Enum):
|
||||
@@ -46,7 +47,7 @@ class DepartureBase(BaseModel):
|
||||
|
||||
|
||||
class DepartureCreate(DepartureBase):
|
||||
pass
|
||||
arrival_id: Optional[int] = None
|
||||
|
||||
|
||||
class DepartureUpdate(BaseModel):
|
||||
@@ -79,6 +80,7 @@ class Departure(DepartureBase):
|
||||
updated_at: datetime
|
||||
submitted_via: Optional[SubmissionSource] = None
|
||||
pilot_email: Optional[str] = None
|
||||
arrival_id: Optional[int] = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
||||
@@ -75,6 +75,7 @@ class LocalFlightUpdate(BaseModel):
|
||||
contact_dt: Optional[datetime] = None
|
||||
departed_dt: Optional[datetime] = None
|
||||
takeoff_dt: Optional[datetime] = None
|
||||
landed_dt: Optional[datetime] = None
|
||||
circuits: Optional[int] = None
|
||||
notes: Optional[str] = None
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
from datetime import datetime
|
||||
from app.models.movement import MovementType
|
||||
|
||||
|
||||
class MovementBase(BaseModel):
|
||||
movement_type: MovementType
|
||||
aircraft_registration: str
|
||||
aircraft_type: Optional[str] = None
|
||||
callsign: Optional[str] = None
|
||||
timestamp: datetime
|
||||
entity_type: str
|
||||
entity_id: int
|
||||
to_location: Optional[str] = None
|
||||
from_location: Optional[str] = None
|
||||
runway: Optional[str] = None
|
||||
wind: Optional[str] = None
|
||||
pressure_setting: Optional[str] = None
|
||||
created_by: Optional[str] = None
|
||||
ip_address: Optional[str] = None
|
||||
notes: Optional[str] = None
|
||||
|
||||
|
||||
class MovementCreate(MovementBase):
|
||||
pass
|
||||
|
||||
|
||||
class Movement(MovementBase):
|
||||
id: int
|
||||
created_at: datetime
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
@@ -11,6 +11,7 @@ class PPRStatus(str, Enum):
|
||||
LANDED = "LANDED"
|
||||
DELETED = "DELETED"
|
||||
DEPARTED = "DEPARTED"
|
||||
ACTIVATED = "ACTIVATED"
|
||||
|
||||
|
||||
class UserRole(str, Enum):
|
||||
|
||||
Reference in New Issue
Block a user