-
Notifications
You must be signed in to change notification settings - Fork 0
Integrate infrastructure layer for post query services #337
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
Integrate infrastructure layer for post query services #337
Conversation
…repository Implement query service for retrieving user and other users' posts with pagination support
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
Interface adherence
- The
GetPostQueryService
correctly implements theGetPostQueryServiceInterface
, exposing all defined methods with appropriate input/output types. - Each method returns either a domain entity (
PostEntity
) or aPaginationDto
, maintaining consistency across the application layer.
Enum usage
- Visibility filtering uses
PostVisibilityEnum::PUBLIC->value
, ensuring type-safe access to int-based enum values that align with DB schema.
Pagination integrity
- Laravel's
paginate()
method is used with the correct parameter order:
paginate(perPage, columns, pageName, currentPage)
- Pagination data is fully preserved in the resulting
PaginationDto
, enabling consistent API responses.
Null-safety and validation
getEachUserPost
returnsnull
when no post is found — explicitly handledgetAllUserPosts
includes anexists()
check to prevent invalid user IDs from triggering unnecessary DB calls
Domain transformation
- All data retrieved from the database is transformed via
PostFromModelEntityFactory
into domain entities before being returned, decoupling Eloquent from the domain.
Areas for potential extension
- Add authorisation checks at this layer or higher (e.g. ownership validation)
- Add query filters (e.g. keyword search, tag filtering) as part of future use cases
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 an infrastructure-backed query for fetching posts from all users except the specified one, updating domain mappings and model casts to use the new PostVisibility
enum.
- Introduces
getOthersAllPosts
inGetPostQueryService
and its interface signature - Updates
Post
model to cast visibility to the new enum and provides a visibility label accessor - Adjusts the
PostFromModelEntityFactory
andPostVisibility
enum to align with integer-backed enum values - Adds basic tests for the new query service method
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
src/app/Post/Infrastructure/QueryService/GetPostQueryService.php | Added getOthersAllPosts method and integrated PostVisibility |
src/app/Post/Application/QueryServiceInterface/GetPostQueryServiceInterface.php | Declared getOthersAllPosts in the interface |
src/app/Post/Domain/EntityFactory/PostFromModelEntityFactory.php | Updated enum usage to PostVisibilityEnum::from(...) |
src/app/Models/Post.php | Switched to enum casting and removed custom attribute definition |
src/app/Common/Domain/Enum/PostVisibility.php | Changed enum to integer-backed values and updated cases |
src/app/Post/Infrastructure/InfrastructureTest/GetOthersAllPostsQueryServiceTest.php | Added tests for the new query service method |
Comments suppressed due to low confidence (4)
src/app/Post/Infrastructure/QueryService/GetPostQueryService.php:89
- [nitpick] Missing PHPDoc for this new method; please add a docblock describing parameters, return type, and behavior when no posts are found.
public function getOthersAllPosts(
src/app/Post/Infrastructure/InfrastructureTest/GetOthersAllPostsQueryServiceTest.php:98
- [nitpick] There’s no test for the scenario when no other users’ posts exist; consider adding a case where
getOthersAllPosts
returns null or an empty pagination DTO.
public function test_check_query_service_return_value(): void
src/app/Post/Application/QueryServiceInterface/GetPostQueryServiceInterface.php:23
- PaginationDto is referenced but not imported in this interface; add
use App\Common\Application\Dto\Pagination as PaginationDto;
at the top.
public function getOthersAllPosts(
src/app/Models/Post.php:26
- The
PostVisibility
enum used in casts is not imported; adduse App\Common\Domain\Enum\PostVisibility;
or qualify it with its full namespace.
protected $casts = [
$currentPage | ||
); | ||
|
||
if (empty($allPosts)) { |
Copilot
AI
Jul 5, 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.
Using empty() on a LengthAwarePaginator will always return false; use $allPosts->isEmpty() to detect when no records are returned.
if (empty($allPosts)) { | |
if ($allPosts->isEmpty()) { |
Copilot uses AI. Check for mistakes.
'mediaPath' => $request['media_path'] ?? null, | ||
'visibility' => new PostVisibility( | ||
PostVisibilityEnum::fromString($request['visibility']) | ||
PostVisibilityEnum::from($request['visibility'] ?? PostVisibilityEnum::PUBLIC) |
Copilot
AI
Jul 5, 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.
Default PostVisibilityEnum::PUBLIC
is an enum instance, not its backing value; use PostVisibilityEnum::PUBLIC->value
or ensure only an int is passed to from()
.
PostVisibilityEnum::from($request['visibility'] ?? PostVisibilityEnum::PUBLIC) | |
PostVisibilityEnum::from($request['visibility'] ?? PostVisibilityEnum::PUBLIC->value) |
Copilot uses AI. Check for mistakes.
Description
This PR introduces the infrastructure layer implementation for post-related query operations within the application. It includes the
GetPostQueryService
class, which serves as the concrete implementation of theGetPostQueryServiceInterface
.The class provides query capabilities against the Eloquent models and maps the retrieved data into domain entities and DTOs, effectively bridging the persistence mechanism with the domain logic.