Class UserDetailsServiceImpl

java.lang.Object
com.myhrcrmproject.service.UserDetailsServiceImpl
All Implemented Interfaces:
CommonService<UserDetailsRequestDTO,UserDetailsResponseDTO>, org.springframework.security.core.userdetails.UserDetailsService

@Service public class UserDetailsServiceImpl extends Object implements CommonService<UserDetailsRequestDTO,UserDetailsResponseDTO>, org.springframework.security.core.userdetails.UserDetailsService
Service class that handles CRUD (Create, Read, Update, Delete) operations for user details entities.

This service provides methods to perform operations on user details entities, such as retrieving, creating, updating, and deleting user details records. It also includes additional methods for setting user roles and implementing Spring Security's UserDetailsService.

Version:
1.0
Author:
Denys Chaykovskyy
  • Constructor Details

    • UserDetailsServiceImpl

      public UserDetailsServiceImpl()
  • Method Details

    • findAll

      public List<UserDetailsResponseDTO> findAll()
      Retrieves a list of all user details records.
      Specified by:
      findAll in interface CommonService<UserDetailsRequestDTO,UserDetailsResponseDTO>
      Returns:
      A list of response DTOs representing all user details records.
    • findById

      public UserDetailsResponseDTO findById(Integer id)
      Retrieves a user details record by its unique identifier.
      Specified by:
      findById in interface CommonService<UserDetailsRequestDTO,UserDetailsResponseDTO>
      Parameters:
      id - The identifier of the user details record to retrieve.
      Returns:
      The response DTO representing the retrieved user details record.
      Throws:
      NotFoundException - if the user details record with the specified id is not found.
    • create

      public UserDetailsResponseDTO create(UserDetailsRequestDTO requestDTO)
      Creates a new user details record based on the provided request DTO.
      Specified by:
      create in interface CommonService<UserDetailsRequestDTO,UserDetailsResponseDTO>
      Parameters:
      requestDTO - The request DTO containing information for creating the user details record.
      Returns:
      The response DTO representing the created user details record.
      Throws:
      AlreadyExistsException - if a user with the specified username already exists.
    • update

      public UserDetailsResponseDTO update(Integer id, UserDetailsRequestDTO requestDTO)
      Updates an existing user details record based on the provided id and request DTO.
      Specified by:
      update in interface CommonService<UserDetailsRequestDTO,UserDetailsResponseDTO>
      Parameters:
      id - The identifier of the user details record to update.
      requestDTO - The request DTO containing information for updating the user details record.
      Returns:
      The response DTO representing the updated user details record.
      Throws:
      NotFoundException - if the user details record with the specified id is not found.
    • delete

      public void delete(Integer id)
      Deletes a user details record based on the provided id.
      Specified by:
      delete in interface CommonService<UserDetailsRequestDTO,UserDetailsResponseDTO>
      Parameters:
      id - The identifier of the user details record to delete.
      Throws:
      NotFoundException - if the user details record with the specified id is not found.
    • setRole

      public UserDetailsShortResponseDTO setRole(Integer id, String userRole)
      Sets the role of a user based on the provided id and role name.
      Parameters:
      id - The identifier of the user details record to update.
      userRole - The name of the role to set.
      Returns:
      The short response DTO representing the user details record with the updated role.
      Throws:
      NotFoundException - if the user details record with the specified id or the specified role is not found.
    • loadUserByUsername

      public org.springframework.security.core.userdetails.UserDetails loadUserByUsername(String userName) throws org.springframework.security.core.userdetails.UsernameNotFoundException
      Loads a user by the given username.
      Specified by:
      loadUserByUsername in interface org.springframework.security.core.userdetails.UserDetailsService
      Parameters:
      userName - The username of the user to load.
      Returns:
      The UserDetails object representing the loaded user.
      Throws:
      org.springframework.security.core.userdetails.UsernameNotFoundException - if the user with the specified username is not found.