feat: ✨ add paginated user retrieval#34
Merged
Merged
Conversation
Adds paginated user retrieval support to the user repository contract via a new findPaginated() method. The in-memory repository implementation now returns a paginated subset of users along with the total user count, enabling pagination metadata to be calculated by consumers without requiring a separate query. This implementation is intended primarily for demo and development use.
Adds paginated user retrieval to the user service by delegating to the repository findPaginated() method. Also introduces service-level tests covering: - correct user counts - page-based result separation - per-page limits - empty results beyond available pages This establishes a basic pagination flow across the service layer.
Added a dedicated DTO for paginated user collections, including pagination metadata such as total items, current page, items per page, and total pages.
Modify the request method to parse and include query strings in the URI.
Modify ListUsersAction to retrieve paginated users and return metadata in the response.
There was a problem hiding this comment.
Pull request overview
Adds pagination support to the GET /api/v1/users endpoint by introducing a paginated response DTO, wiring new pagination methods through the service/repository layers, and updating tests and integration request handling to support query strings.
Changes:
- Introduced
PaginatedUsersDTOand updatedListUsersActionto return{ data, meta }withpage/perPagequery params. - Added
UserService::paginated()andUserRepository::findPaginated()with an in-memory implementation. - Updated/added unit + integration tests, and enhanced the integration test request helper to handle query strings; bumped
andrewdyer/actionsdependency.
Reviewed changes
Copilot reviewed 10 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| app/Application/Users/Actions/ListUsersAction.php | Switches list-users endpoint to paginated results and returns pagination metadata. |
| app/Application/Users/DTOs/PaginatedUsersDTO.php | Adds a DTO to serialize paginated user collections with meta. |
| app/Application/Users/Services/UserService.php | Adds a service-level pagination method delegating to the repository. |
| app/Domain/User/UserRepository.php | Extends repository contract with findPaginated(page, perPage). |
| app/Infrastructure/Persistence/User/InMemoryUserRepository.php | Implements pagination over the in-memory seeded user store. |
| tests/Integration/AbstractTestCase.php | Updates request helper to support query strings in test paths. |
| tests/Integration/Application/Users/Actions/ListUsersActionTest.php | Updates list-users integration coverage for paginated payload/metadata. |
| tests/Unit/Application/Users/DTOs/PaginatedUsersDTOTest.php | Adds unit coverage for new paginated DTO serialization. |
| tests/Unit/Application/Users/Services/UserServiceTest.php | Adds unit coverage for UserService::paginated() behavior. |
| composer.json | Bumps andrewdyer/actions version constraint. |
| composer.lock | Locks updated versions (notably andrewdyer/actions and andrewdyer/json-error-handler). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+91
to
+95
| $allUsers = $this->findAll(); | ||
| $total = count($allUsers); | ||
| $offset = ($page - 1) * $perPage; | ||
|
|
||
| $users = array_slice($allUsers, $offset, $perPage); |
Add assertions to verify the response status for user count and paginated user requests.
Change response method calls to include a null meta parameter.
Implement clamping for invalid page and perPage parameters in ListUsersAction and add corresponding tests.
Clarify that page and perPage parameters must be >= 1 in UserService and InMemoryUserRepository.
Remove PaginatedUsersDTO and streamline response structure in ListUsersAction.
Remove outdated comments and clarify pagination sections for user listing.
Implement tests for pagination functionality and user retrieval in InMemoryUserRepository.
Ensure totalPages is calculated correctly without clamping to a minimum of 1.
Update testTotalIncreasesAfterUsersAreCreated to directly assert user count increase without unnecessary pagination checks.
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 support for listing users in the API, enhancing both the application and test code to provide paginated responses with metadata. The changes include new DTOs, service and repository methods, updates to integration and unit tests, and a dependency version bump.
Pagination support for users listing:
PaginatedUsersDTO, to encapsulate paginated user data and associated metadata for API responses.ListUsersActionto return paginated users and metadata using query parameterspageandperPage, and to use the new DTO for serialization. [1] [2]Service and repository enhancements:
paginatedmethod toUserServiceandfindPaginatedmethod toUserRepositoryand its in-memory implementation, enabling paginated retrieval of users and total count. [1] [2] [3]Testing improvements:
PaginatedUsersDTOto verify correct instantiation and serialization.UserServicepagination logic, including edge cases and parameter handling.Infrastructure and dependency updates:
composer.jsonto require a newer version ofandrewdyer/actionsfor compatibility with the changes.