Created
October 2, 2018 13:07
-
-
Save YEMEAC/b4cf8b75c2d5d5bed3da08eb1bac918e to your computer and use it in GitHub Desktop.
Wanted to throw an exception using Reactive Spring only if username a new user wanted to have was being used for someone what was't him
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Mono<UserDto> validateUpdate(Long partyId, UserDto request) { | |
return partyClient.getIndividual(partyId) | |
.flatMap(r -> securityClient.getByUserName(request.getUsername())) | |
.switchIfEmpty(Mono.just(UserModel.builder().withId(partyId).build())) //dummy to have something to compare with and kee the reactive flow "flowing" | |
.flatMap(r -> { | |
if (!r.getId().equals(partyId)) { | |
throw new UserAlreadyExistsException("Username already taken"); | |
} | |
return Mono.just(request); | |
} | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment