Class UserService
- java.lang.Object
-
- edu.cnm.deepdive.tunefull.service.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>
- Since:
- 1.0
- Version:
- 1.0
- Author:
- Robert Dominugez, Roderick Frechette, Laura Steiner
-
-
Constructor Summary
Constructors Constructor Description UserService(UserRepository userRepository, RelationshipRepository relationshipRepository)
Autowired constructor forUserService
-
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 theconvert
method to convert a Json web token into a UsernamePasswordAuthenticationTokenvoid
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.
-
-
-
Constructor Detail
-
UserService
@Autowired public UserService(UserRepository userRepository, RelationshipRepository relationshipRepository)
Autowired constructor forUserService
- Parameters:
userRepository
- UserRepositoryrelationshipRepository
- 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
- Stringusername
- Stringemail
- 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 theconvert
method to convert a Json web token into a UsernamePasswordAuthenticationToken- Specified by:
convert
in interfaceorg.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
- Usergenre
- Genre enum- Returns:
- Genre enum
-
delete
public void delete(User user)
Deletes the current user.- Parameters:
user
- User
-
-