diff --git a/src/main/java/guru/springframework/spring5webfluxrest/controllers/CategoryController.java b/src/main/java/guru/springframework/spring5webfluxrest/controllers/CategoryController.java index 8ca4f3b..4019581 100644 --- a/src/main/java/guru/springframework/spring5webfluxrest/controllers/CategoryController.java +++ b/src/main/java/guru/springframework/spring5webfluxrest/controllers/CategoryController.java @@ -42,17 +42,16 @@ Mono update(@PathVariable String id, @RequestBody Category category) { return categoryRepository.save(category); } - @PatchMapping("/api/v1/categories/{id}") - Mono patch(@PathVariable String id, @RequestBody Category category) { - - Category foundCategory = categoryRepository.findById(id).block(); - - if(foundCategory.getDescription() != category.getDescription()){ - foundCategory.setDescription(category.getDescription()); - return categoryRepository.save(foundCategory); - } - - return Mono.just(foundCategory); - } + @PatchMapping(path = "/{id}") + public Mono patch(@PathVariable String id, @RequestBody Category category) { + return categoryRepository.findById(id) + .flatMap(response -> { + if (response.getDescription() != category.getDescription()) { + response.setDescription(category.getDescription()); + return categoryRepository.save(response); + } + return Mono.just(response); + }); + } }