Remove constructor arguments and add getters and setters for CustomCatalogEntry

This commit is contained in:
Erik Hohlfeld 2023-11-10 18:34:31 +01:00 committed by Simon Bruder
parent 6875622c19
commit de0fbc31dc
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
3 changed files with 23 additions and 18 deletions

View file

@ -1,5 +1,8 @@
package catering.orderCatalog; package catering.orderCatalog;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
public class CustomCatalogEntry { 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 minimumTimePeriod; // Declared as int for simplification of the prototype. Only whole hours.
private int totalCost; // Should actually accumulate the price of all items. private int totalCost; // Should actually accumulate the price of all items.
public CustomCatalogEntry(EventType eventType, Map<String, Integer> products, int minimumTimePeriod, int totalCost) { public CustomCatalogEntry() {
this.id = idCounter; this.id = idCounter;
idCounter++; idCounter++;
this.eventType = eventType; this.eventType = EventType.EVENT_CATERING;
this.products = products; this.products = new HashMap<String, Integer>();
this.minimumTimePeriod = minimumTimePeriod; this.minimumTimePeriod = 5;
this.totalCost = totalCost; this.totalCost = 3;
} }
public int getId() { public int getId() {
@ -39,6 +42,18 @@ public class CustomCatalogEntry {
return totalCost + ""; 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 { public enum EventType {
EVENT_CATERING, EVENT_CATERING,
PARTY_SERVICE, PARTY_SERVICE,

View file

@ -20,12 +20,7 @@ public class CustomCatalogEntryDataInitializer implements DataInitializer {
Map<String, Integer> products = new HashMap<>(); Map<String, Integer> products = new HashMap<>();
products.put("Brötchen", 30); products.put("Brötchen", 30);
products.put("Kerze", 20); products.put("Kerze", 20);
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry( catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry());
CustomCatalogEntry.EventType.EVENT_CATERING,
products,
3,
300
));
products = new HashMap<>(); products = new HashMap<>();
products.put("Kuchen", 3); products.put("Kuchen", 3);
@ -33,11 +28,6 @@ public class CustomCatalogEntryDataInitializer implements DataInitializer {
products.put("Pizza Margherita", 1); products.put("Pizza Margherita", 1);
products.put("Pizza Quattro Formaggi", 1); products.put("Pizza Quattro Formaggi", 1);
products.put("Ballon", 20); products.put("Ballon", 20);
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry( catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry());
CustomCatalogEntry.EventType.PARTY_SERVICE,
products,
3,
500
));
} }
} }

View file

@ -17,7 +17,7 @@ public class CustomCatalogEntryRepository {
return catalogEntries.add(catalogEntry); return catalogEntries.add(catalogEntry);
} }
public boolean removeOrder(int catalogEntryID) { public boolean removeCatalogEntry(int catalogEntryID) {
for (CustomCatalogEntry catalogEntry : catalogEntries) { for (CustomCatalogEntry catalogEntry : catalogEntries) {
if (catalogEntry.getId() == catalogEntryID) { if (catalogEntry.getId() == catalogEntryID) {
return this.catalogEntries.remove(catalogEntry); return this.catalogEntries.remove(catalogEntry);