Make orderCatalog use OrderType

This commit is contained in:
Erik Hohlfeld 2023-11-21 11:34:25 +01:00 committed by Simon Bruder
parent 2248e8eeef
commit 317af597f5
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
4 changed files with 21 additions and 25 deletions

View file

@ -1,5 +1,6 @@
package catering.orderCatalog; package catering.orderCatalog;
import catering.order.OrderType;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -17,7 +18,7 @@ public class CatalogController {
public CatalogController(CustomCatalogEntryRepository catalogEntryRepository) { public CatalogController(CustomCatalogEntryRepository catalogEntryRepository) {
inventory = new HashSet<>(); inventory = new HashSet<>();
formCatalogEntry = new CustomCatalogEntry( formCatalogEntry = new CustomCatalogEntry(
CustomCatalogEntry.EventType.EVENT_CATERING, OrderType.EVENT_CATERING,
new HashMap<String, Integer>(), new HashMap<String, Integer>(),
0, 0,
0); 0);
@ -38,7 +39,7 @@ public class CatalogController {
} }
@PostMapping("/catalog_editor/catalog_add") @PostMapping("/catalog_editor/catalog_add")
public String catalog_add(@RequestParam CustomCatalogEntry.EventType eventType, public String catalog_add(@RequestParam OrderType eventType,
@RequestParam int minimumTimePeriod, @RequestParam int minimumTimePeriod,
@RequestParam int totalCost, @RequestParam int totalCost,
Model model) { Model model) {
@ -48,14 +49,13 @@ public class CatalogController {
products.put(product.getName(), product.getAmount()); products.put(product.getName(), product.getAmount());
} }
System.out.println("Products looks like this:" + products);
catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry( catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(
eventType, eventType,
products, products,
minimumTimePeriod, minimumTimePeriod,
totalCost)); totalCost));
this.formCatalogEntry = new CustomCatalogEntry( this.formCatalogEntry = new CustomCatalogEntry(
CustomCatalogEntry.EventType.EVENT_CATERING, OrderType.EVENT_CATERING,
new HashMap<String, Integer>(), new HashMap<String, Integer>(),
0, 0,
0); 0);
@ -95,7 +95,7 @@ public class CatalogController {
@PostMapping("/catalog_editor/add_time") @PostMapping("/catalog_editor/add_time")
public String add_time(@RequestParam int minimumTimePeriod, public String add_time(@RequestParam int minimumTimePeriod,
@RequestParam CustomCatalogEntry.EventType eventType, @RequestParam OrderType eventType,
@RequestParam Map<String, Integer> products, @RequestParam Map<String, Integer> products,
Model model) { Model model) {
formCatalogEntry.setMinimumTimePeriod(minimumTimePeriod); formCatalogEntry.setMinimumTimePeriod(minimumTimePeriod);
@ -107,19 +107,19 @@ public class CatalogController {
public String chooseEvent(String events) { public String chooseEvent(String events) {
switch (events) { switch (events) {
case "event_catering": case "event_catering":
formCatalogEntry.setEventType(CustomCatalogEntry.EventType.EVENT_CATERING); formCatalogEntry.setEventType(OrderType.EVENT_CATERING);
break; break;
case "party_service": case "sushi_night":
formCatalogEntry.setEventType(CustomCatalogEntry.EventType.PARTY_SERVICE); formCatalogEntry.setEventType(OrderType.SUSHI_NIGHT);
break; break;
case "mobile_breakfast": case "mobile_breakfast":
formCatalogEntry.setEventType(CustomCatalogEntry.EventType.MOBILE_BREAKFAST); formCatalogEntry.setEventType(OrderType.MOBILE_BREAKFAST);
break; break;
case "rent_a_cook": case "rent_a_cook":
formCatalogEntry.setEventType(CustomCatalogEntry.EventType.RENT_A_COOK); formCatalogEntry.setEventType(OrderType.RENT_A_COOK);
break; break;
default: default:
formCatalogEntry.setEventType(CustomCatalogEntry.EventType.EVENT_CATERING); formCatalogEntry.setEventType(OrderType.EVENT_CATERING);
break; break;
} }

View file

@ -1,16 +1,18 @@
package catering.orderCatalog; package catering.orderCatalog;
import catering.order.OrderType;
import java.util.Map; import java.util.Map;
public class CustomCatalogEntry { public class CustomCatalogEntry {
static int idCounter = 0; static int idCounter = 0;
private int id; private int id;
private EventType eventType; private OrderType eventType;
private Map<String, Integer> products; private Map<String, Integer> products;
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(OrderType eventType, Map<String, Integer> products, int minimumTimePeriod, int totalCost) {
this.id = idCounter; this.id = idCounter;
idCounter++; idCounter++;
this.eventType = eventType; this.eventType = eventType;
@ -23,7 +25,7 @@ public class CustomCatalogEntry {
return id; return id;
} }
public EventType getEventType() { public OrderType getEventType() {
return eventType; return eventType;
} }
@ -39,7 +41,7 @@ public class CustomCatalogEntry {
return totalCost; return totalCost;
} }
public void setEventType(EventType eventType) { public void setEventType(OrderType eventType) {
this.eventType = eventType; this.eventType = eventType;
} }
@ -57,11 +59,4 @@ public class CustomCatalogEntry {
public void setTotalCost(int totalCost) { public void setTotalCost(int totalCost) {
this.totalCost = totalCost; this.totalCost = totalCost;
} }
public enum EventType {
EVENT_CATERING,
PARTY_SERVICE,
MOBILE_BREAKFAST,
RENT_A_COOK
}
} }

View file

@ -1,5 +1,6 @@
package catering.orderCatalog; package catering.orderCatalog;
import catering.order.OrderType;
import org.salespointframework.core.DataInitializer; import org.salespointframework.core.DataInitializer;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@ -20,7 +21,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(CustomCatalogEntry.EventType.EVENT_CATERING, products, 4, 500)); catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(OrderType.EVENT_CATERING, products, 4, 500));
products = new HashMap<>(); products = new HashMap<>();
products.put("Kuchen", 3); products.put("Kuchen", 3);
@ -28,6 +29,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(CustomCatalogEntry.EventType.PARTY_SERVICE, products, 2, 1000)); catalogEntryRepository.addCatalogEntry(new CustomCatalogEntry(OrderType.RENT_A_COOK, products, 2, 1000));
} }
} }

View file

@ -13,7 +13,7 @@
<form th:object="${formCatalogEntry}" method="post" th:action="@{/catalog_editor/chooseEvent}"> <form th:object="${formCatalogEntry}" method="post" th:action="@{/catalog_editor/chooseEvent}">
<select class="form-select w-auto d-inline-block" name="events" id="events"> <select class="form-select w-auto d-inline-block" name="events" id="events">
<option value="event_catering">Eventcatering</option> <option value="event_catering">Eventcatering</option>
<option value="party_service">Partyservice</option> <option value="sushi_night">Sushi Night</option>
<option value="mobile_breakfast">Mobile Breakfast</option> <option value="mobile_breakfast">Mobile Breakfast</option>
<option value="rent_a_cook">Rent-a-Cook</option> <option value="rent_a_cook">Rent-a-Cook</option>
</select> </select>