Skip to content

Conversation

zigzagdev
Copy link
Owner

Why

The existing implementation of GetAllUserPostQueryService returned all posts associated with a given user without any pagination logic. For scalability and performance, especially when dealing with a large volume of posts, pagination is essential.

What

  • Refactored the getAllUserPosts method to accept $perPage and $currentPage parameters.
  • Integrated Laravel's built-in paginate method to fetch paginated user posts.
  • Adapted the result to a PaginationDto, mapping each post to a domain entity via PostFromModelEntityFactory.
  • Updated the paginationDto() method to handle pagination metadata (e.g., total, current_page, per_page, etc.).
  • Added integration tests that:
    • Insert 50 dummy posts with controlled timestamps.
    • Fetch the first and second pages using the service.
    • Assert the expected size and content of the paginated result.

@zigzagdev zigzagdev requested a review from Copilot June 14, 2025 04:51
@zigzagdev zigzagdev self-assigned this Jun 14, 2025
@zigzagdev zigzagdev added enhancement New feature or request backend labels Jun 14, 2025
Copilot

This comment was marked as outdated.

@zigzagdev zigzagdev changed the base branch from main to feature/show-post-index June 14, 2025 04:54
@zigzagdev zigzagdev requested a review from Copilot June 14, 2025 04:57
@zigzagdev zigzagdev merged commit 11dec37 into feature/show-post-index Jun 14, 2025
@zigzagdev zigzagdev deleted the feature/show-post-index-infra-with-pagination branch June 14, 2025 04:57
Copy link

@Copilot 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 refactors GetAllUserPostQueryService to support paginated queries and updates related interfaces and DTOs, along with adding integration tests to verify the new behavior.

  • Service now accepts $perPage and $currentPage, uses Laravel’s paginate, and maps results to a PaginationDto.
  • The interface signature was updated to match the new pagination parameters and return type.
  • Pagination DTO was expanded (with corrected from and to types) and integration tests were added to seed posts and assert pagination metadata.

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 1 comment.

File Description
src/app/Post/Infrastructure/QueryService/GetAllUserPostQueryService.php Updated service to accept pagination params, use paginate(), and return PaginationDto
src/app/Post/Infrastructure/InfrastructureTest/GetAllUserPostQueryServiceTest.php Added integration tests for pagination with dummy posts
src/app/Post/Application/QueryServiceInterface/GetAllUserPostQueryServiceInterface.php Updated interface method signature and return type for pagination
src/app/Common/Application/Dto/Pagination.php Changed from/to from string to int and expanded constructor parameters
Files not reviewed (1)
  • .idea/workspace.xml: Language not supported
Comments suppressed due to low confidence (3)

src/app/Post/Infrastructure/InfrastructureTest/GetAllUserPostQueryServiceTest.php:35

  • The createDummyPosts method is defined but never invoked, so no posts are inserted for the tests. Consider calling createDummyPosts (and refresh) in setUp to seed posts before each test.
parent::setUp();

src/app/Post/Infrastructure/InfrastructureTest/GetAllUserPostQueryServiceTest.php:116

  • Test coverage is missing an assertion that the number of items in getData matches the requested perPage. Consider adding an assertion like $this->assertCount($this->perPage, $result->getData()); to verify page size.
        }

src/app/Common/Application/Dto/Pagination.php:11

  • [nitpick] Adding a PHPDoc block to explain the purpose of each constructor parameter would improve readability and maintainability of the Pagination DTO.
          private array $data,

Comment on lines +32 to +35
return $this->paginationDto($userPosts->toArray());
}

private function paginationDto(
Copy link

Copilot AI Jun 14, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider renaming paginationDto to buildPaginationDto to better reflect that this method constructs a PaginationDto from raw data.

Suggested change
return $this->paginationDto($userPosts->toArray());
}
private function paginationDto(
return $this->buildPaginationDto($userPosts->toArray());
}
private function buildPaginationDto(

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend enhancement New feature or request

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant