Package api.mpba.rastvdmy.service.impl
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 Summary
ConstructorDescriptionUserProfileServiceImpl
(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. -
Method Summary
Modifier and TypeMethodDescriptionvoid
deleteUser
(jakarta.servlet.http.HttpServletRequest request) Deletes the user profile.void
deleteUserByEmail
(jakarta.servlet.http.HttpServletRequest request, UUID userId) Deletes the user profile by email.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.generateToken
(UserProfile userProfile) Generates an access token for the user profile.getUser
(jakarta.servlet.http.HttpServletRequest request) Retrieves a user profile based on the authenticated user.getUserById
(jakarta.servlet.http.HttpServletRequest request, UUID id) Retrieves a user profile by its unique ID.getUsers
(jakarta.servlet.http.HttpServletRequest request) Retrieves all user profiles with decrypted data.void
removeUserAvatar
(jakarta.servlet.http.HttpServletRequest request) Removes the user avatar image.updateUser
(jakarta.servlet.http.HttpServletRequest request, UserUpdateRequest userRequest) Updates the user profile with new information.void
updateUserRole
(jakarta.servlet.http.HttpServletRequest request, UUID userId) Updates the user role.updateUserSpecificCredentials
(jakarta.servlet.http.HttpServletRequest request, UUID userId, @Valid AdminUpdateUserRequest userRequest) Admin updates the user profile with new information.void
updateUserStatus
(jakarta.servlet.http.HttpServletRequest request, UUID userId) Updates the user status.void
uploadUserAvatar
(jakarta.servlet.http.HttpServletRequest request, org.springframework.web.multipart.MultipartFile userAvatar) Uploads a user avatar image.org.springframework.security.core.userdetails.UserDetailsService
Retrieves the user details service.Methods inherited from class api.mpba.rastvdmy.service.generator.FinancialDataGenerator
generateAccountNumber, generateBankNumber, generateCardNumber, generateCvv, generateIban, generatePin, generateSwift, getRandomExpirationDate, getRandomStartDate
-
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 interfaceUserProfileService
- 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 interfaceUserProfileService
- Parameters:
request
- the HTTP request containing user authentication datapageable
- pagination information- Returns:
- a paginated list of user profiles
-
getUser
Retrieves a user profile based on the authenticated user.- Specified by:
getUser
in interfaceUserProfileService
- 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 interfaceUserProfileService
- Parameters:
request
- the HTTP request containing user authentication dataid
- 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 interfaceUserProfileService
- Parameters:
request
- the HTTP request containing user authentication datauserRequest
- 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 interfaceUserProfileService
- Parameters:
request
- the HTTP request containing user authentication datauserId
- the unique ID of the user profileuserRequest
- the new user data- Returns:
- the updated user profile
-
generateToken
Generates an access token for the user profile.- Specified by:
generateToken
in interfaceUserProfileService
- 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 interfaceUserProfileService
- Parameters:
request
- the HTTP request containing user authentication datauserAvatar
- 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 interfaceUserProfileService
- 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 interfaceUserProfileService
- Parameters:
request
- the HTTP request containing user authentication datauserId
- 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 interfaceUserProfileService
- Parameters:
request
- the HTTP request containing user authentication datauserId
- 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 interfaceUserProfileService
- 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 interfaceUserProfileService
- Parameters:
request
- the HTTP request containing user authentication datauserId
- 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 interfaceUserProfileService
- Returns:
- the user details service
-