Commit often...

This commit is contained in:
James Pattinson
2025-10-23 16:43:01 +00:00
parent 981bb39888
commit b2f60322a1
5 changed files with 256 additions and 14 deletions

View File

@@ -152,6 +152,7 @@ async def update_ppr_status(
db,
ppr_id=ppr_id,
status=status_update.status,
timestamp=status_update.timestamp,
user=current_user.username,
user_ip=client_ip
)
@@ -169,7 +170,7 @@ async def update_ppr_status(
"id": ppr.id,
"ac_reg": ppr.ac_reg,
"status": ppr.status.value,
"timestamp": ppr.landed_dt.isoformat() if ppr.landed_dt else None
"timestamp": ppr.landed_dt.isoformat() if ppr.landed_dt else (ppr.departed_dt.isoformat() if ppr.departed_dt else None)
}
})

View File

@@ -110,6 +110,7 @@ class CRUDPPR:
db: Session,
ppr_id: int,
status: PPRStatus,
timestamp: Optional[datetime] = None,
user: str = "system",
user_ip: str = "127.0.0.1"
) -> Optional[PPRRecord]:
@@ -120,11 +121,12 @@ class CRUDPPR:
old_status = db_obj.status
db_obj.status = status
# Set timestamps based on status
# Set timestamps based on status - use provided timestamp or current time
current_time = timestamp if timestamp is not None else datetime.utcnow()
if status == PPRStatus.LANDED:
db_obj.landed_dt = datetime.utcnow()
db_obj.landed_dt = current_time
elif status == PPRStatus.DEPARTED:
db_obj.departed_dt = datetime.utcnow()
db_obj.departed_dt = current_time
db.add(db_obj)
db.commit()

View File

@@ -71,6 +71,7 @@ class PPRUpdate(BaseModel):
class PPRStatusUpdate(BaseModel):
status: PPRStatus
timestamp: Optional[datetime] = None
class PPRInDBBase(PPRBase):