diff --git a/src/quartz_api/internal/service/uk_national/endpoint_types.py b/src/quartz_api/internal/service/uk_national/endpoint_types.py index 6c9a77f..ebdd878 100644 --- a/src/quartz_api/internal/service/uk_national/endpoint_types.py +++ b/src/quartz_api/internal/service/uk_national/endpoint_types.py @@ -41,6 +41,9 @@ def convert_list_of_gsp_ids(gsp_ids:str | None) -> list[int] | None: if gsp_ids is None: return gsp_ids + if gsp_ids == "": + return None + return [int(gsp_id) for gsp_id in gsp_ids.split(",")] class EnhancedBaseModel(BaseModel): diff --git a/src/quartz_api/internal/service/uk_national/gsp_router.py b/src/quartz_api/internal/service/uk_national/gsp_router.py index 418f30d..4fa595c 100644 --- a/src/quartz_api/internal/service/uk_national/gsp_router.py +++ b/src/quartz_api/internal/service/uk_national/gsp_router.py @@ -329,6 +329,7 @@ async def get_all_available_forecasts( """ # Default (no gsp_ids): served from warm cache only. If we're here it's a cache miss — # trigger a warm in the background and ask the client to retry. + gsp_ids = convert_list_of_gsp_ids(gsp_ids) start_datetime_utc_set = start_datetime_utc != default_now_window_start() end_datetime_utc_set = end_datetime_utc != default_window_end() @@ -365,7 +366,7 @@ async def get_all_available_forecasts( # gsp_ids path: custom query, fetch live. gsps_to_convert: dict[int, models.Location] = { k: v for k, v in gsp_id_map.items() - if k in convert_list_of_gsp_ids(gsp_ids) + if k in gsp_ids } tasks = [ db.get_predicted_generation( @@ -567,10 +568,8 @@ async def get_truths_for_all_gsps( - **start_datetime_utc**: optional start datetime for the query. - **end_datetime_utc**: optional end datetime for the query. """ - # Why not just make the endpoint type list[int] and let fast API do this? - gsp_ids: list[int] | None = convert_list_of_gsp_ids(gsp_ids) out: list[GSPYieldGroupByDatetime] = [] - + gsp_ids = convert_list_of_gsp_ids(gsp_ids) gsp_uuid_id_map: dict[UUID, int] = {v.uuid: k for k, v in gsp_id_map.items()} if gsp_ids is None: