Skip to content

Conversation

zigzagdev
Copy link
Owner

Description

This pull request integrates the ViewModel and Controller logic for the Post module into the Presentation layer.

Changes introduced:

  • Implemented GetAllUserPostViewModel to structure individual post responses.
  • Developed getAllPosts method in the controller to handle incoming requests and apply pagination logic.
  • Mapped DTO data to view models and returned structured JSON responses.
  • Included exception handling with consistent response formatting.

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

  • Verified that the GetAllUserPostViewModel correctly transforms GetAllUserPostDto data.
  • Ensured getAllPosts() controller method receives userId, perPage, and currentPage properly and handles exceptions.
  • Confirmed that all response formats match expected frontend structure.
  • Unit tests were created and passed for both ViewModel and Controller.

@zigzagdev zigzagdev linked an issue Jun 14, 2025 that may be closed by this pull request
@zigzagdev zigzagdev requested a review from Copilot June 14, 2025 10:50
@zigzagdev zigzagdev self-assigned this Jun 14, 2025
@zigzagdev zigzagdev added enhancement New feature or request backend labels Jun 14, 2025
@zigzagdev zigzagdev merged commit 00f62e0 into feature/show-post-index Jun 14, 2025
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 integrates the ViewModel and Controller layers for retrieving user posts, adds pagination, and updates corresponding tests.

  • Introduced GetAllUserPostViewModel to map DTOs to response shapes
  • Added getAllPosts in PostController with pagination and exception handling
  • Created tests for the view model and basic response-type check for the controller

Reviewed Changes

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

File Description
src/app/Post/Presentation/ViewModel/GetAllUserPostViewModel.php New ViewModel for structuring post data
src/app/Post/Presentation/PresentationTest/GetAllUserPostViewModelTest.php Tests for building and serializing the ViewModel
src/app/Post/Presentation/PresentationTest/Controller/PostController_getAllUserPostTest.php Test for controller response type (JsonResponse)
src/app/Post/Presentation/Controller/PostController.php Added getAllPosts method with pagination logic
Files not reviewed (1)
  • .idea/workspace.xml: Language not supported
Comments suppressed due to low confidence (2)

src/app/Post/Presentation/PresentationTest/Controller/PostController_getAllUserPostTest.php:113

  • This test only checks the response type. Consider adding assertions to verify the JSON body structure (e.g., status, data, pagination metadata) to ensure the controller returns the expected payload.
$this->assertInstanceOf(JsonResponse::class, $response);

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

  • The JsonResponse type is not imported at the top of the file, causing an undefined class error. Add use Illuminate\Http\JsonResponse;.
): JsonResponse

);

$viewModels = array_map(
fn($item) => $item->toArray(),
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.

The controller maps each item with ->toArray() directly but never constructs the GetAllUserPostViewModel. To ensure proper mapping from DTO to view model, apply GetAllUserPostViewModel::build($item)->toArray() instead of calling toArray() on the raw item.

Suggested change
fn($item) => $item->toArray(),
fn($item) => GetAllUserPostViewModel::build($item)->toArray(),

Copilot uses AI. Check for mistakes.

@zigzagdev zigzagdev deleted the feature/show-post-index-presentation branch June 14, 2025 11:15
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.

Show Post Presentation Layer

1 participant