From 955a3e38f30113699ce3c6d1aec85ab5d683bcba Mon Sep 17 00:00:00 2001 From: april Date: Tue, 9 Jan 2024 13:17:34 -0600 Subject: [PATCH] Handle totals with no flights --- api/database/flights.py | 19 ++++++++++++++++++- api/routes/flights.py | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/api/database/flights.py b/api/database/flights.py index 589a30f..ae59ae5 100644 --- a/api/database/flights.py +++ b/api/database/flights.py @@ -67,7 +67,24 @@ async def retrieve_totals(user: str, start_date: datetime = None, end_date: date result = await cursor.to_list(length=None) if not result: - raise HTTPException(404, "No flights found") + return { + "time_total": 0.0, + "time_solo": 0.0, + "time_night": 0.0, + "time_pic": 0.0, + "time_sic": 0.0, + "time_instrument": 0.0, + "time_sim": 0.0, + "time_xc": 0.0, + "landings_day": 0, + "landings_night": 0, + "xc_dual_recvd": 0.0, + "xc_solo": 0.0, + "xc_pic": 0.0, + "night_dual_recvd": 0.0, + "night_pic": 0.0 + + } totals = result[0] async for log in flight_collection.find({"user": ObjectId(user)}): diff --git a/api/routes/flights.py b/api/routes/flights.py index d274a5b..ee968d5 100644 --- a/api/routes/flights.py +++ b/api/routes/flights.py @@ -67,6 +67,7 @@ async def get_flight_totals(user: UserDisplaySchema = Depends(get_current_user), end = datetime.strptime(end_date, "%Y-%m-%d") if end_date != "" else None except (TypeError, ValueError): raise HTTPException(400, "Date range not processable") + return await db.retrieve_totals(user.id, start, end)