Skip to content

fix(archi): clean archi of the project#89

Merged
MayuriXx merged 1 commit into
mainfrom
fix/clean-archi
May 7, 2026
Merged

fix(archi): clean archi of the project#89
MayuriXx merged 1 commit into
mainfrom
fix/clean-archi

Conversation

@MayuriXx
Copy link
Copy Markdown
Collaborator

@MayuriXx MayuriXx commented May 5, 2026

Refactoring Summary — Clean Architecture
✅ 1. Single UserService at the data level
"Local or Remote is only one service in the data level"
Created domain/services/UserService.java — single interface merging LocalUserService (CRUD) + fetchAndSaveUsers (remote fetch + save)
Created data/sources/api/RemoteUserService.java — interface moved from domain to data layer (internal use only)
Deleted domain/services/LocalUserService.java
Deleted domain/services/RemoteUserService.java (domain level)
Updated data/services/UserServiceImpl.java — now implements UserService, injects List internally, dispatches by UserSource
Updated DummyUserServiceImpl & RandomUserServiceImpl — imports updated to data.sources.api.RemoteUserService
Simplified all use cases: LocalUserService → UserService
FetchAndSaveRandomUsersUseCase reduced to a single userService.fetchAndSaveUsers(page, size, source) call

✅ 2. UserRequest and PaginatedRequest in the presentation layer
Created presentation/dto/UserRequest.java — HTTP input DTO for create/update endpoints
Created presentation/dto/PaginatedRequest.java — record with toPageable() using Spring Data PageRequest
Deleted domain/entities/UserRequest.java
CreateUserUseCase and UpdateRandomUserUseCase now accept UserEntity directly (no domain → presentation dependency)
UserHandler converts UserRequest → UserEntity via a private toEntity() helper

✅ 3. Pagination in the database (not only API)
UserService.filterUsers now returns Page and takes a Pageable
UserServiceImpl.filterUsers uses userRepository.findAll(spec, pageable) (Spring Data JPA)
FilterUsersUseCase.execute takes (UserFilter, Pageable)
GET /random-users/filter endpoint adds page (default: 0) and size (default: 20) as @RequestParam
UserHandler.filterUsers builds a PaginatedRequest and calls toPageable() before delegating

✅ 4. Single UserApiConfig for Dummy and Random User APIs
Created data/sources/api/UserApiConfig.java — merges all 4 Retrofit beans: dummyUserRetrofit, dummyUserApi, randomUserRetrofit, randomUserApi
Deleted data/sources/api/dummy/DummyUserApiConfig.java
Deleted data/sources/api/randomuser/RandomUserApiConfig.java

🧪 Tests updated
All 34 unit tests pass. Updated files: CreateUserDTOUseCaseTest, UpdateRandomUserDTOUseCaseTest, FetchAndSaveRandomUsersUseCaseTest, FilterUsersUseCaseTest, UserDTOServiceImplTest, UserDTOHandlerTest, GetUserDTOByIdUseCaseTest, DeleteUserDTOByIdUseCaseTest, StepDefinition, CucumberTypeConfig.

@MayuriXx MayuriXx linked an issue May 5, 2026 that may be closed by this pull request
@MayuriXx MayuriXx force-pushed the fix/clean-archi branch 3 times, most recently from ee6c9f6 to b63cb9b Compare May 5, 2026 11:45
@MayuriXx MayuriXx marked this pull request as ready for review May 5, 2026 11:45
Copilot AI review requested due to automatic review settings May 5, 2026 11:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the project toward a cleaner layered architecture by consolidating user service responsibilities, moving HTTP DTOs to the presentation layer, and adding database-backed pagination for filtering. It also consolidates API Retrofit configuration and renames the persistence model to UserDAO, with broad test and documentation updates.

Changes:

  • Introduces a single domain.services.UserService (merging local CRUD + remote fetch-and-save) and updates use cases/handlers accordingly.
  • Moves UserRequest into the presentation layer, adds PaginatedRequest, and updates the filter endpoint to return paginated results (Page<UserEntity>).
  • Consolidates Dummy/RandomUser Retrofit beans into UserApiConfig, renames DB entity UserUserDAO, and updates tests/docs.

Reviewed changes

