Skip to content

Commit

Permalink
added me-endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Erling Jahr committed Nov 21, 2023
1 parent 4746a3d commit 1aa81ba
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/main/java/no/fintlabs/user/LoggedOnUser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package no.fintlabs.user;


import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@AllArgsConstructor
public class LoggedOnUser {
String firstName;
String lastName;
String organisationId;
String mail;
}
14 changes: 14 additions & 0 deletions src/main/java/no/fintlabs/user/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,18 @@ public ResponseEntity<DetailedUser> getDetailedUserById(@AuthenticationPrincipal
else {
return new ResponseEntity<>(HttpStatus.FORBIDDEN);}
}

@GetMapping("/me")
public ResponseEntity<LoggedOnUser> getLoggedOnUser(@AuthenticationPrincipal Jwt jwt){
FintJwtEndUserPrincipal principal = FintJwtEndUserPrincipal.from(jwt);
LoggedOnUser loggedOnUser = new LoggedOnUser(
principal.getGivenName(),
principal.getSurname(),
principal.getOrgId(),
principal.getMail()
);

return new ResponseEntity<>(loggedOnUser,HttpStatus.OK);
}

}
7 changes: 3 additions & 4 deletions src/main/java/no/fintlabs/user/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void save(User user) {
private Runnable onSaveNewUser(User user) {
return () -> {
User newUser = userRepository.save(user);
//log.info("Create new user: " + user.getId());
log.info("Create new user: " + user.getId());
memberService.process(memberService.create(newUser));
userEntityProducerService.publish(newUser);
};
Expand All @@ -51,11 +51,10 @@ private Runnable onSaveNewUser(User user) {
private Consumer<User> onSaveExistingUser(User user) {
return existingUser -> {
user.setId(existingUser.getId());
//log.info("Update user: " + user.getId());
log.info("Update user: " + user.getId());
memberService.process(memberService.create(user));
userRepository.save(user);
User userToPublish = userRepository.findById(user.getId()).orElse(user);
userEntityProducerService.publish(userToPublish);
userEntityProducerService.publish(user);
};
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/application-local.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
fint:
org-id: fintlabs.no
application-id: fint-kontroll-user-catalog
kafka:
default-replicas: 1
bootstrap-servers: localhost:9092
Expand Down

0 comments on commit 1aa81ba

Please sign in to comment.