mirror of
https://github.com/joaovitoriasilva/endurain.git
synced 2026-01-09 15:57:59 -05:00
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.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user