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 f1f71beaf4
commit 3470a369c7
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;
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<String, Integer> 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<String, Integer>();
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,

View file

@ -20,12 +20,7 @@ public class CustomCatalogEntryDataInitializer implements DataInitializer {
Map<String, Integer> 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());
}
}

View file

@ -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);