From 84c9016be4209d97070a7aad5998acd73105d280 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Tue, 29 Dec 2020 20:07:12 +0100 Subject: [PATCH] Fix IndexError when Bikepoint doesn't exist in historical data --- projects/project-3/backend/api_database.py | 2 +- projects/project-3/backend/routers/dashboard.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/projects/project-3/backend/api_database.py b/projects/project-3/backend/api_database.py index e3bd246..a812cdb 100644 --- a/projects/project-3/backend/api_database.py +++ b/projects/project-3/backend/api_database.py @@ -37,7 +37,7 @@ def get_dashboard(station_id): JOIN bike_points b ON u.start_station_id = b.id_num JOIN dashboard d ON u.start_station_id = d.id WHERE u.start_station_id = ?""" - return get_db_connection().execute(query, (station_id,)).fetchall() + return get_db_connection().execute(query, (station_id,)).fetchone() def get_dashboard_to(station_id, start_date, end_date): diff --git a/projects/project-3/backend/routers/dashboard.py b/projects/project-3/backend/routers/dashboard.py index 95a4c36..e8cdd7a 100644 --- a/projects/project-3/backend/routers/dashboard.py +++ b/projects/project-3/backend/routers/dashboard.py @@ -26,7 +26,7 @@ class StationDashboard(BaseModel): @router.get("/", response_model=StationDashboard) def get_general_dashboard(station_id: int): - return api_database.get_dashboard(station_id)[0] + return api_database.get_dashboard(station_id) or {} class StationDashboardTopStationsEntry(BaseModel):