Refactor: Eliminate duplicate code and optimize database queries (#1) - #12
Merged
Merged
Conversation
* Initial plan * Refactor: Fix duplicate DB queries, add validation, centralize mapping Co-authored-by: Krzykoz <72080194+Krzykoz@users.noreply.github.com> * Add validation and mapper unit tests Co-authored-by: Krzykoz <72080194+Krzykoz@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Krzykoz <72080194+Krzykoz@users.noreply.github.com>
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 introduces comprehensive improvements to validation, exception handling, code structure, and test coverage across the codebase. The most significant changes include adding validation annotations to DTOs and enforcing them in controllers, refactoring exception handling for consistency, centralizing entity-to-DTO mapping logic, optimizing user existence checks, and introducing unit tests for DTO validation.
Validation Enhancements:
@NotBlank,@Email,@Pattern) to DTOs such asAuthenticationRequest,RegisterRequest,UserRequest, andUrlRequestto enforce input constraints. [1] [2] [3] [4]@Validon request bodies, ensuring validation is triggered automatically for incoming API requests. [1] [2] [3] [4] [5]Exception Handling Improvements:
BaseExceptionclass to standardize custom exceptions.UrlNotFoundException,UserAlreadyExistsException,UserNotFoundException) to extend fromBaseExceptionfor consistent error handling. [1] [2] [3]Code Structure and Reusability:
EntityMapperto centralize and reuse logic for converting entities to DTOs, reducing code duplication in services.UserServiceandUrlServiceto useEntityMapperfor mapping entities to response DTOs, removing redundant mapping methods. [1] [2] [3] [4] [5] [6]Repository and Service Optimization:
existsByEmailOrUsernameto optimize user existence checks, replacing redundant queries inAuthenticationService. [1] [2]findByIdmethod fromUrlRepositoryto clean up unused code.Testing and Validation Coverage:
DtoValidationTestto thoroughly test validation constraints on all DTOs, ensuring correctness and robustness of validation logic.