Adding support for OFFSET/LIMIT pagination in Activity.Api#65
Merged
willvelida merged 2 commits intomainfrom Jul 9, 2025
Merged
Adding support for OFFSET/LIMIT pagination in Activity.Api#65willvelida merged 2 commits intomainfrom
willvelida merged 2 commits intomainfrom
Conversation
Signed-off-by: Will Velida <willvelida@hotmail.co.uk>
Contributor
There was a problem hiding this comment.
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.GetAllActivitySummariesto accept aPaginationRequestand return aPaginationResponse. - Implemented pagination in
CosmosRepositorywith anOFFSET @offset LIMIT @limitquery and a total-count query. - Added
PaginationRequest/PaginationResponsemodels, updated handlers to acceptpageNumber/pageSize, and expanded unit tests; updatedmain.bicepto 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces pagination functionality to the
GetAllActivitySummariesendpoint in theBiotrackr.Activity.Apiproject. 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
pageNumberandpageSizeto theactivityApiGetAllresource inmain.bicepto enable pagination in API requests.Endpoint Handler Changes: Modified the
GetAllActivitiesmethod inActivityHandlersto accept optionalpageNumberandpageSizeparameters and use the newPaginationRequestmodel to fetch paginated results.Repository Method Update: Updated the
GetAllActivitySummariesmethod inCosmosRepositoryto support pagination by calculatingOFFSETandLIMITvalues based on thePaginationRequest. Added logging for pagination parameters.Pagination Models:
PaginationRequestandPaginationResponseclasses inModels. These handle pagination logic, such as clamping invalid values and calculating metadata likeTotalPages,HasPreviousPage, andHasNextPage.Unit Test Enhancements:
Endpoint Tests: Refactored unit tests for
ActivityHandlersto validate the behavior of pagination parameters and default values, ensuring correct handling of paginated responses.Repository Tests: Added comprehensive tests for the
GetAllActivitySummariesmethod inCosmosRepositoryto verify correct pagination metadata, query behavior, and error handling.Model Tests: Created new unit tests for
PaginationRequestandPaginationResponseto ensure proper validation, default value assignment, and metadata calculations. [1] [2]