Skip to content

Conversation

zigzagdev
Copy link
Owner

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 the GetPostQueryServiceInterface.

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.

@zigzagdev zigzagdev self-assigned this Jul 5, 2025
@zigzagdev zigzagdev requested a review from Copilot July 5, 2025 06:28
@zigzagdev zigzagdev linked an issue Jul 5, 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

Interface adherence

  • The GetPostQueryService correctly implements the GetPostQueryServiceInterface, exposing all defined methods with appropriate input/output types.
  • Each method returns either a domain entity (PostEntity) or a PaginationDto, 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 returns null when no post is found — explicitly handled
  • getAllUserPosts includes an exists() 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

@zigzagdev zigzagdev merged commit 8088b8c into feature/see-other-posts Jul 5, 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 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 in GetPostQueryService and its interface signature
  • Updates Post model to cast visibility to the new enum and provides a visibility label accessor
  • Adjusts the PostFromModelEntityFactory and PostVisibility 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; add use App\Common\Domain\Enum\PostVisibility; or qualify it with its full namespace.
    protected $casts = [

$currentPage
);

if (empty($allPosts)) {
Copy link

Copilot AI Jul 5, 2025

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.

Suggested change
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)
Copy link

Copilot AI Jul 5, 2025

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().

Suggested change
PostVisibilityEnum::from($request['visibility'] ?? PostVisibilityEnum::PUBLIC)
PostVisibilityEnum::from($request['visibility'] ?? PostVisibilityEnum::PUBLIC->value)

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 Infra

1 participant