For readability sake, is it better to use optionals or write my code in an iterative manner?
Here's a route I'm working on, does this look readable do you?
@PostMapping("/verify-email")
public ResponseEntity<String> verifyAccount(@RequestBody String email) {
Optional<AppUser> optionalUser = appUserService.findByEmail(email);
return optionalUser
.filter(user -> !user.isEnabled()).stream().findFirst()
.map(verificationTokenService::findByUser)
.map(verificationToken -> {
verificationToken.ifPresent(verificationTokenService::delete);
verificationTokenService.createVerificationToken(optionalUser.get(), VerificationTokenType.VERIFY_ACCOUNT);
String message = String.format("Account verification link has been sent to %s", email);
return ResponseEntity.ok(message);
}).orElseThrow(() -> new VerificationTokenException());
}
I like my code to be readable and clean, and I'm seriously considering writing it. Or is this a good way to use optional?
Function<VerificationToken, ResponseEntity>from the multi-line lambda code \$\endgroup\$How to ...questions because that means the code isn't working as intended yet. There is a site that can help you, Please read Where can I get help? and How do I ask a good question?. \$\endgroup\$