From da92a0f87ab513195ed698f29ab6d73ba470772a Mon Sep 17 00:00:00 2001 From: William Wills Date: Wed, 9 Oct 2024 17:21:23 -0400 Subject: [PATCH] feat: get activity by warehouseUnitId working --- app/api/v1/activities.py | 2 +- app/crud/chia.py | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/api/v1/activities.py b/app/api/v1/activities.py index 6b4b312..1f42a83 100644 --- a/app/api/v1/activities.py +++ b/app/api/v1/activities.py @@ -160,7 +160,7 @@ async def get_activity_by_cw_unit_id( (activities, total) = db_crud.select_activity_with_pagination( model=models.Activity, filters=activity_filters, - order_by='desc', + order_by=[models.Activity.height.asc()], page=page, limit=limit, ) diff --git a/app/crud/chia.py b/app/crud/chia.py index 8d55252..1c59a72 100644 --- a/app/crud/chia.py +++ b/app/crud/chia.py @@ -70,7 +70,15 @@ def _get_paginated_data(self, path: str, search_params: Dict[str, Any]) -> List[ # to prevent an infinite loop need to assume that there is no data matching the search from this iteration on return all_data - all_data.extend(data["data"]) # Add data from the current page + try: + if data["page"] and data["pageCount"] and data["data"]: + all_data.extend(data["data"]) # Add data from the current page + else: + all_data.append(data) # data was not paginated, append and return + return all_data + except: + all_data.append(data) # data was not paginated, append and return + return all_data if page >= data["pageCount"]: break # Exit loop if all pages have been processed @@ -183,7 +191,7 @@ def combine_climate_units_and_metadata(self, search: Dict[str, Any]) -> List[Dic warehouse_project_id = unit["issuance"]["warehouseProjectId"] project = project_by_id[warehouse_project_id] except (KeyError, TypeError): - logger.warning(f"Can not get project by warehouse_project_id: {warehouse_project_id}") + logger.warning(f"Can not get project by warehouse_project_id") continue org_metadata = metadata_by_id.get(unit_org_uid)