Class UserService

java.lang.Object
app.YUP.service.UserService

@Service public class UserService extends Object
This class represents the service layer for the User entity. It contains methods for creating, retrieving, and validating users. The class is annotated with Spring's @Service annotation to indicate that it's a service component.
Version:
1.0
  • Constructor Details

    • UserService

      public UserService()
  • Method Details

    • deleteUser

      public void deleteUser(User user)
      Deletes a user from the database.
      Parameters:
      user - the user to delete. If the user is null, a ResourceNotFoundException is thrown.
      Throws:
      ResourceNotFoundException - if the user to delete is null.
    • updateUser

      public void updateUser(User user, UserUpdateRequest userUpdateRequest)
      Updates a user's information in the database.
      Parameters:
      user - the user to update. If the user is null, a ResourceNotFoundException is thrown.
      userUpdateRequest - the updated information for the user. If the username or email is null or empty, an InvalidParameterException is thrown.
      Throws:
      ResourceNotFoundException - if the user to update is null.
      InvalidParameterException - if the username or email is null or empty.
    • getUserById

      public User getUserById(String userId)
      Retrieves a user by their unique identifier (UUID).
      Parameters:
      userId - the unique identifier of the user to retrieve
      Returns:
      the user with the given unique identifier
      Throws:
      ResourceNotFoundException - if the user with the given unique identifier is not found
    • getUserByUsername

      public User getUserByUsername(String username)
      Retrieves a user by their username.
      Parameters:
      username - the username of the user to retrieve
      Returns:
      the user with the given username
      Throws:
      ResourceNotFoundException - if the user with the given username is not found
    • existsByUsername

      public boolean existsByUsername(String username)
      Checks if a user with the given username exists in the database.
      Parameters:
      username - the username to check
      Returns:
      true if a user with the given username exists, false otherwise
    • checkIfUserExistsByUsername

      protected void checkIfUserExistsByUsername(String username)
      Checks if a user with the given username already exists in the system.
      Parameters:
      username - the username of the user to check
      Throws:
      ResourceNotFoundException - if the username already exists
    • mapEntityToDTO

      public UserResponse mapEntityToDTO(User user)
      Maps a User entity to a UserResponse DTO.
      Parameters:
      user - the User entity to map
      Returns:
      the UserResponse DTO
    • existsById

      public boolean existsById(UUID userId)
      Checks if a user with the given unique identifier (UUID) exists in the database.
      Parameters:
      userId - the unique identifier of the user to check
      Returns:
      true if a user with the given unique identifier exists, false otherwise
    • checkEmail

      protected void checkEmail(String email)
      Checks if the email is valid and not already in use.
      Parameters:
      email - the email to check
      Throws:
      InvalidParameterException - if the email is invalid or already in use