diff --git a/src/main/java/catering/order/CustomCart.java b/src/main/java/catering/order/CustomCart.java new file mode 100644 index 0000000..091cc68 --- /dev/null +++ b/src/main/java/catering/order/CustomCart.java @@ -0,0 +1,39 @@ +package catering.order; + +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + + +@Component +public class CustomCart { + private CustomOrder.OrderType orderType; + private Map products; + + public CustomCart() { + this.orderType = CustomOrder.OrderType.SOMETHING_ELSE; + this.products = new HashMap<>(); + } + + public CustomOrder.OrderType getOrderType() { + return orderType; + } + + public void setOrderType(CustomOrder.OrderType type) { + this.orderType = type; + return; + } + + public Map getProucts() { + return products; + } + + public void addProduct(String product, int number) { + products.put(product, number); + } + + public boolean removeProduct(String product) { + return products.remove(product) != null; + } +} diff --git a/src/main/java/catering/order/CustomOrder.java b/src/main/java/catering/order/CustomOrder.java index 2d92d06..f694f57 100644 --- a/src/main/java/catering/order/CustomOrder.java +++ b/src/main/java/catering/order/CustomOrder.java @@ -32,7 +32,7 @@ public class CustomOrder { this.products = products; this.invoiceAvailable = invoiceAvailable; this.totalCost = totalCost; - this.formatter = DateTimeFormatter.ofPattern("MM.dd.yyy, HH:mm 'Uhr'"); + this.formatter = DateTimeFormatter.ofPattern("dd.MM.yyy, HH:mm 'Uhr'"); } public int getId() { diff --git a/src/main/java/catering/order/OrderController.java b/src/main/java/catering/order/OrderController.java index 555e55a..7bce790 100644 --- a/src/main/java/catering/order/OrderController.java +++ b/src/main/java/catering/order/OrderController.java @@ -2,9 +2,7 @@ package catering.order; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.*; import java.util.ArrayList; @@ -12,9 +10,11 @@ import java.util.ArrayList; public class OrderController { private final CustomOrderRepository orderRepository; + private final CustomCart cart; - public OrderController(CustomOrderRepository orderRepository) { + public OrderController(CustomOrderRepository orderRepository, CustomCart cart) { this.orderRepository = orderRepository; + this.cart = cart; } @GetMapping("/orders") @@ -25,8 +25,11 @@ public class OrderController { } @GetMapping("/event") - public String event() { - return "eventPlanner"; + public String event(Model model) { + model.addAttribute("items", cart.getProucts()); + model.addAttribute("type", cart.getOrderType()); + model.addAttribute("productForm", new ProductForm()); + return "event"; } @PostMapping("/orders/remove") @@ -34,4 +37,14 @@ public class OrderController { orderRepository.removeOrder(orderID); return "redirect:/orders"; } + + + @PostMapping("/event/addProduct") + public String addProduct(@ModelAttribute ProductForm product, Model model) { + cart.addProduct(product.getProduct(), product.getNumber()); + model.addAttribute("items", cart.getProucts()); + model.addAttribute("type", cart.getOrderType()); + model.addAttribute("productForm", new ProductForm()); + return "redirect:/event"; + } } diff --git a/src/main/java/catering/order/ProductForm.java b/src/main/java/catering/order/ProductForm.java new file mode 100644 index 0000000..4a22739 --- /dev/null +++ b/src/main/java/catering/order/ProductForm.java @@ -0,0 +1,24 @@ +package catering.order; + +import org.springframework.web.bind.annotation.ModelAttribute; + +public class ProductForm { + private String product; + private int number; + + public String getProduct() { + return product; + } + + public int getNumber() { + return number; + } + + public void setProduct(String product) { + this.product = product; + } + + public void setNumber(int number) { + this.number = number; + } +} diff --git a/src/main/java/catering/welcome/WelcomeController.java b/src/main/java/catering/welcome/WelcomeController.java index 0c6f75d..c79b936 100644 --- a/src/main/java/catering/welcome/WelcomeController.java +++ b/src/main/java/catering/welcome/WelcomeController.java @@ -31,8 +31,4 @@ public class WelcomeController { return "catalog"; } - @GetMapping("/event_configuration") - public String event_configuration() { - return "event_configuration"; - } } diff --git a/src/main/resources/templates/eventPlanner.html b/src/main/resources/templates/event.html similarity index 63% rename from src/main/resources/templates/eventPlanner.html rename to src/main/resources/templates/event.html index b14768c..de67872 100644 --- a/src/main/resources/templates/eventPlanner.html +++ b/src/main/resources/templates/event.html @@ -18,21 +18,35 @@

Eventplaner (planen Sie Ihr Event)

+ + - - - - - - - + + +
EventtypSISHI_NIGHT
Produkt Anzahl
Sake Nigiri200
Sake Nigiri200
+

Product hinzufügen

+ +
+
+ + +
+ +
+ + +
+ + +
+