Skip to content

Instantly share code, notes, and snippets.

@alexandre-jacquot-ptl
Created May 23, 2021 13:16
Show Gist options
  • Save alexandre-jacquot-ptl/e0374d3fdfb71886969d830de2b12aa2 to your computer and use it in GitHub Desktop.
Save alexandre-jacquot-ptl/e0374d3fdfb71886969d830de2b12aa2 to your computer and use it in GitHub Desktop.
r2dbc ItemController patch
@RestController
@RequestMapping(value = "/items")
public class ItemController {
private final ItemService itemService;
private final ItemMapper itemMapper;
...
@ApiOperation("Patch an existing item following the patch merge RCF (https://tools.ietf.org/html/rfc7396)")
@PatchMapping(value = "/{id}")
public Mono<ResponseEntity<Void>> patch(@PathVariable @NotNull final Long id,
@RequestHeader(value = HttpHeaders.IF_MATCH) final Long version,
@Valid @RequestBody final ItemPatchResource patch) {
return itemService.findById(id, version, true)
.map(item -> itemMapper.patch(patch, item))
.flatMap(itemService::update)
.map(itemId -> noContent().build());
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment