From ba4c0edc467dc329675acaeed49707e933c9f10a Mon Sep 17 00:00:00 2001 From: Nate-Wessel Date: Tue, 16 Jul 2024 18:02:52 +0000 Subject: [PATCH] only return holidays within date range --- backend/app/routes.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/backend/app/routes.py b/backend/app/routes.py index 055a468..4e96ae2 100644 --- a/backend/app/routes.py +++ b/backend/app/routes.py @@ -131,11 +131,24 @@ def get_date_bounds(): def get_holidays(): "Return dates of all known holidays in ascending order" connection = getConnection() + query = f""" + SELECT + dt::text, + EXTRACT(ISODOW FROM dt)::int, + holiday + FROM ref.holiday + WHERE dt >= %(minDate)s AND dt < %(maxDate)s + ORDER BY dt; + """ with connection: with connection.cursor() as cursor: - cursor.execute( - "SELECT dt::text, EXTRACT(ISODOW FROM dt)::int, holiday FROM ref.holiday ORDER BY dt;" - ) - dates = [{'date': dt, 'dow': dow, 'name': nm} for (dt, dow, nm) in cursor.fetchall()] + cursor.execute(query, get_date_bounds()) + dates = [ + { + 'date': dt, + 'dow': dow, + 'name': nm + } for (dt, dow, nm) in cursor.fetchall() + ] connection.close() return dates \ No newline at end of file