refactor: add generic controller and query#24
Merged
Conversation
There was a problem hiding this comment.
Pull Request Overview
This pull request refactors the user controller to reduce code duplication by introducing generic handler functions for CRUD operations, simplifies the user picture change workflow by embedding the user ID in the request DTO, and reorganizes the generic query logic into a more appropriate package location.
- Introduced generic handler functions (
HandleCreate,HandleGetAll,HandleUpdate,HandleDelete) to standardize CRUD operations across controllers - Simplified the
ChangePictureservice method signature by including the ID field directly inUserChangePictureRequestDTO - Moved generic pagination query logic from
support/base/query.gotoinfrastructure/query/generic.go
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| api/v1/controller/generic.go | New file containing generic handler functions for CRUD operations |
| api/v1/controller/user.go | Refactored to use generic handlers, reducing boilerplate code |
| core/helper/dto/user.go | Added ID field to UserChangePictureRequest DTO |
| core/service/user.go | Updated ChangePicture method signature to accept only the DTO parameter |
| core/service/tests/picture_test.go | Updated test to match new ChangePicture signature |
| api/v1/controller/tests/user_test.go | Updated mock and test expectations for ChangePicture |
| infrastructure/query/generic.go | Relocated from support/base/query.go with package name change |
| infrastructure/query/user.go | Updated import reference for GetWithPagination function |
| go.mod | Made validator/v10 a direct dependency |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or 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.
Description
This pull request refactors the user controller logic for CRUD operations by introducing generic handler functions to reduce code duplication and standardize error handling. It also updates the user picture change workflow to simplify the service interface, and moves the generic query logic to a more appropriate package. Some test and DTO adjustments are made to match these changes.
Controller Refactoring and Handler Abstraction:
HandleCreate,HandleGetAll,HandleGetByID,HandleUpdate,HandleDelete) inapi/v1/controller/generic.goto standardize and simplify CRUD operations in controllers, replacing repetitive code inuser.go. [1] [2] [3]User Picture Change Workflow Simplification:
UserChangePictureRequestDTO to include anIDfield, so service methods no longer need a separate user ID argument.UserServiceinterface and implementation:ChangePicturenow takes only a single DTO argument (with the ID inside), not a separateuserID. [1] [2]ChangePicture. [1] [2] [3]Query Layer Refactor:
support/base/query.gotoinfrastructure/query/generic.goand updated usages to import from the new location. [1] [2] [3]Dependency and Import Cleanup:
github.com/go-playground/validator/v10a direct dependency ingo.modto ensure proper validation support.reflect) fromuser.goafter controller refactoring.Change
Check all options that are relevant.
Checklist