Class UserService
- java.lang.Object
-
- edu.cnm.deepdive.interviewprep.service.UserService
-
- All Implemented Interfaces:
Converter<Jwt,UsernamePasswordAuthenticationToken>
@Service public class UserService extends Object implements Converter<Jwt,UsernamePasswordAuthenticationToken>
This class implements the high level persistence and business logic for the User entity.
-
-
Constructor Summary
Constructors Constructor Description UserService(UserRepository repository)
Constructor that instantiates a new User repository object.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description UsernamePasswordAuthenticationToken
convert(Jwt source)
void
delete(User user)
Deletes aUser
object that matches the parameter user from the database.Optional<User>
get(UUID id)
Returns aUser
object that matches the id.Iterable<User>
getAll()
Returns a list ofUser
ordered by display name in ascending order.Optional<User>
getByExternalKey(UUID externalKey)
Returns aUser
that matches the external key.User
getCurrentUser()
Gets a currentUser
object from the database.User
getOrCreate(String oauthKey, String displayName)
Queries the database for aUser
object defined by Oauth key.User
save(User user)
Saves a User object to the database.User
update(User updateUser, User user)
Updates the currentUser
object records from the provided updated User record, and saves the result to the database.
-
-
-
Constructor Detail
-
UserService
@Autowired public UserService(UserRepository repository)
Constructor that instantiates a new User repository object.- Parameters:
repository
- User repository object.
-
-
Method Detail
-
convert
public UsernamePasswordAuthenticationToken convert(Jwt source)
- Specified by:
convert
in interfaceConverter<Jwt,UsernamePasswordAuthenticationToken>
-
getOrCreate
public User getOrCreate(String oauthKey, String displayName)
Queries the database for aUser
object defined by Oauth key. If a User object doesn't exist it gets added to the database.- Parameters:
oauthKey
- An OAuth key in the form of a string.displayName
- A display name in the form of a string.- Returns:
- A User object.
-
get
public Optional<User> get(UUID id)
Returns aUser
object that matches the id.- Parameters:
id
- Id in the form of a universally unique identifier.- Returns:
- An optional User object.
-
getByExternalKey
public Optional<User> getByExternalKey(UUID externalKey)
Returns aUser
that matches the external key.- Parameters:
externalKey
- External key in the form of a universally unique identifier.- Returns:
- An optional User object.
-
getAll
public Iterable<User> getAll()
Returns a list ofUser
ordered by display name in ascending order.- Returns:
- A list of User objects.
-
save
public User save(User user)
Saves a User object to the database.- Parameters:
user
- A User object.- Returns:
- A User object.
-
delete
public void delete(User user)
Deletes aUser
object that matches the parameter user from the database.- Parameters:
user
- A User Object.
-
getCurrentUser
public User getCurrentUser()
Gets a currentUser
object from the database.- Returns:
- A User object.
-
-