code-examples icon indicating copy to clipboard operation
code-examples copied to clipboard

Improvment: OkOrNotFound controller base class method.

Open rcollette opened this issue 2 years ago • 0 comments

I think it would be a better example for your readers to have a controller base class method like:

private static final NOT_FOUND = ResponseEntity.notFound().build();

protected Mono<ResponseEntity<T>> OkOrNotFound(Mono<T> result){
  return result.map(ResponseEntity::ok).defaultIfEmpty(NOT_FOUND);
}

In use it's now just

return OkOrNotFound(result);

rcollette avatar Mar 14 '23 12:03 rcollette