-
Notifications
You must be signed in to change notification settings - Fork 0
Merge Presentation layer for GetOthersPosts flow (Controller, ViewModel, Factory) #346
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 Presentation layer for GetOthersPosts flow (Controller, ViewModel, Factory) #346
Conversation
…tation-viewmodel Add GetPostViewModel and GetPostsViewModelCollection with unit tests
…tation-controller Add GetOthersPostsController action and its feature test
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
- 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
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 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
inPostController
to handle request parameters, invoke the use case, build view models, and return a standardized JSON payload. - Adds
GetPostViewModel
andGetPostsViewModelCollection
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 ofGetUserEachPostDto
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 testsGetPostsViewModelCollection
. Consider renaming it toGetPostsViewModelCollectionTest
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 useGetPostViewModel
(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 appropriateuse
statement for the factory so this call compiles.
$paginationViewModel = PaginationViewModelFactory::build(
); | ||
|
||
if (empty($allPosts)) { | ||
if (empty($getPosts)) { |
Copilot
AI
Jul 6, 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.
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.
if (empty($getPosts)) { | |
if ($getPosts->isEmpty()) { |
Copilot uses AI. Check for mistakes.
$allPosts = $getPosts->map(function ($post) { | ||
return PostFromModelEntityFactory::build($post->toArray()); | ||
}); | ||
|
||
return $this->paginationDto($allPosts->toArray()); |
Copilot
AI
Jul 6, 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.
LengthAwarePaginator
doesn’t have a map
method directly. You should call $getPosts->getCollection()->map(...)
to transform items, then rebuild the paginator if needed.
$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.
$request->shouldReceive('input') | ||
->with('perPage') | ||
->andReturn($this->perPage); | ||
|
||
$request->shouldReceive('input') | ||
->with('currentPage') |
Copilot
AI
Jul 6, 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 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.
$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.
Description
This PR merges the Presentation Layer implementation for retrieving posts made by other users (
getOthersPosts
).It includes:
getOthersPosts()
GetAllUserPostViewModel
Implemented Components
1. Controller
userId
,per_page
,current_page
)GetOthersAllPostsUseCase
GetUserEachPostDto
toGetAllUserPostViewModel
PaginationViewModelFactory
for frontend consumptionstatus
,data
,meta
2. ViewModel: GetAllUserPostViewModel
GetUserEachPostDto
via staticbuild()
methodtoArray()
3. PaginationViewModelFactory
$data
asPaginationDto
$viewModels
as transformed array of DTOs