refactor: handle optional user inside userservice, replace @autowire #227

Merged
jank merged 2 commits from refactor-get-current-user into main 2025-05-28 08:50:56 +00:00
Member
No description provided.
ptran added 1 commit 2025-05-28 08:42:54 +00:00
refactor: handle optional user inside userservice, replace @autowire
All checks were successful
CI / Get Changed Files (pull_request) Successful in 11s
CI / eslint (pull_request) Has been skipped
CI / oxlint (pull_request) Has been skipped
CI / Docker frontend validation (pull_request) Has been skipped
CI / prettier (pull_request) Has been skipped
CI / test-build (pull_request) Has been skipped
CI / Checkstyle Main (pull_request) Successful in 51s
CI / Docker backend validation (pull_request) Successful in 53s
1c45ff0058
jank added 1 commit 2025-05-28 08:45:06 +00:00
Merge branch 'main' into refactor-get-current-user
All checks were successful
CI / Get Changed Files (pull_request) Successful in 8s
CI / eslint (pull_request) Has been skipped
CI / oxlint (pull_request) Has been skipped
CI / Docker frontend validation (pull_request) Has been skipped
CI / prettier (pull_request) Has been skipped
CI / test-build (pull_request) Has been skipped
CI / Docker backend validation (pull_request) Successful in 12s
CI / Checkstyle Main (pull_request) Successful in 30s
Setup Gitea Tea CLI / setup-and-login (pull_request) Successful in 1m3s
20b7c445e0
Collaborator

--body APPROVE

This refactoring improves code quality significantly:

Positive Changes:
Better dependency injection: Removed @Autowired annotations in favor of constructor injection, which is the recommended Spring practice for better testability and immutability
Cleaner user handling: Centralized Optional handling in UserService.getCurrentUser() - now returns UserEntity directly and throws UserNotFoundException internally, eliminating repetitive null checks
Reduced boilerplate: Removed 50+ lines of repetitive Optional.isEmpty() checks across multiple controllers
Consistent error handling: UserNotFoundException is now consistently thrown from a single location
Code maintainability: Easier to modify user retrieval logic in the future since it's centralized

Code Quality:

  • All changes follow Spring best practices
  • Maintains existing functionality while improving structure
  • No breaking changes to public APIs
  • Proper exception handling maintained

The refactoring successfully eliminates code duplication while maintaining the same error behavior. The centralized approach in UserService.getCurrentUser() is much cleaner than the previous scattered Optional handling.

--body **APPROVE** ✅ This refactoring improves code quality significantly: **Positive Changes:** ✅ **Better dependency injection**: Removed @Autowired annotations in favor of constructor injection, which is the recommended Spring practice for better testability and immutability ✅ **Cleaner user handling**: Centralized Optional<UserEntity> handling in UserService.getCurrentUser() - now returns UserEntity directly and throws UserNotFoundException internally, eliminating repetitive null checks ✅ **Reduced boilerplate**: Removed 50+ lines of repetitive Optional.isEmpty() checks across multiple controllers ✅ **Consistent error handling**: UserNotFoundException is now consistently thrown from a single location ✅ **Code maintainability**: Easier to modify user retrieval logic in the future since it's centralized **Code Quality:** - All changes follow Spring best practices - Maintains existing functionality while improving structure - No breaking changes to public APIs - Proper exception handling maintained The refactoring successfully eliminates code duplication while maintaining the same error behavior. The centralized approach in UserService.getCurrentUser() is much cleaner than the previous scattered Optional handling.
jank approved these changes 2025-05-28 08:47:17 +00:00
jank merged commit 7be0fc97bc into main 2025-05-28 08:50:56 +00:00
jank deleted branch refactor-get-current-user 2025-05-28 08:50:56 +00:00
Commenting is not possible because the repository is archived.
No reviewers
No milestone
No project
No assignees
3 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: SZUT/casino#227
No description provided.