From bde2754a51ed5a2c8d99e23b3cbc5d1e75b7f428 Mon Sep 17 00:00:00 2001 From: Erik Hohlfeld Date: Sat, 11 Nov 2023 22:06:48 +0100 Subject: [PATCH] Add removal of CustomCatalogEntry inside catalog via button --- .../orderCatalog/CatalogController.java | 26 +++++++++++++------ .../orderCatalog/CustomCatalogEntry.java | 13 ++++++---- .../CustomCatalogEntryDataInitializer.java | 4 +-- src/main/resources/templates/catalog.html | 14 +++++++++- .../resources/templates/catalog_editor.html | 8 +++--- 5 files changed, 45 insertions(+), 20 deletions(-) diff --git a/src/main/java/catering/orderCatalog/CatalogController.java b/src/main/java/catering/orderCatalog/CatalogController.java index f33ce2f..e9b1054 100644 --- a/src/main/java/catering/orderCatalog/CatalogController.java +++ b/src/main/java/catering/orderCatalog/CatalogController.java @@ -7,6 +7,7 @@ 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.Iterator; import java.util.Set; @@ -30,14 +31,22 @@ public class CatalogController { @GetMapping("/catalog_editor") public String catalog_configuration(Model model) { model.addAttribute("inventory", inventory); - model.addAttribute("formCatalogEntry", new CustomCatalogEntry()); + model.addAttribute("formCatalogEntry", new CustomCatalogEntry( + CustomCatalogEntry.EventType.EVENT_CATERING, + new HashMap(), + 0, + 0)); return "catalog_editor"; } @PostMapping("/catalog_editor/catalog_add") - public String catalog_add(@ModelAttribute CustomCatalogEntry formCatalogEntry, Model model) { + public String catalog_add(Model model) { catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry( - // TODO: Fill with formCatalogEntry's data + // TODO: Fill with formCatalogEntry's data instead of dummy data + CustomCatalogEntry.EventType.EVENT_CATERING, + new HashMap(), + 0, + 0 )); return "redirect:/catalog"; } @@ -46,7 +55,7 @@ public class CatalogController { @PostMapping("/catalog/remove") public String removeEntry(@RequestParam int catalogEntryID) { catalogEntryRepository.removeCatalogEntry(catalogEntryID); - return "catalog_editor"; + return "redirect:/catalog"; } @PostMapping("/catalog_editor/product_add") @@ -70,10 +79,11 @@ public class CatalogController { } @PostMapping("/catalog_editor/add_time") - public String add_time(@ModelAttribute CustomCatalogEntry formCatalogEntry, Model model) { - System.out.println(formCatalogEntry.getMinimumTimePeriod()); - model.addAttribute("formCatalogEntry", formCatalogEntry); - // Might not work because on every GetMapping of /catalog_editor a new formCatalogEntry is created + public String add_time(@RequestParam int minimumTimePeriod, @ModelAttribute CustomCatalogEntry formCatalogEntry, Model model) { + System.out.println(minimumTimePeriod); + /*System.out.println(formCatalogEntry.getMinimumTimePeriod()); + model.addAttribute("formCatalogEntry", formCatalogEntry);*/ + // TODO: Might not work because on every GetMapping of /catalog_editor a new formCatalogEntry is created return "redirect:/catalog_editor"; } diff --git a/src/main/java/catering/orderCatalog/CustomCatalogEntry.java b/src/main/java/catering/orderCatalog/CustomCatalogEntry.java index 58bc624..d97b35c 100644 --- a/src/main/java/catering/orderCatalog/CustomCatalogEntry.java +++ b/src/main/java/catering/orderCatalog/CustomCatalogEntry.java @@ -11,13 +11,13 @@ public class CustomCatalogEntry { private int minimumTimePeriod; // Declared as int for simplification of the prototype. Only whole hours. private int totalCost; // Should actually accumulate the price of all items. - public CustomCatalogEntry() { + public CustomCatalogEntry(EventType eventType, Map products, int minimumTimePeriod, int totalCost) { this.id = idCounter; idCounter++; - this.eventType = EventType.EVENT_CATERING; - this.products = new HashMap(); - this.minimumTimePeriod = 5; - this.totalCost = 3; + this.eventType = eventType; + this.products = products; + this.minimumTimePeriod = minimumTimePeriod; + this.totalCost = totalCost; } public int getId() { @@ -44,6 +44,9 @@ public class CustomCatalogEntry { this.eventType = eventType; } + public void setProducts(Map products) { + this.products = products; + } public void setMinimumTimePeriod(int timePeriod) { this.minimumTimePeriod = timePeriod; } diff --git a/src/main/java/catering/orderCatalog/CustomCatalogEntryDataInitializer.java b/src/main/java/catering/orderCatalog/CustomCatalogEntryDataInitializer.java index 1581ea8..6359cbb 100644 --- a/src/main/java/catering/orderCatalog/CustomCatalogEntryDataInitializer.java +++ b/src/main/java/catering/orderCatalog/CustomCatalogEntryDataInitializer.java @@ -20,7 +20,7 @@ public class CustomCatalogEntryDataInitializer implements DataInitializer { Map products = new HashMap<>(); products.put("Brötchen", 30); products.put("Kerze", 20); - catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry()); + catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(CustomCatalogEntry.EventType.EVENT_CATERING, products, 4, 500)); products = new HashMap<>(); products.put("Kuchen", 3); @@ -28,6 +28,6 @@ public class CustomCatalogEntryDataInitializer implements DataInitializer { products.put("Pizza Margherita", 1); products.put("Pizza Quattro Formaggi", 1); products.put("Ballon", 20); - catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry()); + catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(CustomCatalogEntry.EventType.PARTY_SERVICE, products, 2, 1000)); } } diff --git a/src/main/resources/templates/catalog.html b/src/main/resources/templates/catalog.html index f3339cb..d148848 100644 --- a/src/main/resources/templates/catalog.html +++ b/src/main/resources/templates/catalog.html @@ -33,6 +33,7 @@ **BILD** + h @@ -41,6 +42,12 @@ + +
+ + +
+ @@ -57,6 +64,12 @@ +
+
+ +
+
+
@@ -70,4 +83,3 @@

- diff --git a/src/main/resources/templates/catalog_editor.html b/src/main/resources/templates/catalog_editor.html index fdbd39b..edf8e6e 100644 --- a/src/main/resources/templates/catalog_editor.html +++ b/src/main/resources/templates/catalog_editor.html @@ -18,7 +18,7 @@

Basisevent konfigurieren

-

Dienstleistung

+

Dienstleistung

+ @@ -46,8 +46,6 @@ Stückpreis - - € @@ -58,6 +56,8 @@ +
+