diff --git a/src/main/java/catering/order/CustomCart.java b/src/main/java/catering/order/CustomCart.java index 091cc68..ccc29ed 100644 --- a/src/main/java/catering/order/CustomCart.java +++ b/src/main/java/catering/order/CustomCart.java @@ -1,5 +1,6 @@ package catering.order; +import org.salespointframework.quantity.Quantity; import org.springframework.stereotype.Component; import java.util.HashMap; @@ -9,7 +10,7 @@ import java.util.Map; @Component public class CustomCart { private CustomOrder.OrderType orderType; - private Map products; + private Map products; public CustomCart() { this.orderType = CustomOrder.OrderType.SOMETHING_ELSE; @@ -25,15 +26,20 @@ public class CustomCart { return; } - public Map getProucts() { + public Map getProucts() { return products; } public void addProduct(String product, int number) { - products.put(product, number); + products.put(product, Quantity.of(number)); } public boolean removeProduct(String product) { return products.remove(product) != null; } + + public void resetCart() { + orderType = CustomOrder.OrderType.SOMETHING_ELSE; + products = new HashMap<>(); + } } diff --git a/src/main/java/catering/order/OrderController.java b/src/main/java/catering/order/OrderController.java index 7bce790..6abc26e 100644 --- a/src/main/java/catering/order/OrderController.java +++ b/src/main/java/catering/order/OrderController.java @@ -1,10 +1,14 @@ package catering.order; +import org.salespointframework.quantity.Quantity; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; +import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Map; +import java.util.Optional; @Controller public class OrderController { @@ -26,8 +30,8 @@ public class OrderController { @GetMapping("/event") public String event(Model model) { + model.addAttribute("orderType", cart.getOrderType()); model.addAttribute("items", cart.getProucts()); - model.addAttribute("type", cart.getOrderType()); model.addAttribute("productForm", new ProductForm()); return "event"; } @@ -40,11 +44,49 @@ public class OrderController { @PostMapping("/event/addProduct") - public String addProduct(@ModelAttribute ProductForm product, Model model) { - cart.addProduct(product.getProduct(), product.getNumber()); + public String addProduct(@ModelAttribute ProductForm productForm, Model model) { + cart.addProduct(productForm.getProduct(), productForm.getNumber()); + model.addAttribute("orderType", cart.getOrderType()); model.addAttribute("items", cart.getProucts()); - model.addAttribute("type", cart.getOrderType()); model.addAttribute("productForm", new ProductForm()); return "redirect:/event"; } + + @PostMapping("/event/checkout") + public String checkout(Model model) { + System.out.println(cart); + CustomOrder myOrder = new CustomOrder( + cart.getOrderType(), + LocalDateTime.MIN, + LocalDateTime.MAX, + cart.getProucts(), + false, + Double.MAX_VALUE + ); + + orderRepository.addOrder(myOrder); + model.addAttribute("orders", orderRepository.getOrders()); + model.addAttribute("total", orderRepository.getOrders().size()); + cart.resetCart(); + return "redirect:/orders"; + } + + @PostMapping("/event/changeOrderType") + public String changeOrderType(@RequestParam(name = "orderType") Optional optionalOrderType, Model model) { + String orderType = optionalOrderType.orElse("DEINE_FETTE_MUTTER"); + switch (orderType) { + case "RaK": + cart.setOrderType(CustomOrder.OrderType.RENT_A_COOK); + break; + case "EK": + cart.setOrderType(CustomOrder.OrderType.EVENT_CATERING); + break; + case "SN": + cart.setOrderType(CustomOrder.OrderType.SUSHI_NIGHT); + break; + default: + } + + return "redirect:/event"; + } } diff --git a/src/main/resources/templates/event.html b/src/main/resources/templates/event.html index de67872..303bf13 100644 --- a/src/main/resources/templates/event.html +++ b/src/main/resources/templates/event.html @@ -5,7 +5,7 @@ - Katalog + Katalog
@@ -18,10 +18,21 @@

Eventplaner (planen Sie Ihr Event)

- + + +
+ + +
- + @@ -47,6 +58,12 @@ +
+
+ + +
+
Produkt Anzahl