feat: ✨ add user command handling#37
Open
andrewdyer wants to merge 9 commits into
Open
Conversation
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.
There was a problem hiding this comment.
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/DeleteUserCommandand matching handlers; rewires actions to use them viaCommandBus. - Registers
CommandBuswith handler mappings inbootstrap/dependencies.phpand addsandrewdyer/command-bustocomposer.json/composer.lock. - Removes
AbstractUserAction; switches read actions (List,Show) toUserRepositorydirectly with explicit not-found handling inShowUserAction; 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors the user-related HTTP actions to use the Command Bus pattern, improving separation of concerns and maintainability. It removes the
AbstractUserActionbase 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
UserServicein user actions with the Command Bus pattern. Each action (CreateUserAction,UpdateUserAction,DeleteUserAction) now dispatches a corresponding command (CreateUserCommand,UpdateUserCommand,DeleteUserCommand) via theCommandBus, 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
AbstractUserActionbase class, as actions no longer share a dependency onUserService.Dependency Injection and Bootstrapping:
Registers the
CommandBusand its command-handler mappings in the DI container, ensuring that commands are properly routed to their handlers. [1] [2]Adds
andrewdyer/command-busas a new dependency incomposer.json.Repository Usage and Error Handling:
ListUsersActionandShowUserActionto useUserRepositorydirectly for retrieving users, improving clarity and directness of data access. Also adds explicit error handling for not-found users inShowUserAction. [1] [2] [3] [4]Testing: