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 TypeMethodDescriptionvoid
changePassword
(UUID id, String password) Changes the password of the specified user and updates the last modified date.void
deactivate
(UUID id) Deactivates a user account by setting the active flag to false and updating the last modified date.boolean
emailAlreadyExistsForDifferentUsers
(String email, UUID id) Checks if an email already exists in the database for a different user than the one specified.boolean
existsByEmail
(String email) Checks if any user exists with the specified email.boolean
existsByLogin
(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.boolean
loginAlreadyExistsForDifferentUsers
(String login, UUID id) Checks if a login already exists in the database for a different user than the one specified.void
reactivate
(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.void
Updates 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:
findById
in 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:
emailAlreadyExistsForDifferentUsers
in 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:
loginAlreadyExistsForDifferentUsers
in 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:
findByLogin
in 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:
findAll
in 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:
save
in 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:
existsByEmail
in 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:
existsByLogin
in 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:
deactivate
in 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:
reactivate
in 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:
changePassword
in 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:
update
in 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)
-