Skip to content

Conversation

zigzagdev
Copy link
Owner

Description

This PR merges the Presentation Layer implementation for retrieving posts made by other users (getOthersPosts).
It includes:

  • Controller method: getOthersPosts()
  • ViewModel: GetAllUserPostViewModel
  • ViewModelCollection (if applicable)
  • PaginationViewModelFactory integration

Implemented Components

1. Controller

public function getOthersPosts(
    Request $request,
    int $userId,
    GetOthersAllPostsUseCase $useCase
): JsonResponse
  • Resolves route and query parameters (userId, per_page, current_page)
  • Invokes GetOthersAllPostsUseCase
  • Maps GetUserEachPostDto to GetAllUserPostViewModel
  • Wraps in PaginationViewModelFactory for frontend consumption
  • Returns structured JSON: status, data, meta

2. ViewModel: GetAllUserPostViewModel

  • Accepts a single GetUserEachPostDto via static build() method
  • Exposes data via toArray()

3. PaginationViewModelFactory

  • Receives:
    • $data as PaginationDto
    • $viewModels as transformed array of DTOs
  • Returns consistent pagination metadata and data structure

@zigzagdev zigzagdev requested a review from Copilot July 6, 2025 09:22
@zigzagdev zigzagdev self-assigned this Jul 6, 2025
@zigzagdev zigzagdev linked an issue Jul 6, 2025 that may be closed by this pull request
Copy link
Owner Author

@zigzagdev zigzagdev left a comment

Choose a reason for hiding this comment

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

Self Review

  • Controller doesn't violate Single Responsibility Principle
  • ViewModel correctly abstracts internal DTO structure
  • Pagination response format matches frontend contract
  • Exception handling returns clean 500 response
  • No Domain layer is leaked into Presentation

@zigzagdev zigzagdev merged commit 46bb270 into feature/see-other-posts Jul 6, 2025
@zigzagdev zigzagdev deleted the feature/see-other-posts-presentation branch July 6, 2025 09:24
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 adds the presentation layer for retrieving posts made by other users, including a new controller endpoint with pagination, view models for single posts and collections, and plumbing through the query service and use case.

  • Introduces getOthersPosts in PostController to handle request parameters, invoke the use case, build view models, and return a standardized JSON payload.
  • Adds GetPostViewModel and GetPostsViewModelCollection to convert DTOs into array data for the API.
  • Updates query service, use case, and DTO collection classes to return and wrap data in PaginationDto with custom post DTOs.

Reviewed Changes

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

Show a summary per file
File Description
src/app/Post/Presentation/Controller/PostController.php Implements getOthersPosts, maps DTOs to view models, returns JSON
src/app/Post/Presentation/ViewModel/GetPostViewModel.php Defines single-post view model with build() and toArray()
src/app/Post/Presentation/ViewModel/GetPostsViewModelCollection.php Defines collection view model mapping an array of DTOs
src/app/Post/Infrastructure/QueryService/GetPostQueryService.php Adjusts query for other users’ posts, renames variables, builds entities
src/app/Post/Application/UseCase/GetOthersAllPostsUseCase.php Wraps paginated results into GetAllUserPostDtoCollection and PaginationDto
src/app/Post/Application/Dto/GetAllUserPostDtoCollection.php Renames DTO collection property from items to posts
src/app/Post/Presentation/PresentationTest/GetPostViewModelTest.php Adds unit tests for single-post view model
src/app/Post/Presentation/PresentationTest/GetPostViewModelCollectionTest.php Adds unit tests for the collection view model
src/app/Post/Presentation/PresentationTest/Controller/PostController_getOthersPostsTest.php Adds a smoke test for the new controller endpoint
Comments suppressed due to low confidence (5)

src/app/Post/Application/Dto/GetAllUserPostDtoCollection.php:9

  • The docblock and type hint refer to PostDto and $items, but the constructor now takes an array of GetUserEachPostDto named $posts. Update the annotation to @param GetUserEachPostDto[] $posts.
    /**

src/app/Post/Presentation/PresentationTest/GetPostViewModelCollectionTest.php:14

  • [nitpick] The test class is named GetPostViewModelCollectionTest but it tests GetPostsViewModelCollection. Consider renaming it to GetPostsViewModelCollectionTest to match the class under test.
class GetPostViewModelCollectionTest extends TestCase

src/app/Post/Presentation/PresentationTest/Controller/PostController_getOthersPostsTest.php:85

  • The controller test only verifies the return type. Add assertions to confirm the JSON structure (status, data, meta) and HTTP status code to fully validate the new endpoint.
        $this->assertInstanceOf(JsonResponse::class, $result);

src/app/Post/Presentation/Controller/PostController.php:175

  • The controller refers to GetAllUserPostViewModel, but no such class was added. It should either import and use GetPostViewModel (or rename the view model class) so this reference resolves correctly.
                fn(GetUserEachPostDto $dto) => GetAllUserPostViewModel::build($dto)->toArray(),

src/app/Post/Presentation/Controller/PostController.php:179

  • Missing import for PaginationViewModelFactory. Add the appropriate use statement for the factory so this call compiles.
            $paginationViewModel = PaginationViewModelFactory::build(

);

if (empty($allPosts)) {
if (empty($getPosts)) {
Copy link

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

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

Checking empty($getPosts) on a paginator object won’t detect when there are zero records. Use $getPosts->isEmpty() on the underlying collection or check count($getPosts) instead.

Suggested change
if (empty($getPosts)) {
if ($getPosts->isEmpty()) {

Copilot uses AI. Check for mistakes.

Comment on lines +111 to 115
$allPosts = $getPosts->map(function ($post) {
return PostFromModelEntityFactory::build($post->toArray());
});

return $this->paginationDto($allPosts->toArray());
Copy link

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

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

LengthAwarePaginator doesn’t have a map method directly. You should call $getPosts->getCollection()->map(...) to transform items, then rebuild the paginator if needed.

Suggested change
$allPosts = $getPosts->map(function ($post) {
return PostFromModelEntityFactory::build($post->toArray());
});
return $this->paginationDto($allPosts->toArray());
$allPosts = $getPosts->getCollection()->map(function ($post) {
return PostFromModelEntityFactory::build($post->toArray());
});
$getPosts->setCollection($allPosts);
return $this->paginationDto($getPosts->toArray());

Copilot uses AI. Check for mistakes.

Comment on lines +66 to +71
$request->shouldReceive('input')
->with('perPage')
->andReturn($this->perPage);

$request->shouldReceive('input')
->with('currentPage')
Copy link

Copilot AI Jul 6, 2025

Choose a reason for hiding this comment

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

The test mocks input('perPage') and input('currentPage'), but the controller calls $request->get('per_page', ...) and get('current_page', ...). Align the test to mock get('per_page') and get('current_page') for accurate coverage.

Suggested change
$request->shouldReceive('input')
->with('perPage')
->andReturn($this->perPage);
$request->shouldReceive('input')
->with('currentPage')
$request->shouldReceive('get')
->with('per_page')
->andReturn($this->perPage);
$request->shouldReceive('get')
->with('current_page')

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

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

See Other Posts Presentation

1 participant