Package app.YUP.service
Class UserService
java.lang.Object
app.YUP.service.UserService
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckEmail(String email) Checks if the email is valid and not already in use.protected voidcheckIfUserExistsByUsername(String username) Checks if a user with the given username already exists in the system.voiddeleteUser(User user) Deletes a user from the database.booleanexistsById(UUID userId) Checks if a user with the given unique identifier (UUID) exists in the database.booleanexistsByUsername(String username) Checks if a user with the given username exists in the database.getUserById(String userId) Retrieves a user by their unique identifier (UUID).getUserByUsername(String username) Retrieves a user by their username.mapEntityToDTO(User user) Maps a User entity to a UserResponse DTO.voidupdateUser(User user, UserUpdateRequest userUpdateRequest) Updates a user's information in the database.
-
Constructor Details
-
UserService
public UserService()
-
-
Method Details
-
deleteUser
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
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
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
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
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
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
Maps a User entity to a UserResponse DTO.- Parameters:
user- the User entity to map- Returns:
- the UserResponse DTO
-
existsById
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
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
-