Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
BE-#0: Refactor openEventFromInvitationLink()
Browse files Browse the repository at this point in the history
  • Loading branch information
Drumber committed Apr 24, 2024
1 parent c67cb5d commit d7e3017
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ public Event generateInvitationLink(AuthenticatedPrincipal principal, String eve
@PreAuthorize("hasRole('GUEST')")
public Optional<String> openEventFromInvitationLink(AuthenticatedPrincipal principal, String invitationLink) {
Optional<Event> event = findEventByInvitationLink(invitationLink);
if (event.isPresent() && principal instanceof GuestAuthenticationPrincipal guestPrincipal) {
guestPrincipal.grantAccessToEvent(event.get().getId());
} else if (event.isPresent() && principal instanceof OAuth2User) {
// add user as participant
event = event.map(e -> addUserToParticipantsIfNotParticipating(principal, e));
}
return event.map(presentEvent -> env.getProperty("frontend.url") + "/event/" + presentEvent.getId());
return event.map(presentEvent -> {
if (principal instanceof GuestAuthenticationPrincipal guestPrincipal) {
guestPrincipal.grantAccessToEvent(presentEvent.getId());
} else if (principal instanceof OAuth2User) {
// add user as participant
addUserToParticipantsIfNotParticipating(principal, presentEvent);
}
return env.getProperty("frontend.url") + "/event/" + presentEvent.getId();
});
}

private Event getEventById(String eventId) {
Expand Down

0 comments on commit d7e3017

Please sign in to comment.