Class UserProfileServiceImpl

java.lang.Object
api.mpba.rastvdmy.service.generator.FinancialDataGenerator
api.mpba.rastvdmy.service.impl.UserProfileServiceImpl
All Implemented Interfaces:
UserProfileService

@Service public class UserProfileServiceImpl extends FinancialDataGenerator implements UserProfileService
Service implementation for managing user profiles. This class provides methods for retrieving, updating, and deleting user profiles, as well as handling user authentication and authorization. It also includes methods for encrypting and decrypting user data.
  • Constructor Details

    • UserProfileServiceImpl

      @Autowired public UserProfileServiceImpl(UserProfileRepository userProfileRepository, JwtService jwtService, org.springframework.security.crypto.password.PasswordEncoder passwordEncoder, GenerateAccessToken generateAccessToken, UserDataValidator userDataValidator)
      Constructs a new UserProfileServiceImpl with the specified repository, JWT service, password encoder, REST template, and access token generator.
      Parameters:
      userProfileRepository - The repository for user profiles.
      jwtService - The service for handling JWT tokens.
      passwordEncoder - The encoder for hashing passwords.
      generateAccessToken - The generator for access tokens.
      userDataValidator - The validator for user data.
  • Method Details

    • getUsers

      @Cacheable("users") public List<UserProfile> getUsers(jakarta.servlet.http.HttpServletRequest request)
      Retrieves all user profiles with decrypted data.
      Specified by:
      getUsers in interface UserProfileService
      Parameters:
      request - the HTTP request containing user authentication data
      Returns:
      a list of user profiles
    • filterAndSortUsers

      @Cacheable("users") public org.springframework.data.domain.Page<UserProfile> filterAndSortUsers(jakarta.servlet.http.HttpServletRequest request, org.springframework.data.domain.Pageable pageable)
      Filters and sorts user profiles based on pagination.
      Specified by:
      filterAndSortUsers in interface UserProfileService
      Parameters:
      request - the HTTP request containing user authentication data
      pageable - pagination information
      Returns:
      a paginated list of user profiles
    • getUser

      @Cacheable("users") public UserProfile getUser(jakarta.servlet.http.HttpServletRequest request)
      Retrieves a user profile based on the authenticated user.
      Specified by:
      getUser in interface UserProfileService
      Parameters:
      request - the HTTP request containing user authentication data
      Returns:
      the user profile of the authenticated user
    • getUserById

      @Cacheable("users") public UserProfile getUserById(jakarta.servlet.http.HttpServletRequest request, UUID id)
      Retrieves a user profile by its unique ID.
      Specified by:
      getUserById in interface UserProfileService
      Parameters:
      request - the HTTP request containing user authentication data
      id - the unique ID of the user profile
      Returns:
      the user profile
    • updateUser

      @CachePut(value="users", key="#request.userPrincipal.name + \'_update\'") public UserProfile updateUser(jakarta.servlet.http.HttpServletRequest request, UserUpdateRequest userRequest) throws Exception
      Updates the user profile with new information.
      Specified by:
      updateUser in interface UserProfileService
      Parameters:
      request - the HTTP request containing user authentication data
      userRequest - the new user data
      Returns:
      the updated user profile
      Throws:
      Exception - if an error occurs during the update
    • updateUserSpecificCredentials

      @CachePut(value="users", key="#request.userPrincipal.name + \'_admin_update\'") public UserProfile updateUserSpecificCredentials(jakarta.servlet.http.HttpServletRequest request, UUID userId, @Valid @Valid AdminUpdateUserRequest userRequest)
      Admin updates the user profile with new information.
      Specified by:
      updateUserSpecificCredentials in interface UserProfileService
      Parameters:
      request - the HTTP request containing user authentication data
      userId - the unique ID of the user profile
      userRequest - the new user data
      Returns:
      the updated user profile
    • generateToken

      public String generateToken(UserProfile userProfile)
      Generates an access token for the user profile.
      Specified by:
      generateToken in interface UserProfileService
      Parameters:
      userProfile - the user profile
      Returns:
      the generated access token
    • uploadUserAvatar

      @CachePut(value="users", key="#request.userPrincipal.name") public void uploadUserAvatar(jakarta.servlet.http.HttpServletRequest request, org.springframework.web.multipart.MultipartFile userAvatar)
      Uploads a user avatar image.
      Specified by:
      uploadUserAvatar in interface UserProfileService
      Parameters:
      request - the HTTP request containing user authentication data
      userAvatar - the user avatar image
    • removeUserAvatar

      @CachePut(value="users", key="#request.userPrincipal.name") public void removeUserAvatar(jakarta.servlet.http.HttpServletRequest request)
      Removes the user avatar image.
      Specified by:
      removeUserAvatar in interface UserProfileService
      Parameters:
      request - the HTTP request containing user authentication data
    • updateUserRole

      @CachePut(value="users", key="#request.userPrincipal.name") public void updateUserRole(jakarta.servlet.http.HttpServletRequest request, UUID userId)
      Updates the user role.
      Specified by:
      updateUserRole in interface UserProfileService
      Parameters:
      request - the HTTP request containing user authentication data
      userId - the unique ID of the user profile
    • updateUserStatus

      @CachePut(value="users", key="#request.userPrincipal.name") public void updateUserStatus(jakarta.servlet.http.HttpServletRequest request, UUID userId)
      Updates the user status.
      Specified by:
      updateUserStatus in interface UserProfileService
      Parameters:
      request - the HTTP request containing user authentication data
      userId - the unique ID of the user profile
    • deleteUser

      @Transactional public void deleteUser(jakarta.servlet.http.HttpServletRequest request)
      Deletes the user profile.
      Specified by:
      deleteUser in interface UserProfileService
      Parameters:
      request - the HTTP request containing user authentication data
    • deleteUserByEmail

      @Transactional public void deleteUserByEmail(jakarta.servlet.http.HttpServletRequest request, UUID userId)
      Deletes the user profile by email.
      Specified by:
      deleteUserByEmail in interface UserProfileService
      Parameters:
      request - the HTTP request containing user authentication data
      userId - the unique ID of the user profile
    • userDetailsService

      public org.springframework.security.core.userdetails.UserDetailsService userDetailsService()
      Retrieves the user details service.
      Specified by:
      userDetailsService in interface UserProfileService
      Returns:
      the user details service