patch methode für Kategorie mit PatchDTO Objekt implementiert

This commit is contained in:
Technoir committed 2026-10-07 15:25:56 +02:00
1 parent ed0df61e16
commit 1acd4af71f
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> editCategory(@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) {
}