From 362b8483646676ac95e7c4a4a2ccd09905947202 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Vit=C3=B3ria=20Silva?= Date: Mon, 8 Dec 2025 22:58:06 +0000 Subject: [PATCH] Add pagination metadata to health API list responses Updated the list response schemas and routers for health_sleep, health_steps, and health_weight to include num_records and page_number fields. This provides clients with additional pagination metadata alongside the total count and records. --- backend/app/health_sleep/router.py | 6 +++++- backend/app/health_sleep/schema.py | 6 +++++- backend/app/health_steps/router.py | 6 +++++- backend/app/health_steps/schema.py | 6 +++++- backend/app/health_weight/router.py | 11 ++++++++--- backend/app/health_weight/schema.py | 6 +++++- 6 files changed, 33 insertions(+), 8 deletions(-) diff --git a/backend/app/health_sleep/router.py b/backend/app/health_sleep/router.py index 553154739..96b831a7a 100644 --- a/backend/app/health_sleep/router.py +++ b/backend/app/health_sleep/router.py @@ -98,6 +98,8 @@ async def read_health_sleep_all_pagination( Returns: HealthSleepListResponse: Response containing: - total (int): Total number of health sleep records for the user. + - num_records (int): Number of records returned in this response. + - page_number (int): Page number of the current response. - records (list): List of health sleep records for the requested page. Raises: @@ -110,7 +112,9 @@ async def read_health_sleep_all_pagination( token_user_id, db, page_number, num_records ) - return health_sleep_schema.HealthSleepListResponse(total=total, records=records) + return health_sleep_schema.HealthSleepListResponse( + total=total, num_records=num_records, page_number=page_number, records=records + ) @router.post("", status_code=201) diff --git a/backend/app/health_sleep/schema.py b/backend/app/health_sleep/schema.py index 070f92930..655aa0691 100644 --- a/backend/app/health_sleep/schema.py +++ b/backend/app/health_sleep/schema.py @@ -242,10 +242,12 @@ class HealthSleepListResponse(BaseModel): Response schema for health sleep list with total count. This class wraps a list of health sleep records along with the total count, - providing a complete response for list endpoints. + number of records, and page number providing a complete response for list endpoints. Attributes: total (int): Total number of sleep records for the user. + num_records (int | None): Number of records returned in this response. + page_number (int | None): Page number of the current response. records (list[HealthSleep]): List of health sleep measurements. Configuration: @@ -255,6 +257,8 @@ class HealthSleepListResponse(BaseModel): """ total: int + num_records: int | None = None + page_number: int | None = None records: list[HealthSleep] model_config = ConfigDict( diff --git a/backend/app/health_steps/router.py b/backend/app/health_steps/router.py index f022b708d..593dc8570 100644 --- a/backend/app/health_steps/router.py +++ b/backend/app/health_steps/router.py @@ -99,6 +99,8 @@ async def read_health_steps_all_pagination( Returns: HealthStepsListResponse: A response object containing: - total (int): The total number of health steps records for the user. + - num_records (int): Number of records returned in this response. + - page_number (int): Page number of the current response. - records (list): A list of paginated health steps records. Raises: @@ -111,7 +113,9 @@ async def read_health_steps_all_pagination( token_user_id, db, page_number, num_records ) - return health_steps_schema.HealthStepsListResponse(total=total, records=records) + return health_steps_schema.HealthStepsListResponse( + total=total, num_records=num_records, page_number=page_number, records=records + ) @router.post("", status_code=201) diff --git a/backend/app/health_steps/schema.py b/backend/app/health_steps/schema.py index 0d45b57e9..cf44cf241 100644 --- a/backend/app/health_steps/schema.py +++ b/backend/app/health_steps/schema.py @@ -51,10 +51,12 @@ class HealthStepsListResponse(BaseModel): Response schema for health steps list with total count. This class wraps a list of health steps records along with the total count, - providing a complete response for list endpoints. + number of records, and page number providing a complete response for list endpoints. Attributes: total (int): Total number of steps records for the user. + num_records (int | None): Number of records returned in this response. + page_number (int | None): Page number of the current response. records (list[HealthSteps]): List of health steps measurements. Configuration: @@ -64,6 +66,8 @@ class HealthStepsListResponse(BaseModel): """ total: int + num_records: int | None = None + page_number: int | None = None records: list[HealthSteps] model_config = ConfigDict( diff --git a/backend/app/health_weight/router.py b/backend/app/health_weight/router.py index 43fd12ab8..6067ca73b 100644 --- a/backend/app/health_weight/router.py +++ b/backend/app/health_weight/router.py @@ -97,8 +97,11 @@ async def read_health_weight_all_pagination( db (Session): The database session dependency. Returns: - HealthWeightListResponse: An object containing the total count and paginated list - of health weight records for the user. + HealthWeightListResponse: A response object containing: + - total (int): The total number of health weight records for the user. + - num_records (int): Number of records returned in this response. + - page_number (int): Page number of the current response. + - records (list): A list of paginated health weight records. Raises: HTTPException: If authentication fails or user lacks required permissions. @@ -110,7 +113,9 @@ async def read_health_weight_all_pagination( token_user_id, db, page_number, num_records ) - return health_weight_schema.HealthWeightListResponse(total=total, records=records) + return health_weight_schema.HealthWeightListResponse( + total=total, num_records=num_records, page_number=page_number, records=records + ) @router.post("", status_code=201) diff --git a/backend/app/health_weight/schema.py b/backend/app/health_weight/schema.py index 75ff8fd90..c32ba0e7a 100644 --- a/backend/app/health_weight/schema.py +++ b/backend/app/health_weight/schema.py @@ -70,10 +70,12 @@ class HealthWeightListResponse(BaseModel): Response schema for health weight list with total count. This class wraps a list of health weight records along with the total count, - providing a complete response for list endpoints. + number of records, and page number providing a complete response for list endpoints. Attributes: total (int): Total number of weight records for the user. + num_records (int | None): Number of records returned in this response. + page_number (int | None): Page number of the current response. records (list[HealthWeight]): List of health weight measurements. Configuration: @@ -83,6 +85,8 @@ class HealthWeightListResponse(BaseModel): """ total: int + num_records: int | None = None + page_number: int | None = None records: list[HealthWeight] model_config = ConfigDict(