diff --git a/src/main/java/catering/orderCatalog/CatalogController.java b/src/main/java/catering/orderCatalog/CatalogController.java index fc34fb2..085fbfb 100644 --- a/src/main/java/catering/orderCatalog/CatalogController.java +++ b/src/main/java/catering/orderCatalog/CatalogController.java @@ -2,14 +2,23 @@ package catering.orderCatalog; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.RequestParam; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; @Controller public class CatalogController { private CustomCatalogEntryRepository catalogEntryRepository; + private Set inventory; public CatalogController(CustomCatalogEntryRepository catalogEntryRepository) { + inventory = new HashSet<>(); this.catalogEntryRepository = catalogEntryRepository; } @@ -20,13 +29,44 @@ public class CatalogController { } @GetMapping("/catalog_editor") - public String event_configuration() { + public String catalog_configuration(Model model) { + model.addAttribute("inventory", inventory); + model.addAttribute("formCatalogEntry", new CustomCatalogEntry()); return "catalog_editor"; } + // Removes a catalog entry @PostMapping("/catalog/remove") - public String removeItem() { + public String removeEntry(@RequestParam int catalogEntryID) { + catalogEntryRepository.removeCatalogEntry(catalogEntryID); return "catalog_editor"; } + @PostMapping("/catalog_editor/product_add") + public String product_add(Model model) { + inventory.add(new CustomProduct("Test product", 5, 50)); + return "redirect:/catalog_editor"; + } + + @PostMapping("/catalog_editor/catalog_add") + public String catalog_add(@ModelAttribute CustomCatalogEntry formCatalogEntry, Model model) { + catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry()); + return "redirect:/catalog"; + } + + // Removes a product from the catalog_editor + @PostMapping("/catalog_editor/remove_product") + public String removeProduct(@RequestParam int productId, Model model) { + inventory.remove(productId); + model.addAttribute("inventory", inventory); + + return "redirect:/catalog_editor"; + } + + @PostMapping("/catalog_editor/add_time") + public String add_time(@ModelAttribute CustomCatalogEntry formCatalogEntry, Model model) { + model.addAttribute("formCatalogEntry", formCatalogEntry); + return "redirect:/catalog_editor"; + } + } diff --git a/src/main/resources/templates/catalog_editor.html b/src/main/resources/templates/catalog_editor.html index aa320be..aa202d1 100644 --- a/src/main/resources/templates/catalog_editor.html +++ b/src/main/resources/templates/catalog_editor.html @@ -3,8 +3,7 @@ xmlns:sec="http://www.thymeleaf.org/extras/spring-security" xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"> - Basiseventkonfiguration - + Basisevent-Konfiguration

Basisevent konfigurieren

+

Dienstleistung

@@ -28,9 +28,14 @@ Eventbasispreis: 500€

Mindestzeitraum

- h +
+ +
+ +

Basisausstattung

@@ -39,39 +44,30 @@ - - + + - - - - - - - - -
Menge Stückpreis
Brötchen
+ + - - 1,00 € -
- - + + +
Kerze - - 3.00 € -
- - + + +
[Artikel Hinzufügen]

Gesamtpreis: 90 €
- +
+ +