Class UserRepositoryImpl
java.lang.Object
com.fiap.tech_challenge.parte1.ms_users.repositories.UserRepositoryImpl
- All Implemented Interfaces:
UserRepository
Implementation of the
UserRepository interface using Spring's JdbcClient for data access.
Handles CRUD operations and queries related to User entities in the database.-
Constructor Summary
ConstructorsConstructorDescriptionUserRepositoryImpl(org.springframework.jdbc.core.simple.JdbcClient jdbcClient) Constructs a new UserRepositoryImpl with the providedJdbcClient. -
Method Summary
Modifier and TypeMethodDescriptionvoidchangePassword(UUID id, String password) Changes the password of the specified user and updates the last modified date.voiddeactivate(UUID id) Deactivates a user account by setting the active flag to false and updating the last modified date.booleanemailAlreadyExistsForDifferentUsers(String email, UUID id) Checks if an email already exists in the database for a different user than the one specified.booleanexistsByEmail(String email) Checks if any user exists with the specified email.booleanexistsByLogin(String login) Checks if any user exists with the specified login.findAll(int size, int offset) Retrieves a paginated list of users from the database.Finds a user by their unique identifier.findByLogin(String login) Finds a user by their login.booleanloginAlreadyExistsForDifferentUsers(String login, UUID id) Checks if a login already exists in the database for a different user than the one specified.voidreactivate(UUID id) Reactivates a user account by setting the active flag to true and updating the last modified date.Saves a new user entity in the database.voidUpdates the basic information of an existing user, including name, email, login, and password.
-
Constructor Details
-
UserRepositoryImpl
public UserRepositoryImpl(org.springframework.jdbc.core.simple.JdbcClient jdbcClient) Constructs a new UserRepositoryImpl with the providedJdbcClient.- Parameters:
jdbcClient- the JdbcClient used to execute SQL queries
-
-
Method Details
-
findById
Finds a user by their unique identifier.- Specified by:
findByIdin interfaceUserRepository- Parameters:
id- the UUID of the user to find- Returns:
- an Optional containing the User if found, or empty if no user with the given ID exists
-
emailAlreadyExistsForDifferentUsers
Checks if an email already exists in the database for a different user than the one specified.- Specified by:
emailAlreadyExistsForDifferentUsersin interfaceUserRepository- Parameters:
email- the email to check for existenceid- the UUID of the user to exclude from the check- Returns:
- true if another user with the email exists, false otherwise
-
loginAlreadyExistsForDifferentUsers
Checks if a login already exists in the database for a different user than the one specified.- Specified by:
loginAlreadyExistsForDifferentUsersin interfaceUserRepository- Parameters:
login- the login to check for existenceid- the UUID of the user to exclude from the check- Returns:
- true if another user with the login exists, false otherwise
-
findByLogin
Finds a user by their login.- Specified by:
findByLoginin interfaceUserRepository- Parameters:
login- the login string to search by- Returns:
- an Optional containing the User if found, or empty if no user with the login exists
-
findAll
Retrieves a paginated list of users from the database.- Specified by:
findAllin interfaceUserRepository- Parameters:
size- the maximum number of users to returnoffset- the number of users to skip (offset) for pagination- Returns:
- a list of User entities
-
save
Saves a new user entity in the database.- Specified by:
savein interfaceUserRepository- Parameters:
user- the User entity to save- Returns:
- the UUID assigned to the newly saved user
-
existsByEmail
Checks if any user exists with the specified email.- Specified by:
existsByEmailin interfaceUserRepository- Parameters:
email- the email to check for existence- Returns:
- true if a user with the email exists, false otherwise
-
existsByLogin
Checks if any user exists with the specified login.- Specified by:
existsByLoginin interfaceUserRepository- Parameters:
login- the login to check for existence- Returns:
- true if a user with the login exists, false otherwise
-
deactivate
Deactivates a user account by setting the active flag to false and updating the last modified date.- Specified by:
deactivatein interfaceUserRepository- Parameters:
id- the UUID of the user to deactivate
-
reactivate
Reactivates a user account by setting the active flag to true and updating the last modified date.- Specified by:
reactivatein interfaceUserRepository- Parameters:
id- the UUID of the user to reactivate
-
changePassword
Changes the password of the specified user and updates the last modified date.- Specified by:
changePasswordin interfaceUserRepository- Parameters:
id- the UUID of the user whose password is to be changedpassword- the new password (expected to be already hashed)
-
update
Updates the basic information of an existing user, including name, email, login, and password.- Specified by:
updatein interfaceUserRepository- Parameters:
id- the UUID of the user to updatename- the new name for the useremail- the new email for the userlogin- the new login for the userpassword- the new password (expected to be hashed)
-