docs(docstrings): add docstrings to public method interfaces (#25)
- Resolves #18 Reviewed-on: #25
This commit was merged in pull request #25.
This commit is contained in:
@@ -44,10 +44,21 @@ public class UserService {
|
||||
this.jwtService = jwtService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up a user by their database ID.
|
||||
*
|
||||
* @param userId the ID of the user to find
|
||||
* @return the matching {@link User}, or empty if none exists
|
||||
*/
|
||||
public Optional<User> getUserById(Long userId) {
|
||||
return userRepository.findById(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user backing the current Spring Security authentication, if authenticated.
|
||||
*
|
||||
* @return the authenticated {@link User}, or empty if no user is authenticated
|
||||
*/
|
||||
public Optional<User> getLoggedInUser() {
|
||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||
if (auth != null && auth.isAuthenticated() && auth.getPrincipal() instanceof User user) {
|
||||
@@ -56,6 +67,13 @@ public class UserService {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Verifies a Google ID token, creating or updating the corresponding user, and issues a session JWT.
|
||||
*
|
||||
* @param idToken the Google ID token to verify
|
||||
* @return a signed JWT for the authenticated user
|
||||
* @throws NotAuthenticated if the token is invalid or its subject is missing
|
||||
*/
|
||||
public String login(String idToken) {
|
||||
GoogleIdToken googleIdToken = getGoogleIdToken(idToken);
|
||||
String googleId = googleIdToken.getPayload().getSubject();
|
||||
@@ -70,6 +88,12 @@ public class UserService {
|
||||
return jwtService.generateToken(user.getId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Looks up a user by their stream key.
|
||||
*
|
||||
* @param streamKey the stream key to match
|
||||
* @return the matching {@link User}, or empty if none exists
|
||||
*/
|
||||
public Optional<User> getUserByStreamKey(String streamKey) {
|
||||
return userRepository.findByStreamKey(streamKey);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user