shoppinglistcontroller hinzugefügt und das hinzufügen einer Kategorie implementiert

This commit is contained in:
Technoir committed 2026-10-04 17:06:27 +02:00
1 parent 02a5139e29
commit b65b58aa39
1 file changed
+40
@@ -0,0 +1,40 @@
package de.timaldinger.einkaufsliste.Controller;
import de.timaldinger.einkaufsliste.Dto.ShoppingCategoryDTO;
import de.timaldinger.einkaufsliste.Models.ShoppingList;
import de.timaldinger.einkaufsliste.Models.ShoppingListCategory;
import de.timaldinger.einkaufsliste.Models.ShoppingListItem;
import de.timaldinger.einkaufsliste.Repository.ShoppingListCategoryRepository;
import de.timaldinger.einkaufsliste.Repository.ShoppingListRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.thymeleaf.expression.Lists;
import java.util.List;
import java.util.UUID;
@RestController
public class ShoppingListController {
@Autowired
private ShoppingListCategoryRepository shoppingListCategoryRepository;
@Autowired
private ShoppingListRepository shoppingListRepository;
@PostMapping("/api/list/{listID}/category/")
public ShoppingListCategory addCategory(@PathVariable UUID listID, @RequestBody ShoppingCategoryDTO newCategory){
String name = newCategory.categoryName();
ShoppingList list = shoppingListRepository.findById(listID).orElseThrow();
ShoppingListCategory category = new ShoppingListCategory(name, List.of(),list);
shoppingListCategoryRepository.save(category);
return category;
}
}