Skip to content

Conversation

@zigzagdev
Copy link
Owner

Description

This PR implements the edit() method on the post controller to handle post editing requests. The method is responsible for:

  • Receiving an HTTP request (Illuminate\Http\Request)
  • Merging route parameters with request body
  • Building a validated EditPostUseCommand
  • Executing the EditUseCase to persist changes
  • Returning a formatted JSON response via EditPostViewModel

Additionally, transaction control and exception rollback are implemented to ensure database integrity.

Why

This implementation closes the loop between Presentation and Application layers. By combining command parsing, transaction control, and ViewModel output, we ensure a cohesive and robust update flow.

How

  • Added edit() method to controller

    • Wraps logic in DB::beginTransaction() / commit() / rollBack()
    • Uses EditPostUseCommand::build() with merged data
    • Injects EditUseCase and wraps output in EditPostViewModel
  • On success: returns 200 OK with JSON payload

  • On failure: returns 500 with error message

  • Added integration-style controller test to verify:

    • UseCase is called with correct data
    • ViewModel transforms response correctly
    • Transaction boundaries are respected

@zigzagdev zigzagdev requested a review from Copilot June 21, 2025 09:35
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.

  • Confirmed that merged input contains route + body data for command build
  • Ensured transaction is committed only on success
  • Verified rollback occurs on exception
  • ViewModel formats response correctly
  • Test covers both success and failure paths
  • Used Mockery::overload to mock Request
  • Used Mockery::on() to match command input strictly

@zigzagdev zigzagdev linked an issue Jun 21, 2025 that may be closed by this pull request
@zigzagdev zigzagdev self-assigned this Jun 21, 2025
@zigzagdev zigzagdev added enhancement New feature or request backend labels Jun 21, 2025
@zigzagdev zigzagdev merged commit 8136012 into feature/edit-post-presentation Jun 21, 2025
@zigzagdev zigzagdev deleted the feature/edit-post-presentation-controller branch June 21, 2025 09:36
Copy link

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 introduces an edit() endpoint in the PostController to handle post updates within a database transaction and integrates the EditUseCase and EditPostViewModel. It also adds an integration-style test to verify the new flow.

  • Adds edit() method to controller with transaction control, command building, use case execution, and ViewModel response.
  • Updates necessary imports for the EditUseCase, EditPostUseCommand, and EditPostViewModel.
  • Introduces a new controller test to confirm that JsonResponse is returned.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/app/Post/Presentation/Controller/PostController.php Added edit() action, transaction handling, command & ViewModel integration
src/app/Post/Presentation/PresentationTest/Controller/PostController_editTest.php New test to exercise the edit() controller action
Comments suppressed due to low confidence (5)

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

  • [nitpick] The parameter name $user_id (and similarly $post_id) uses snake_case. For consistency with PSR and the rest of the codebase, consider renaming to $userId and $postId.
        int $user_id,

src/app/Post/Presentation/PresentationTest/Controller/PostController_editTest.php:135

  • The test only verifies the response type. Consider adding assertions for the HTTP status code and the JSON payload to fully cover success and error scenarios.
        $this->assertInstanceOf(JsonResponse::class, $result);

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

  • The code catches Throwable but Throwable is not imported. Add use Throwable; at the top of the file to avoid an undefined class error.
        } catch (Throwable $e) {

src/app/Post/Presentation/PresentationTest/Controller/PostController_editTest.php:120

  • The test stubs Request::all() but the controller calls Request::toArray(). You should mock toArray() instead (or call all() in the controller) to ensure the test returns the expected data.
            ->shouldReceive('all')

src/app/Post/Presentation/PresentationTest/Controller/PostController_editTest.php:3

  • [nitpick] The namespace repeats Presentation. Consider flattening to App\Post\PresentationTest\Controller to avoid redundancy and improve clarity.
namespace App\Post\Presentation\PresentationTest\Controller;

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.

Implement edit method into PostController

2 participants