Delete associated images when deleting flight log
This commit is contained in:
parent
bb2388fac8
commit
b65805aed5
@ -13,6 +13,7 @@ from .aircraft import retrieve_aircraft_by_tail, update_aircraft_field
|
|||||||
from .db import flight_collection, aircraft_collection
|
from .db import flight_collection, aircraft_collection
|
||||||
from schemas.flight import FlightConciseSchema, FlightDisplaySchema, FlightCreateSchema, flight_display_helper, \
|
from schemas.flight import FlightConciseSchema, FlightDisplaySchema, FlightCreateSchema, flight_display_helper, \
|
||||||
flight_add_helper, FlightPatchSchema
|
flight_add_helper, FlightPatchSchema
|
||||||
|
from .img import delete_image
|
||||||
|
|
||||||
logger = logging.getLogger("api")
|
logger = logging.getLogger("api")
|
||||||
|
|
||||||
@ -265,5 +266,9 @@ async def delete_flight(id: str) -> FlightDisplaySchema:
|
|||||||
if flight is None:
|
if flight is None:
|
||||||
raise HTTPException(404, "Flight not found")
|
raise HTTPException(404, "Flight not found")
|
||||||
|
|
||||||
|
# Delete associated images
|
||||||
|
for image in flight.images:
|
||||||
|
await delete_image(image)
|
||||||
|
|
||||||
await flight_collection.delete_one({"_id": to_objectid(id)})
|
await flight_collection.delete_one({"_id": to_objectid(id)})
|
||||||
return FlightDisplaySchema(**flight_display_helper(flight))
|
return FlightDisplaySchema(**flight_display_helper(flight))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user