Class UserService

  • All Implemented Interfaces:
    org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,​org.springframework.security.authentication.UsernamePasswordAuthenticationToken>

    @Service
    public class UserService
    extends java.lang.Object
    implements org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,​org.springframework.security.authentication.UsernamePasswordAuthenticationToken>
    UserService provides a layer between UserRepository and UserController for business logic.
    Since:
    1.0
    Version:
    1.0
    Author:
    Robert Dominugez, Roderick Frechette, Laura Steiner
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.springframework.security.authentication.UsernamePasswordAuthenticationToken convert​(org.springframework.security.oauth2.jwt.Jwt jwt)
      Overrides the convert method to convert a Json web token into a UsernamePasswordAuthenticationToken
      void delete​(User user)
      Deletes the current user.
      java.util.Optional<User> get​(long id)
      Finds and returns a single User object by id.
      java.util.List<User> getAll()
      Returns a list of all users, ordered by username in alphabetical order.
      User getOrCreate​(java.lang.String oauthKey, java.lang.String username, java.lang.String email)
      Gets the user with the oauth key, or creates the user if one does not exist for this oauth.
      User.Genre updateGenre​(User user, User.Genre genre)
      Updates the user's favorite genre.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • UserService

        @Autowired
        public UserService​(UserRepository userRepository,
                           RelationshipRepository relationshipRepository)
        Autowired constructor for UserService
        Parameters:
        userRepository - UserRepository
        relationshipRepository - RelationshipRepository
    • Method Detail

      • getOrCreate

        public User getOrCreate​(java.lang.String oauthKey,
                                java.lang.String username,
                                java.lang.String email)
        Gets the user with the oauth key, or creates the user if one does not exist for this oauth.
        Parameters:
        oauthKey - String
        username - String
        email - String
        Returns:
        the User that has been found or created
      • convert

        public org.springframework.security.authentication.UsernamePasswordAuthenticationToken convert​(org.springframework.security.oauth2.jwt.Jwt jwt)
        Overrides the convert method to convert a Json web token into a UsernamePasswordAuthenticationToken
        Specified by:
        convert in interface org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.jwt.Jwt,​org.springframework.security.authentication.UsernamePasswordAuthenticationToken>
        Parameters:
        jwt - Jwt
        Returns:
        UsernamePasswordAuthenticationToken
      • get

        public java.util.Optional<User> get​(long id)
        Finds and returns a single User object by id.
        Parameters:
        id - long
        Returns:
        Optional<User>
      • getAll

        public java.util.List<User> getAll()
        Returns a list of all users, ordered by username in alphabetical order.
        Returns:
        List<User>
      • updateGenre

        public User.Genre updateGenre​(User user,
                                      User.Genre genre)
        Updates the user's favorite genre.
        Parameters:
        user - User
        genre - Genre enum
        Returns:
        Genre enum
      • delete

        public void delete​(User user)
        Deletes the current user.
        Parameters:
        user - User