Skip to content

Adding support for OFFSET/LIMIT pagination in Activity.Api#65

Merged
willvelida merged 2 commits intomainfrom
feature/activity.api/pagination
Jul 9, 2025
Merged

Adding support for OFFSET/LIMIT pagination in Activity.Api#65
willvelida merged 2 commits intomainfrom
feature/activity.api/pagination

Conversation

@willvelida
Copy link
Owner

This pull request introduces pagination functionality to the GetAllActivitySummaries endpoint in the Biotrackr.Activity.Api project. The changes include updates to the API definition, endpoint handlers, repository methods, and unit tests to support paginated responses. Additionally, new models for handling pagination requests and responses have been implemented.

Pagination Implementation:

  • API Definition Update: Added query parameters pageNumber and pageSize to the activityApiGetAll resource in main.bicep to enable pagination in API requests.

  • Endpoint Handler Changes: Modified the GetAllActivities method in ActivityHandlers to accept optional pageNumber and pageSize parameters and use the new PaginationRequest model to fetch paginated results.

  • Repository Method Update: Updated the GetAllActivitySummaries method in CosmosRepository to support pagination by calculating OFFSET and LIMIT values based on the PaginationRequest. Added logging for pagination parameters.

Pagination Models:

  • New Models: Introduced PaginationRequest and PaginationResponse classes in Models. These handle pagination logic, such as clamping invalid values and calculating metadata like TotalPages, HasPreviousPage, and HasNextPage.

Unit Test Enhancements:

  • Endpoint Tests: Refactored unit tests for ActivityHandlers to validate the behavior of pagination parameters and default values, ensuring correct handling of paginated responses.

  • Repository Tests: Added comprehensive tests for the GetAllActivitySummaries method in CosmosRepository to verify correct pagination metadata, query behavior, and error handling.

  • Model Tests: Created new unit tests for PaginationRequest and PaginationResponse to ensure proper validation, default value assignment, and metadata calculations. [1] [2]

Signed-off-by: Will Velida <willvelida@hotmail.co.uk>
@willvelida willvelida requested a review from Copilot July 9, 2025 11:32
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds OFFSET/LIMIT pagination support to the GetAllActivitySummaries endpoint by introducing pagination models, updating the repository and handler logic, and extending unit tests and the Bicep API definition.

  • Changed ICosmosRepository.GetAllActivitySummaries to accept a PaginationRequest and return a PaginationResponse.
  • Implemented pagination in CosmosRepository with an OFFSET @offset LIMIT @limit query and a total-count query.
  • Added PaginationRequest/PaginationResponse models, updated handlers to accept pageNumber/pageSize, and expanded unit tests; updated main.bicep to include query parameters.

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Biotrackr.Activity.Api/Repositories/Interfaces/ICosmosRepository.cs Switched GetAllActivitySummaries to use PaginationRequest/PaginationResponse.
src/Biotrackr.Activity.Api/Repositories/CosmosRepository.cs Added pagination logic, logging, and a helper to fetch total count.
src/Biotrackr.Activity.Api/Models/PaginationRequest.cs Introduced PaginationRequest and PaginationResponse models with validation and metadata.
src/Biotrackr.Activity.Api/EndpointHandlers/ActivityHandlers.cs Modified handler signature to accept optional pagination parameters.
src/Biotrackr.Activity.Api.UnitTests/RepositoryTests/CosmosRepositoryShould.cs Refactored repository tests to assert paginated responses and behavior.
src/Biotrackr.Activity.Api.UnitTests/ModelTests/PaginationResponseShould.cs Added tests for pagination metadata calculations.
src/Biotrackr.Activity.Api.UnitTests/ModelTests/PaginationRequestShould.cs Added tests for page clamping and skip calculations.
src/Biotrackr.Activity.Api.UnitTests/EndpointHandlerTests/ActivityHandlersShould.cs Updated endpoint tests for pagination parameters and defaults.
infra/apps/activity-api/main.bicep Added pageNumber and pageSize query parameters to the API operation.

Signed-off-by: Will Velida <willvelida@hotmail.co.uk>
@willvelida willvelida merged commit 3e071ea into main Jul 9, 2025
9 checks passed
@willvelida willvelida deleted the feature/activity.api/pagination branch July 9, 2025 12:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants