item wird via post erstellt
This commit is contained in:
1 parent
be7b752ce7
commit
09fa991077
1 file changed
+15
@@ -1,10 +1,12 @@
|
||||
package de.timaldinger.einkaufsliste.Controller;
|
||||
|
||||
import de.timaldinger.einkaufsliste.Dto.ShoppingCategoryDTO;
|
||||
import de.timaldinger.einkaufsliste.Dto.ShoppingListItemDTO;
|
||||
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.ShoppingListItemRepository;
|
||||
import de.timaldinger.einkaufsliste.Repository.ShoppingListRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.ui.Model;
|
||||
@@ -24,6 +26,8 @@ public class ShoppingListController {
|
||||
private ShoppingListCategoryRepository shoppingListCategoryRepository;
|
||||
@Autowired
|
||||
private ShoppingListRepository shoppingListRepository;
|
||||
@Autowired
|
||||
private ShoppingListItemRepository shoppingListItemRepository;
|
||||
|
||||
@PostMapping("/api/list/{listID}/category/")
|
||||
public ShoppingListCategory addCategory(@PathVariable UUID listID, @RequestBody ShoppingCategoryDTO newCategory){
|
||||
@@ -37,4 +41,15 @@ public class ShoppingListController {
|
||||
|
||||
return category;
|
||||
}
|
||||
|
||||
@PostMapping("/api/list/{listID}/item/")
|
||||
public ShoppingListItem addItem(@PathVariable UUID listID, @RequestBody ShoppingListItemDTO newItem){
|
||||
String name = newItem.itemName();
|
||||
String amount = newItem.itemAmount();
|
||||
ShoppingListCategory c = shoppingListCategoryRepository.findById(newItem.category()).orElseThrow();
|
||||
ShoppingList list = shoppingListRepository.findById(listID).orElseThrow();
|
||||
ShoppingListItem item = new ShoppingListItem(name, amount, false, c, list);
|
||||
shoppingListItemRepository.save(item);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user