java.lang.Object
org.ntnu.idi.idatt2106.sparesti.sparestibackend.service.UserService

@Service public class UserService extends Object
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 Details Link icon

    • UserService Link icon

      public UserService()
  • Method Details Link icon

    • save Link icon

      public User save(User user)
      Persists a user entity
      Parameters:
      user - User entity
      Returns:
      The saved user entity
    • findUserByUsername Link icon

      public User findUserByUsername(String username) throws UserNotFoundException
      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 Link icon

      public UserResponse findUserByUsernameToDTO(String username)
      Finds user by their username
      Parameters:
      username - Username of user
      Returns:
      User with matching username
    • findUserByEmail Link icon

      public User findUserByEmail(String email) throws EmailNotFoundException
      Find user by their email
      Parameters:
      email - Email of user
      Returns:
      User with matching email
      Throws:
      EmailNotFoundException - If email could not be found
    • updateUser Link icon

      public UserResponse updateUser(String username, UserUpdateDTO updateDTO)
      Updates a user specified by their username
      Parameters:
      username - username of user
      updateDTO - Updated user changes
      Returns:
      Updated user
    • userExistByEmail Link icon

      public boolean userExistByEmail(String email)
      Determines whether a user with the given email exists
      Parameters:
      email - Email
      Returns:
      True, if a user with the given email exists
    • updatePassword Link icon

      public void updatePassword(Long userID, String newPassword)
      Updates a user's password
      Parameters:
      userID - Identifies a user
      newPassword - New password of user
    • getStreak Link icon

      public StreakResponse getStreak(String username) throws UserNotFoundException
      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