Class UserRepositoryAdapterImpl
java.lang.Object
com.example.blogs.app.api.user.repository.adapter.UserRepositoryAdapterImpl
- All Implemented Interfaces:
UserRepositoryAdapter
Translates database constraint violations and errors into domain-specific exceptions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionFinds a user by their unique ID.findByUsername(String username) Finds a user by username and translates exceptions to domain-specific errors.findByUsernameOrEmail(String usernameOrEmail) Finds a user by username or email address.save(CreateUserCommand command) Persists a new user entity.update(UserEntity userEntity) Updates an existing user entity and translates exceptions to domain-specific errors.
-
Constructor Details
-
UserRepositoryAdapterImpl
public UserRepositoryAdapterImpl()
-
-
Method Details
-
save
Description copied from interface:UserRepositoryAdapterPersists a new user entity.- Specified by:
savein interfaceUserRepositoryAdapter- Parameters:
command- user creation details- Returns:
- the saved user entity
-
findByUsernameOrEmail
Description copied from interface:UserRepositoryAdapterFinds a user by username or email address.- Specified by:
findByUsernameOrEmailin interfaceUserRepositoryAdapter- Parameters:
usernameOrEmail- the username or email to search for- Returns:
- the matching user entity
-
findByUsername
Finds a user by username and translates exceptions to domain-specific errors.- Specified by:
findByUsernamein interfaceUserRepositoryAdapter- Parameters:
username- the username to search for- Returns:
- the matching user entity
- Throws:
UserNotFoundException- if no user is foundFailedToFindUserException- for database errors
-
findById
Description copied from interface:UserRepositoryAdapterFinds a user by their unique ID.- Specified by:
findByIdin interfaceUserRepositoryAdapter- Parameters:
id- the user ID to search for- Returns:
- the matching user entity
-
update
Updates an existing user entity and translates exceptions to domain-specific errors. Handles uniqueness constraint violations for username and email updates.- Specified by:
updatein interfaceUserRepositoryAdapter- Parameters:
userEntity- the user entity to update with new values- Returns:
- the updated user entity
- Throws:
UsernameTakenException- if updated username is already takenEmailTakenException- if updated email is already takenFailedToUpdateUserException- for database update failures
-