From 3470a369c78535b0daa30a11c95868ef84b53f76 Mon Sep 17 00:00:00 2001 From: Erik Hohlfeld Date: Fri, 10 Nov 2023 18:34:31 +0100 Subject: [PATCH] Remove constructor arguments and add getters and setters for CustomCatalogEntry --- .../orderCatalog/CustomCatalogEntry.java | 25 +++++++++++++++---- .../CustomCatalogEntryDataInitializer.java | 14 ++--------- .../CustomCatalogEntryRepository.java | 2 +- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/main/java/catering/orderCatalog/CustomCatalogEntry.java b/src/main/java/catering/orderCatalog/CustomCatalogEntry.java index 10f1dfe..c2e6661 100644 --- a/src/main/java/catering/orderCatalog/CustomCatalogEntry.java +++ b/src/main/java/catering/orderCatalog/CustomCatalogEntry.java @@ -1,5 +1,8 @@ package catering.orderCatalog; +import org.springframework.stereotype.Component; + +import java.util.HashMap; import java.util.Map; public class CustomCatalogEntry { @@ -10,13 +13,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(EventType eventType, Map products, int minimumTimePeriod, int totalCost) { + public CustomCatalogEntry() { this.id = idCounter; idCounter++; - this.eventType = eventType; - this.products = products; - this.minimumTimePeriod = minimumTimePeriod; - this.totalCost = totalCost; + this.eventType = EventType.EVENT_CATERING; + this.products = new HashMap(); + this.minimumTimePeriod = 5; + this.totalCost = 3; } public int getId() { @@ -39,6 +42,18 @@ public class CustomCatalogEntry { return totalCost + " €"; } + public void setEventType(EventType eventType) { + this.eventType = eventType; + } + + public void setMinimumTimePeriod(int timePeriod) { + this.minimumTimePeriod = timePeriod; + } + + public void setTotalCost(int totalCost) { + this.totalCost = totalCost; + } + public enum EventType { EVENT_CATERING, PARTY_SERVICE, diff --git a/src/main/java/catering/orderCatalog/CustomCatalogEntryDataInitializer.java b/src/main/java/catering/orderCatalog/CustomCatalogEntryDataInitializer.java index 1b3c16b..1581ea8 100644 --- a/src/main/java/catering/orderCatalog/CustomCatalogEntryDataInitializer.java +++ b/src/main/java/catering/orderCatalog/CustomCatalogEntryDataInitializer.java @@ -20,12 +20,7 @@ public class CustomCatalogEntryDataInitializer implements DataInitializer { Map products = new HashMap<>(); products.put("Brötchen", 30); products.put("Kerze", 20); - catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry( - CustomCatalogEntry.EventType.EVENT_CATERING, - products, - 3, - 300 - )); + catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry()); products = new HashMap<>(); products.put("Kuchen", 3); @@ -33,11 +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( - CustomCatalogEntry.EventType.PARTY_SERVICE, - products, - 3, - 500 - )); + catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry()); } } diff --git a/src/main/java/catering/orderCatalog/CustomCatalogEntryRepository.java b/src/main/java/catering/orderCatalog/CustomCatalogEntryRepository.java index 1a8d9f8..53ac2b5 100644 --- a/src/main/java/catering/orderCatalog/CustomCatalogEntryRepository.java +++ b/src/main/java/catering/orderCatalog/CustomCatalogEntryRepository.java @@ -17,7 +17,7 @@ public class CustomCatalogEntryRepository { return catalogEntries.add(catalogEntry); } - public boolean removeOrder(int catalogEntryID) { + public boolean removeCatalogEntry(int catalogEntryID) { for (CustomCatalogEntry catalogEntry : catalogEntries) { if (catalogEntry.getId() == catalogEntryID) { return this.catalogEntries.remove(catalogEntry);