-
Notifications
You must be signed in to change notification settings - Fork 0
Merge ViewModel and Controller for Post Retrieval in Presentation Layer #216
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge ViewModel and Controller for Post Retrieval in Presentation Layer #216
Conversation
…tation-viewmodel Implement GetAllUserPostViewModel and its test
…tation-controller Implement controller method to retrieve all posts for a user with pagination
There was a problem hiding this 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 transformsGetAllUserPostDto
data. - Ensured
getAllPosts()
controller method receivesuserId
,perPage
, andcurrentPage
properly and handles exceptions. - Confirmed that all response formats match expected frontend structure.
- Unit tests were created and passed for both ViewModel and Controller.
There was a problem hiding this 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
inPostController
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. Adduse Illuminate\Http\JsonResponse;
.
): JsonResponse
); | ||
|
||
$viewModels = array_map( | ||
fn($item) => $item->toArray(), |
Copilot
AI
Jun 14, 2025
There was a problem hiding this comment.
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.
fn($item) => $item->toArray(), | |
fn($item) => GetAllUserPostViewModel::build($item)->toArray(), |
Copilot uses AI. Check for mistakes.
Description
This pull request integrates the ViewModel and Controller logic for the Post module into the Presentation layer.
Changes introduced:
GetAllUserPostViewModel
to structure individual post responses.getAllPosts
method in the controller to handle incoming requests and apply pagination logic.