Class UserService

java.lang.Object
ntnu.idatt2016.v233.SmartMat.service.user.UserService

@Service public class UserService extends Object
UserService is a class that implements the UserDetailsService interface.
Version:
1.1
Author:
Birk, Stian
  • Constructor Details

    • UserService

      public UserService()
  • Method Details

    • getUserFromUsername

      public Optional<User> getUserFromUsername(String username)
      gets user from username out of database
      Parameters:
      username - username of user
      Returns:
      user
    • getUsers

      public List<User> getUsers()
      Gets all users from the database
    • updateUser

      public User updateUser(User user)
      update user if it already exists cant update username from this
      Parameters:
      user - user to update
      Returns:
      optional with user if succeded else return null
    • getPassword

      public String getPassword(String userName)
      gets password from user
      Parameters:
      userName - username of user
      Returns:
      password of user
    • saveUser

      public User saveUser(User user)
      saves user to database
      Parameters:
      user - user to save
      Returns:
      saved user
    • saveUsers

      public List<User> saveUsers(List<User> users)
      saves list of users to database
      Parameters:
      users - list of users to save
      Returns:
      list of saved users
    • delete

      public void delete(User user)
      deletes user from database
      Parameters:
      user - user to delete
    • getUserFromEmail

      public Optional<User> getUserFromEmail(String email)
      gets user from email out of database
      Parameters:
      email - email of user
      Returns:
      user
    • addFavoriteRecipe

      public void addFavoriteRecipe(String username, long recipeId) throws RuntimeException
      adds recipe to users favorite recipes
      Parameters:
      username - username of user
      recipeId - id of recipe
      Throws:
      RuntimeException - if user or recipe does not exist or user
    • addAllergyToUser

      public org.springframework.http.ResponseEntity<String> addAllergyToUser(String username, String allergyName)
      Adds allergy to user
      Parameters:
      username - username of user
      allergyName - name of allergy
      Returns:
      string of allergies
    • removeAllergyFromUser

      public org.springframework.http.ResponseEntity<String> removeAllergyFromUser(String username, String allergyName)
      Removes allergy from user
      Parameters:
      username - username of user
      allergyName - name of allergy
      Returns:
      user with removed allergy