Skip to content

feat: ✨ add paginated user retrieval#34

Merged
andrewdyer merged 16 commits into
mainfrom
feat/pagination
May 21, 2026
Merged

feat: ✨ add paginated user retrieval#34
andrewdyer merged 16 commits into
mainfrom
feat/pagination

Conversation

@andrewdyer
Copy link
Copy Markdown
Owner

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:

  • Added a new DTO, PaginatedUsersDTO, to encapsulate paginated user data and associated metadata for API responses.
  • Updated ListUsersAction to return paginated users and metadata using query parameters page and perPage, and to use the new DTO for serialization. [1] [2]

Service and repository enhancements:

  • Added paginated method to UserService and findPaginated method to UserRepository and its in-memory implementation, enabling paginated retrieval of users and total count. [1] [2] [3]

Testing improvements:

  • Updated and expanded integration tests for paginated user listing, including checks for correct pagination metadata and user presence.
  • Added unit tests for PaginatedUsersDTO to verify correct instantiation and serialization.
  • Added unit tests for UserService pagination logic, including edge cases and parameter handling.

Infrastructure and dependency updates:

  • Updated composer.json to require a newer version of andrewdyer/actions for compatibility with the changes.
  • Improved test request handling to support query strings in paths for integration tests.

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.
Copy link
Copy Markdown

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

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 PaginatedUsersDTO and updated ListUsersAction to return { data, meta } with page/perPage query params.
  • Added UserService::paginated() and UserRepository::findPaginated() with an in-memory implementation.
  • Updated/added unit + integration tests, and enhanced the integration test request helper to handle query strings; bumped andrewdyer/actions dependency.

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 thread app/Application/Users/Actions/ListUsersAction.php Outdated
Comment thread app/Application/Users/Actions/ListUsersAction.php Outdated
Comment on lines +91 to +95
$allUsers = $this->findAll();
$total = count($allUsers);
$offset = ($page - 1) * $perPage;

$users = array_slice($allUsers, $offset, $perPage);
Comment thread app/Application/Users/Services/UserService.php Outdated
Comment thread tests/Integration/Application/Users/Actions/ListUsersActionTest.php Outdated
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.
Copy link
Copy Markdown

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

Copilot reviewed 12 out of 13 changed files in this pull request and generated 3 comments.

Comment thread app/Application/Users/Actions/ListUsersAction.php Outdated
Comment thread tests/Integration/Application/Users/Actions/ListUsersActionTest.php Outdated
Comment thread app/Application/Users/Actions/ListUsersAction.php
Ensure totalPages is calculated correctly without clamping to a minimum of 1.
Update testTotalIncreasesAfterUsersAreCreated to directly assert user count increase without unnecessary pagination checks.
@andrewdyer andrewdyer merged commit 2516b9a into main May 21, 2026
1 check passed
@andrewdyer andrewdyer deleted the feat/pagination branch May 21, 2026 22:42
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