diff --git a/api/database/flights.py b/api/database/flights.py index 09b09c2..a3252a6 100644 --- a/api/database/flights.py +++ b/api/database/flights.py @@ -71,7 +71,10 @@ async def update_flight(body: FlightCreateSchema, id: str) -> FlightDisplaySchem raise HTTPException(404, "Flight not found") updated_flight = await flight_collection.update_one({"_id": ObjectId(id)}, {"$set": body.model_dump()}) - return updated_flight.upserted_id + if updated_flight is None: + raise HTTPException(500, "Failed to update flight") + + return id async def delete_flight(id: str) -> FlightDisplaySchema: diff --git a/api/routes/flights.py b/api/routes/flights.py index c1f1fba..be7c692 100644 --- a/api/routes/flights.py +++ b/api/routes/flights.py @@ -100,9 +100,9 @@ async def add_flight(flight_body: FlightCreateSchema, user: UserDisplaySchema = return {"id": str(flight)} -@router.put('/{flight_id}', summary="Update the given flight with new information", status_code=201) +@router.put('/{flight_id}', summary="Update the given flight with new information", status_code=200) async def update_flight(flight_id: str, flight_body: FlightCreateSchema, - user: UserDisplaySchema = Depends(get_current_user)) -> str: + user: UserDisplaySchema = Depends(get_current_user)) -> dict: """ Update the given flight with new information @@ -121,7 +121,7 @@ async def update_flight(flight_id: str, flight_body: FlightCreateSchema, updated_flight_id = await db.update_flight(flight_body, flight_id) - return str(updated_flight_id) + return {"id": str(updated_flight_id)} @router.delete('/{flight_id}', summary="Delete the given flight", status_code=200, response_model=FlightDisplaySchema)