Class UserRepositoryImpl

java.lang.Object
com.fiap.tech_challenge.parte1.ms_users.repositories.UserRepositoryImpl
All Implemented Interfaces:
UserRepository

@Repository public class UserRepositoryImpl extends Object implements 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 Details

    • UserRepositoryImpl

      public UserRepositoryImpl(org.springframework.jdbc.core.simple.JdbcClient jdbcClient)
      Constructs a new UserRepositoryImpl with the provided JdbcClient.
      Parameters:
      jdbcClient - the JdbcClient used to execute SQL queries
  • Method Details

    • findById

      public Optional<User> findById(UUID id)
      Finds a user by their unique identifier.
      Specified by:
      findById in interface UserRepository
      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

      public boolean emailAlreadyExistsForDifferentUsers(String email, UUID id)
      Checks if an email already exists in the database for a different user than the one specified.
      Specified by:
      emailAlreadyExistsForDifferentUsers in interface UserRepository
      Parameters:
      email - the email to check for existence
      id - the UUID of the user to exclude from the check
      Returns:
      true if another user with the email exists, false otherwise
    • loginAlreadyExistsForDifferentUsers

      public boolean loginAlreadyExistsForDifferentUsers(String login, UUID id)
      Checks if a login already exists in the database for a different user than the one specified.
      Specified by:
      loginAlreadyExistsForDifferentUsers in interface UserRepository
      Parameters:
      login - the login to check for existence
      id - the UUID of the user to exclude from the check
      Returns:
      true if another user with the login exists, false otherwise
    • findByLogin

      public Optional<User> findByLogin(String login)
      Finds a user by their login.
      Specified by:
      findByLogin in interface UserRepository
      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

      public List<User> findAll(int size, int offset)
      Retrieves a paginated list of users from the database.
      Specified by:
      findAll in interface UserRepository
      Parameters:
      size - the maximum number of users to return
      offset - the number of users to skip (offset) for pagination
      Returns:
      a list of User entities
    • save

      public UUID save(User user)
      Saves a new user entity in the database.
      Specified by:
      save in interface UserRepository
      Parameters:
      user - the User entity to save
      Returns:
      the UUID assigned to the newly saved user
    • existsByEmail

      public boolean existsByEmail(String email)
      Checks if any user exists with the specified email.
      Specified by:
      existsByEmail in interface UserRepository
      Parameters:
      email - the email to check for existence
      Returns:
      true if a user with the email exists, false otherwise
    • existsByLogin

      public boolean existsByLogin(String login)
      Checks if any user exists with the specified login.
      Specified by:
      existsByLogin in interface UserRepository
      Parameters:
      login - the login to check for existence
      Returns:
      true if a user with the login exists, false otherwise
    • deactivate

      public void deactivate(UUID id)
      Deactivates a user account by setting the active flag to false and updating the last modified date.
      Specified by:
      deactivate in interface UserRepository
      Parameters:
      id - the UUID of the user to deactivate
    • reactivate

      public void reactivate(UUID id)
      Reactivates a user account by setting the active flag to true and updating the last modified date.
      Specified by:
      reactivate in interface UserRepository
      Parameters:
      id - the UUID of the user to reactivate
    • changePassword

      public void changePassword(UUID id, String password)
      Changes the password of the specified user and updates the last modified date.
      Specified by:
      changePassword in interface UserRepository
      Parameters:
      id - the UUID of the user whose password is to be changed
      password - the new password (expected to be already hashed)
    • update

      public void update(UUID id, String name, String email, String login, String password)
      Updates the basic information of an existing user, including name, email, login, and password.
      Specified by:
      update in interface UserRepository
      Parameters:
      id - the UUID of the user to update
      name - the new name for the user
      email - the new email for the user
      login - the new login for the user
      password - the new password (expected to be hashed)