From 9f7a90814dafb31539e8eeb05266cd6c402932b5 Mon Sep 17 00:00:00 2001 From: Erik Hohlfeld Date: Thu, 9 Nov 2023 20:21:34 +0100 Subject: [PATCH] Initialize all Catalog classes regarding the prototype --- .../orderCatalog/CatalogController.java | 25 ++++++ .../orderCatalog/CustomCatalogEntry.java | 42 ++++++++++ .../CustomCatalogEntryDataInitializer.java | 42 ++++++++++ .../CustomCatalogEntryRepository.java | 28 +++++++ .../catering/welcome/WelcomeController.java | 6 -- src/main/resources/templates/catalog.html | 8 +- .../resources/templates/catalog_editor.html | 76 +++++++++++++++++++ .../templates/event_configuration.html | 52 ------------- 8 files changed, 220 insertions(+), 59 deletions(-) create mode 100644 src/main/java/catering/orderCatalog/CatalogController.java create mode 100644 src/main/java/catering/orderCatalog/CustomCatalogEntry.java create mode 100644 src/main/java/catering/orderCatalog/CustomCatalogEntryDataInitializer.java create mode 100644 src/main/java/catering/orderCatalog/CustomCatalogEntryRepository.java create mode 100644 src/main/resources/templates/catalog_editor.html delete mode 100644 src/main/resources/templates/event_configuration.html diff --git a/src/main/java/catering/orderCatalog/CatalogController.java b/src/main/java/catering/orderCatalog/CatalogController.java new file mode 100644 index 0000000..4f76fe2 --- /dev/null +++ b/src/main/java/catering/orderCatalog/CatalogController.java @@ -0,0 +1,25 @@ +package catering.orderCatalog; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; + +@Controller +public class CatalogController { + + @GetMapping("/catalog") + public String catalog() { + return "catalog"; + } + + @GetMapping("/catalog_editor") + public String event_configuration() { + return "catalog_editor"; + } + + @PostMapping("/catalog/remove") + public String removeItem() { + return "redirect:/catalog"; + } + +} diff --git a/src/main/java/catering/orderCatalog/CustomCatalogEntry.java b/src/main/java/catering/orderCatalog/CustomCatalogEntry.java new file mode 100644 index 0000000..f7eff79 --- /dev/null +++ b/src/main/java/catering/orderCatalog/CustomCatalogEntry.java @@ -0,0 +1,42 @@ +package catering.orderCatalog; + +import java.util.Map; + +public class CustomCatalogEntry { + static int idCounter = 0; + private int id; + private EventType eventType; + private Map products; + private int minimumTimePeriod; // Declared as int for simplification of the prototype. Only whole hours. + + public CustomCatalogEntry(EventType eventType, Map products, int minimumTimePeriod) { + this.id = idCounter; + idCounter++; + this.eventType = eventType; + this.products = products; + this.minimumTimePeriod = minimumTimePeriod; + } + + public int getId() { + return id; + } + + public EventType getEventType() { + return eventType; + } + + public Map getProducts() { + return products; + } + + public int getMinimumTimePeriod() { + return minimumTimePeriod; + } + + public enum EventType { + EVENT_CATERING, + PARTY_SERVICE, + MOBILE_BREAKFAST, + RENT_A_COOK + } +} diff --git a/src/main/java/catering/orderCatalog/CustomCatalogEntryDataInitializer.java b/src/main/java/catering/orderCatalog/CustomCatalogEntryDataInitializer.java new file mode 100644 index 0000000..7586efe --- /dev/null +++ b/src/main/java/catering/orderCatalog/CustomCatalogEntryDataInitializer.java @@ -0,0 +1,42 @@ +package catering.orderCatalog; + +import org.salespointframework.core.DataInitializer; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + +@Component +public class CustomCatalogEntryDataInitializer implements DataInitializer { + private CustomCatalogEntryRepository catalogEntryRepository; + + public CustomCatalogEntryDataInitializer(CustomCatalogEntryRepository catalogEntryRepository) { + this.catalogEntryRepository = catalogEntryRepository; + } + + @Override + public void initialize() { + System.out.println("Initialize CatalogEntryRepository"); + + Map products = new HashMap<>(); + products.put("Brötchen", 30); + products.put("Kerze", 20); + catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry( + CustomCatalogEntry.EventType.EVENT_CATERING, + products, + 3 + )); + + products = new HashMap<>(); + products.put("Kuchen", 3); + products.put("Pizza Funghi", 1); + products.put("Pizza Margherita", 1); + products.put("Pizza Quattro Formaggi", 1); + products.put("Ballon", 20); + catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry( + CustomCatalogEntry.EventType.PARTY_SERVICE, + products, + 3 + )); + } +} diff --git a/src/main/java/catering/orderCatalog/CustomCatalogEntryRepository.java b/src/main/java/catering/orderCatalog/CustomCatalogEntryRepository.java new file mode 100644 index 0000000..f7e8f7a --- /dev/null +++ b/src/main/java/catering/orderCatalog/CustomCatalogEntryRepository.java @@ -0,0 +1,28 @@ +package catering.orderCatalog; + +import org.springframework.stereotype.Component; + +import java.util.HashSet; +import java.util.Set; + +@Component +public class CustomCatalogEntryRepository { + private Set catalogEntries; + + public CustomCatalogEntryRepository() { + this.catalogEntries = new HashSet<>(); + } + + public boolean addCatalogEntry(CustomCatalogEntry catalogEntry) { + return catalogEntries.add(catalogEntry); + } + + public boolean removeOrder(int catalogEntryID) { + for (CustomCatalogEntry catalogEntry : catalogEntries) { + if (catalogEntry.getId() == catalogEntryID) { + return this.catalogEntries.remove(catalogEntry); + } + } + return false; + } +} diff --git a/src/main/java/catering/welcome/WelcomeController.java b/src/main/java/catering/welcome/WelcomeController.java index c79b936..9dbdb42 100644 --- a/src/main/java/catering/welcome/WelcomeController.java +++ b/src/main/java/catering/welcome/WelcomeController.java @@ -25,10 +25,4 @@ public class WelcomeController { public String index() { return "welcome"; } - - @GetMapping("/catalog") - public String catalog() { - return "catalog"; - } - } diff --git a/src/main/resources/templates/catalog.html b/src/main/resources/templates/catalog.html index ee8c925..f946246 100644 --- a/src/main/resources/templates/catalog.html +++ b/src/main/resources/templates/catalog.html @@ -17,7 +17,7 @@
-

Katalog

+

Katalog

@@ -62,6 +62,12 @@
+
+
+ +
+
+
diff --git a/src/main/resources/templates/catalog_editor.html b/src/main/resources/templates/catalog_editor.html new file mode 100644 index 0000000..65530f9 --- /dev/null +++ b/src/main/resources/templates/catalog_editor.html @@ -0,0 +1,76 @@ + + + + Auftragskonfiguration + + +

Auftrag konfigurieren

+
+

Dienstleistung

+ + + Eventbasispreis: 500€ + +

Mindestzeitraum

+ h + +

Basisausstattung

+ + + + + + + + + + + + + + + + + + + + + +
ProduktnameMengeStückpreis
Brötchen + + 1,00 € +
+ + +
+
Kerze + + 3.00 € +
+ + +
+
[Artikel Hinzufügen]
+
+ Gesamtpreis: 90 €
+ +
+ + diff --git a/src/main/resources/templates/event_configuration.html b/src/main/resources/templates/event_configuration.html deleted file mode 100644 index 0e410fb..0000000 --- a/src/main/resources/templates/event_configuration.html +++ /dev/null @@ -1,52 +0,0 @@ - - - - Auftragskonfiguration - - -

Auftrag konfigurieren

-
-

Dienstleistung

- - - Preis 30€ - -

Artikel

- - - - - - - - - - - - - - - - - - - - - -
ProduktnameMengeStückzahl
Brötchen30 [ + / - ]1,00 €[Löschen]
Kerze20 [ + / - ]3.00 €[Löschen]
[Artikel Hinzufügen]
-
- Gesamtpreis: 90 €
- -
- -