Skip to content

feat: ✨ add user command handling#37

Open
andrewdyer wants to merge 9 commits into
mainfrom
feat/commands
Open

feat: ✨ add user command handling#37
andrewdyer wants to merge 9 commits into
mainfrom
feat/commands

Conversation

@andrewdyer

Copy link
Copy Markdown
Owner

This pull request refactors the user-related HTTP actions to use the Command Bus pattern, improving separation of concerns and maintainability. It removes the AbstractUserAction base class, introduces command and handler classes for user operations (create, update, delete), and updates dependency injection and action logic accordingly. Additionally, it adds unit tests for the new command classes.

Command Bus Integration and Refactoring:

  • Replaces direct usage of UserService in user actions with the Command Bus pattern. Each action (CreateUserAction, UpdateUserAction, DeleteUserAction) now dispatches a corresponding command (CreateUserCommand, UpdateUserCommand, DeleteUserCommand) via the CommandBus, and the business logic is handled in dedicated handler classes (CreateUserHandler, UpdateUserHandler, DeleteUserHandler). This decouples action classes from business logic and improves testability. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12]

  • Removes the now-unnecessary AbstractUserAction base class, as actions no longer share a dependency on UserService.

Dependency Injection and Bootstrapping:

  • Registers the CommandBus and its command-handler mappings in the DI container, ensuring that commands are properly routed to their handlers. [1] [2]

  • Adds andrewdyer/command-bus as a new dependency in composer.json.

Repository Usage and Error Handling:

  • Updates ListUsersAction and ShowUserAction to use UserRepository directly for retrieving users, improving clarity and directness of data access. Also adds explicit error handling for not-found users in ShowUserAction. [1] [2] [3] [4]

Testing:

  • Adds unit tests for the new command classes to ensure they correctly store provided data. [1] [2]

Added command-bus dependency to composer files
Added user command classes with unit tests
Added user command handler classes with unit tests
Refactor CreateUserAction, DeleteUserAction, and UpdateUserAction to dispatch commands via the command bus.
Add detailed constructor documentation for CreateUserCommand, DeleteUserCommand, and UpdateUserCommand to clarify required parameters.
Change ListUsersAction and ShowUserAction to extend AbstractAction and update user retrieval methods.
Add missing JsonException in the documentation for handle method in DeleteUserAction.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors the user HTTP actions to use a Command Bus pattern. CreateUserAction, UpdateUserAction, and DeleteUserAction now dispatch commands through AndrewDyer\CommandBus\CommandBus to dedicated handlers, while ListUsersAction and ShowUserAction consume UserRepository directly. The shared AbstractUserAction base class is removed and the andrewdyer/command-bus dependency is added with corresponding DI wiring and unit tests.

Changes:

  • Introduces CreateUserCommand/UpdateUserCommand/DeleteUserCommand and matching handlers; rewires actions to use them via CommandBus.
  • Registers CommandBus with handler mappings in bootstrap/dependencies.php and adds andrewdyer/command-bus to composer.json/composer.lock.
  • Removes AbstractUserAction; switches read actions (List, Show) to UserRepository directly with explicit not-found handling in ShowUserAction; adds unit tests for new commands and handlers.

Reviewed changes

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

Show a summary per file
File Description
composer.json Adds andrewdyer/command-bus dependency
composer.lock Locks andrewdyer/command-bus 1.0.0
bootstrap/dependencies.php Registers CommandBus and binds user command handlers
app/Application/Users/Actions/AbstractUserAction.php Deleted; actions no longer share UserService dep
app/Application/Users/Actions/CreateUserAction.php Dispatches CreateUserCommand via CommandBus
app/Application/Users/Actions/UpdateUserAction.php Dispatches UpdateUserCommand via CommandBus
app/Application/Users/Actions/DeleteUserAction.php Dispatches DeleteUserCommand via CommandBus
app/Application/Users/Actions/ShowUserAction.php Uses UserRepository::findById with explicit not-found throw
app/Application/Users/Actions/ListUsersAction.php Uses UserRepository::findPaginated directly
app/Application/Users/Commands/{Create,Update,Delete}UserCommand.php New command DTOs
app/Application/Users/Handlers/{Create,Update,Delete}UserHandler.php New handlers encapsulating user logic
tests/Unit/Application/Users/Commands/*Test.php Unit tests for command DTOs
tests/Unit/Application/Users/Handlers/*Test.php Unit tests for handlers using in-memory repo

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants