patch methode für Kategorie mit PatchDTO Objekt implementiert
This commit is contained in:
1 parent
ed0df61e16
commit
f4afa546ff
2 files changed
+18
No files matched your search
@@ -1,6 +1,8 @@
|
||||
package de.timaldinger.einkaufsliste.Controller;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Dto.ShoppingCategoryDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.ShoppingCategoryPatchDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.ShoppingItemPatchDTO;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingCategory;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingItem;
|
||||
import de.timaldinger.einkaufsliste.Models.ShoppingList;
|
||||
@@ -38,6 +40,18 @@ public class ShoppingCategoryController {
|
||||
return category;
|
||||
}
|
||||
|
||||
@PatchMapping("/api/category/{categoryID}")
|
||||
public ResponseEntity<Void> editItem(@PathVariable UUID categoryID,@RequestBody ShoppingCategoryPatchDTO toChange){
|
||||
ShoppingCategory category = shoppingCategoryRepository.findById(categoryID).orElseThrow();
|
||||
|
||||
if(toChange.categoryName() != null) category.setCategoryName(toChange.categoryName());
|
||||
|
||||
shoppingCategoryRepository.save(category);
|
||||
|
||||
return ResponseEntity.noContent().build();
|
||||
}
|
||||
|
||||
|
||||
@DeleteMapping("/api/category/{categoryID}")
|
||||
public ResponseEntity<Void> deleteCategory(@PathVariable UUID categoryID, @RequestParam(required = false) Boolean deleteAllItems){
|
||||
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package de.timaldinger.einkaufsliste.Dto;
|
||||
|
||||
public record ShoppingCategoryPatchDTO(String categoryName) {
|
||||
}
|
||||
Reference in new issue
Block a user