Copilot reviewed 55 out of 55 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
src/test/resources/application-test.properties Renames security property keys for the “user” credentials in tests.
src/test/java/features/StepDefinition.java Updates package and switches UserRequest import to presentation DTO.
src/test/java/features/SpringIntegrationTest.java Updates Cucumber Spring glue package name.
src/test/java/features/CucumberTypeConfig.java Updates package/imports and translates JavaDoc to English.
src/test/java/features/CucumberIntegrationTest.java Updates Cucumber glue configuration to features.
src/test/java/com/xpeho/spring_boot_java_random_user/SpringBootJavaRandomUserDAOApplicationTests.java Renames test class to match DAO naming.
src/test/java/com/xpeho/spring_boot_java_random_user/presentation/UserDAOHandlerTest.java Updates handler tests for DTO mapping + pagination + new use case signatures.
src/test/java/com/xpeho/spring_boot_java_random_user/presentation/UserDAOGetByIdContainerTest.java Updates container test to persist UserDAO instead of User.
src/test/java/com/xpeho/spring_boot_java_random_user/domain/usecases/UpdateRandomUserDAOUseCaseTest.java Updates use case test to use UserService and UserEntity payload.
src/test/java/com/xpeho/spring_boot_java_random_user/domain/usecases/GetUserDAOByIdUseCaseTest.java Updates use case test to use UserService.
src/test/java/com/xpeho/spring_boot_java_random_user/domain/usecases/FilterUsersUseCaseTest.java Updates filtering test to use Page + Pageable.
src/test/java/com/xpeho/spring_boot_java_random_user/domain/usecases/FetchAndSaveRandomUsersUseCaseTest.java Updates test to call UserService.fetchAndSaveUsers(...) directly.
src/test/java/com/xpeho/spring_boot_java_random_user/domain/usecases/DeleteUserDAOByIdUseCaseTest.java Updates delete test to use UserService.
src/test/java/com/xpeho/spring_boot_java_random_user/domain/usecases/CreateUserDAOUseCaseTest.java Updates create test to use UserEntity input and UserService.
src/test/java/com/xpeho/spring_boot_java_random_user/data/sources/RandomUserDAOServiceImplTest.java Renames test class to match DAO naming.
src/test/java/com/xpeho/spring_boot_java_random_user/data/sources/DummyUserDAOServiceImplTest.java Renames test class to match DAO naming.
src/test/java/com/xpeho/spring_boot_java_random_user/data/sources/database/UserDAOSpecificationsTest.java Updates specs test generics to UserDAO.
src/test/java/com/xpeho/spring_boot_java_random_user/data/services/UserDAOServiceImplTest.java Updates service test for Pageable + UserDAO entity type.
src/test/java/com/xpeho/spring_boot_java_random_user/data/models/api/randomuser/RandomUserDTOResultDAOTest.java Renames DTO test class.
src/test/java/com/xpeho/spring_boot_java_random_user/data/models/api/randomuser/RandomUserDTOResponseDAOTest.java Renames DTO test class.
src/test/java/com/xpeho/spring_boot_java_random_user/data/models/api/randomuser/RandomUserDTOPictureDAOTest.java Renames DTO test class.
src/test/java/com/xpeho/spring_boot_java_random_user/data/models/api/randomuser/RandomUserDTONameDAOTest.java Renames DTO test class.
src/test/java/com/xpeho/spring_boot_java_random_user/data/models/api/dummy/DummyUserDTOResultDAOTest.java Renames DTO test class.
src/test/java/com/xpeho/spring_boot_java_random_user/data/models/api/dummy/DummyUserDAOResponseTest.java Renames DTO response test class.
src/test/java/com/xpeho/spring_boot_java_random_user/data/converters/UserDAOConverterTest.java Renames converter test + updates DAO type.
src/main/resources/application.properties Renames security property keys; minor doc string tweak.
src/main/java/com/xpeho/spring_boot_java_random_user/presentation/handlers/UserHandler.java Maps UserRequestUserEntity, returns Page<UserEntity> for filtering.
src/main/java/com/xpeho/spring_boot_java_random_user/presentation/exceptions/GlobalExceptionHandler.java Adjusts not-found logging message wording.
src/main/java/com/xpeho/spring_boot_java_random_user/presentation/dto/UserRequest.java Moves UserRequest record into presentation layer.
src/main/java/com/xpeho/spring_boot_java_random_user/presentation/dto/PaginatedRequest.java Adds helper record to build Spring Pageable.
src/main/java/com/xpeho/spring_boot_java_random_user/presentation/controllers/UserController.java Updates API docs and changes filter to paginated response.
src/main/java/com/xpeho/spring_boot_java_random_user/domain/usecases/UpdateRandomUserUseCase.java Changes input from request DTO to UserEntity and uses UserService.
src/main/java/com/xpeho/spring_boot_java_random_user/domain/usecases/GetUserByIdUseCase.java Switches service dependency to UserService.
src/main/java/com/xpeho/spring_boot_java_random_user/domain/usecases/FilterUsersUseCase.java Returns Page<UserEntity> and accepts Pageable.
src/main/java/com/xpeho/spring_boot_java_random_user/domain/usecases/FetchAndSaveRandomUsersUseCase.java Simplifies to a single call into UserService.fetchAndSaveUsers(...).
src/main/java/com/xpeho/spring_boot_java_random_user/domain/usecases/DeleteUserByIdUseCase.java Switches service dependency to UserService.
src/main/java/com/xpeho/spring_boot_java_random_user/domain/usecases/CreateUserUseCase.java Changes input to UserEntity (ensures persisted ID is not taken from input).
src/main/java/com/xpeho/spring_boot_java_random_user/domain/services/UserService.java New consolidated domain service interface.
src/main/java/com/xpeho/spring_boot_java_random_user/domain/services/LocalUserService.java Removes old local-only service interface.
src/main/java/com/xpeho/spring_boot_java_random_user/domain/exceptions/UserNotFoundException.java Changes exception message wording.
src/main/java/com/xpeho/spring_boot_java_random_user/data/sources/database/UserSpecifications.java Updates specifications to work with UserDAO.
src/main/java/com/xpeho/spring_boot_java_random_user/data/sources/database/UserRepository.java Updates repository generics to UserDAO.
src/main/java/com/xpeho/spring_boot_java_random_user/data/sources/api/UserApiConfig.java New shared Retrofit/OkHttp configuration for both APIs.
src/main/java/com/xpeho/spring_boot_java_random_user/data/sources/api/RemoteUserService.java Moves remote service contract into data layer package.
src/main/java/com/xpeho/spring_boot_java_random_user/data/sources/api/randomuser/RandomUserServiceImpl.java Updates import to new RemoteUserService location.
src/main/java/com/xpeho/spring_boot_java_random_user/data/sources/api/randomuser/RandomUserApiConfig.java Removes old per-API config in favor of shared config.
src/main/java/com/xpeho/spring_boot_java_random_user/data/sources/api/dummy/DummyUserServiceImpl.java Updates import to new RemoteUserService location.
src/main/java/com/xpeho/spring_boot_java_random_user/data/sources/api/dummy/DummyUserApiConfig.java Removes old per-API config in favor of shared config.
src/main/java/com/xpeho/spring_boot_java_random_user/data/services/UserServiceImpl.java Implements consolidated UserService, adds pageable filtering + remote dispatch.
src/main/java/com/xpeho/spring_boot_java_random_user/data/models/database/UserDAO.java Renames JPA entity UserUserDAO.
src/main/java/com/xpeho/spring_boot_java_random_user/data/converters/UserConverter.java Updates converter to map to/from UserDAO.
README.md Updates API docs and architecture text; several wording changes.
pom.xml Updates Sonar test exclusion path for new Cucumber package.
mvnw.cmd Updates a header comment string.
Dockerfile Updates comment strings about non-root user.

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

Comment thread src/main/resources/application.properties
Comment thread src/test/resources/application-test.properties
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread README.md Outdated
Comment thread Dockerfile Outdated
Comment thread mvnw.cmd
@MayuriXx MayuriXx requested a review from Theo-lbg May 6, 2026 10:10
Copy link
Copy Markdown
Collaborator

@Theo-lbg Theo-lbg left a comment

Choose a reason for hiding this comment

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

LGTM

@MayuriXx MayuriXx force-pushed the fix/clean-archi branch from b63cb9b to e98147d Compare May 7, 2026 08:40
@sonarqube-xpeho
Copy link
Copy Markdown

@MayuriXx MayuriXx merged commit 799c782 into main May 7, 2026
13 checks passed
@MayuriXx MayuriXx deleted the fix/clean-archi branch May 7, 2026 08:49
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.

Check the architecture of the project

3 participants