diff --git a/src/main/java/catering/orderCatalog/CatalogController.java b/src/main/java/catering/orderCatalog/CatalogController.java index e9b1054..b5facef 100644 --- a/src/main/java/catering/orderCatalog/CatalogController.java +++ b/src/main/java/catering/orderCatalog/CatalogController.java @@ -2,23 +2,25 @@ 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.Iterator; -import java.util.Set; +import java.util.*; @Controller public class CatalogController { private CustomCatalogEntryRepository catalogEntryRepository; private Set inventory; + private CustomCatalogEntry formCatalogEntry; public CatalogController(CustomCatalogEntryRepository catalogEntryRepository) { inventory = new HashSet<>(); + formCatalogEntry = new CustomCatalogEntry( + CustomCatalogEntry.EventType.EVENT_CATERING, + new HashMap(), + 0, + 0); this.catalogEntryRepository = catalogEntryRepository; } @@ -31,23 +33,35 @@ public class CatalogController { @GetMapping("/catalog_editor") public String catalog_configuration(Model model) { model.addAttribute("inventory", inventory); - model.addAttribute("formCatalogEntry", new CustomCatalogEntry( - CustomCatalogEntry.EventType.EVENT_CATERING, - new HashMap(), - 0, - 0)); + model.addAttribute("formCatalogEntry", formCatalogEntry); return "catalog_editor"; } @PostMapping("/catalog_editor/catalog_add") - public String catalog_add(Model model) { + public String catalog_add(@RequestParam CustomCatalogEntry.EventType eventType, + @RequestParam int minimumTimePeriod, + @RequestParam int totalCost, + Model model) { + Map products = new HashMap(); + + for (CustomProduct product : inventory) { + products.put(product.getName(), product.getAmount()); + } + + System.out.println("Products looks like this:" + products); catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry( - // TODO: Fill with formCatalogEntry's data instead of dummy data - CustomCatalogEntry.EventType.EVENT_CATERING, - new HashMap(), - 0, - 0 - )); + eventType, + products, + minimumTimePeriod, + totalCost)); + this.formCatalogEntry = new CustomCatalogEntry( + CustomCatalogEntry.EventType.EVENT_CATERING, + new HashMap(), + 0, + 0); + inventory.clear(); + model.addAttribute("inventory", inventory); + model.addAttribute("formCatalogEntry", formCatalogEntry); return "redirect:/catalog"; } @@ -61,6 +75,7 @@ public class CatalogController { @PostMapping("/catalog_editor/product_add") public String product_add(@RequestParam String name, @RequestParam int amount, @RequestParam double cost) { inventory.add(new CustomProduct(name, amount, cost)); + formCatalogEntry.addProduct(name, amount); return "redirect:/catalog_editor"; } @@ -79,11 +94,35 @@ public class CatalogController { } @PostMapping("/catalog_editor/add_time") - 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 + public String add_time(@RequestParam int minimumTimePeriod, + @RequestParam CustomCatalogEntry.EventType eventType, + @RequestParam Map products, + Model model) { + formCatalogEntry.setMinimumTimePeriod(minimumTimePeriod); + model.addAttribute("formCatalogEntry", formCatalogEntry); + return "redirect:/catalog_editor"; + } + + @PostMapping("/catalog_editor/chooseEvent") + public String chooseEvent(String events) { + switch (events) { + case "event_catering": + formCatalogEntry.setEventType(CustomCatalogEntry.EventType.EVENT_CATERING); + break; + case "party_service": + formCatalogEntry.setEventType(CustomCatalogEntry.EventType.PARTY_SERVICE); + break; + case "mobile_breakfast": + formCatalogEntry.setEventType(CustomCatalogEntry.EventType.MOBILE_BREAKFAST); + break; + case "rent_a_cook": + formCatalogEntry.setEventType(CustomCatalogEntry.EventType.RENT_A_COOK); + break; + default: + formCatalogEntry.setEventType(CustomCatalogEntry.EventType.EVENT_CATERING); + break; + } + return "redirect:/catalog_editor"; } diff --git a/src/main/java/catering/orderCatalog/CustomCatalogEntry.java b/src/main/java/catering/orderCatalog/CustomCatalogEntry.java index d97b35c..3eeacb2 100644 --- a/src/main/java/catering/orderCatalog/CustomCatalogEntry.java +++ b/src/main/java/catering/orderCatalog/CustomCatalogEntry.java @@ -1,6 +1,5 @@ package catering.orderCatalog; -import java.util.HashMap; import java.util.Map; public class CustomCatalogEntry { @@ -36,14 +35,18 @@ public class CustomCatalogEntry { return minimumTimePeriod; } - public String getTotalCost() { - return totalCost + " €"; + public int getTotalCost() { + return totalCost; } public void setEventType(EventType eventType) { this.eventType = eventType; } + public void addProduct(String name, Integer count) { + this.products.put(name, count); + } + public void setProducts(Map products) { this.products = products; } diff --git a/src/main/resources/templates/catalog.html b/src/main/resources/templates/catalog.html index d148848..b2c4fa0 100644 --- a/src/main/resources/templates/catalog.html +++ b/src/main/resources/templates/catalog.html @@ -17,7 +17,7 @@
-

Katalog

+

Katalog

@@ -33,7 +33,6 @@ **BILD** - h @@ -70,6 +69,12 @@
+
+
+ +
+
+
diff --git a/src/main/resources/templates/catalog_editor.html b/src/main/resources/templates/catalog_editor.html index edf8e6e..821cfda 100644 --- a/src/main/resources/templates/catalog_editor.html +++ b/src/main/resources/templates/catalog_editor.html @@ -18,27 +18,28 @@

Basisevent konfigurieren

-

Dienstleistung

- - +

Dienstleistung

+ +
+ + +
Eventbasispreis: 500€ -

Mindestzeitraum

+

Mindestzeitraum

+
- - - -

Basisausstattung

+

Basisausstattung

@@ -56,7 +57,7 @@
Produktname
-
+
@@ -65,10 +66,17 @@ -
-
- Gesamtpreis: 90 €
+ hinzufügen +
+

Momentane Auswahl

+ Eventtyp:
+ Mindestzeitraum:
+ Gesamtpreis: 90 €
+ + + +