Class UserService
java.lang.Object
org.ntnu.idi.idatt2106.sparesti.sparestibackend.service.UserService
Handles business logic related to the user entity. Adds an extra layer abstraction between
controller and the data layer.
- Since:
- 17.4.24
- Version:
- 1.0
- Author:
- Harry L.X and Lars M.L.N
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindUserByEmail
(String email) Find user by their emailfindUserByUsername
(String username) Finds a user from a given username.findUserByUsernameToDTO
(String username) Finds user by their usernameGets the streak of a user, identified by their usernamePersists a user entityvoid
updatePassword
(Long userID, String newPassword) Updates a user's passwordupdateUser
(String username, UserUpdateDTO updateDTO) Updates a user specified by their usernameboolean
userExistByEmail
(String email) Determines whether a user with the given email exists
-
Constructor Details
-
Method Details
-
save
Persists a user entity- Parameters:
user
- User entity- Returns:
- The saved user entity
-
findUserByUsername
Finds a user from a given username.- Parameters:
username
- Username used for finding a user- Returns:
- User entity with matching username
- Throws:
UserNotFoundException
- If no user has the given username
-
findUserByUsernameToDTO
Finds user by their username- Parameters:
username
- Username of user- Returns:
- User with matching username
-
findUserByEmail
Find user by their email- Parameters:
email
- Email of user- Returns:
- User with matching email
- Throws:
EmailNotFoundException
- If email could not be found
-
updateUser
Updates a user specified by their username- Parameters:
username
- username of userupdateDTO
- Updated user changes- Returns:
- Updated user
-
userExistByEmail
Determines whether a user with the given email exists- Parameters:
email
- Email- Returns:
- True, if a user with the given email exists
-
updatePassword
Updates a user's password- Parameters:
userID
- Identifies a usernewPassword
- New password of user
-
getStreak
Gets the streak of a user, identified by their username- Parameters:
username
- Username of user- Returns:
- Streak of the user
- Throws:
UserNotFoundException
- If the user could not be found
-