I\'m developing a app with Spring Boot 2.0 and Kotlin using the WebFlux framework.
I want to check if a user id exits before save a transaction. I\'m stucked in a simple
Let me start by saying I am a newbie on reactive (java) and on this forum. I think you cannot really check in this code if a mono is empty because a mono represents code that will be executed later on, so in this code body you won't know yet if its is empty. Does that make sense?
I just wrote something similar in Java which seems to work (but not 100% this is the best approach either):
public Mono queryStore(ServerRequest request) {
Optional postalCode = request.queryParam("postalCode");
Mono badQuery = ServerResponse.badRequest().build();
Mono notFound = ServerResponse.notFound().build();
if (!postalCode.isPresent()) { return badQuery; }
Flux stores = this.repository
.getNearByStores(postalCode.get(), 5);
return ServerResponse.ok().contentType(APPLICATION_JSON)
.body(stores, Store.class)
.switchIfEmpty(notFound);
}