diff --git a/src/main/java/catering/order/CustomOrder.java b/src/main/java/catering/order/CustomOrder.java index 834651c..e4cc5f0 100644 --- a/src/main/java/catering/order/CustomOrder.java +++ b/src/main/java/catering/order/CustomOrder.java @@ -51,7 +51,7 @@ public class CustomOrder { return totalCost; } - private enum OrderType { + enum OrderType { RENT_A_COOK, EVENT_CATERING, SUSHI_NIGHT, diff --git a/src/main/java/catering/order/CustomOrderDataInitializer.java b/src/main/java/catering/order/CustomOrderDataInitializer.java index 193d5af..d5359e8 100644 --- a/src/main/java/catering/order/CustomOrderDataInitializer.java +++ b/src/main/java/catering/order/CustomOrderDataInitializer.java @@ -1,8 +1,13 @@ package catering.order; import org.salespointframework.core.DataInitializer; +import org.salespointframework.quantity.Quantity; import org.springframework.stereotype.Component; +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.Map; + @Component public class CustomOrderDataInitializer implements DataInitializer { private CustomOrderRepository orderRepository; @@ -13,6 +18,32 @@ public class CustomOrderDataInitializer implements DataInitializer { @Override public void initialize() { - // initialize custom orders + System.out.println("Initialize OrderRepository"); + + Map products = new HashMap<>(); + products.put("Sake Maki", Quantity.of(100)); + products.put("Sake Nigiri", Quantity.of(101)); + orderRepository.addOrder(new CustomOrder( + CustomOrder.OrderType.SUSHI_NIGHT, + LocalDateTime.of(2023, 12, 5, 18, 0), + LocalDateTime.of(2023, 12, 5, 23, 0), + products, + true, + 2000.0 + )); + + products = new HashMap<>(); + products.put("Koch", Quantity.of(3)); + products.put("Wasser (still)", Quantity.of(101)); + products.put("Käseplatte", Quantity.of(1000)); + products.put("Wiener Würstchen", Quantity.of(150)); + orderRepository.addOrder(new CustomOrder( + CustomOrder.OrderType.SUSHI_NIGHT, + LocalDateTime.of(2023, 10, 2, 11, 0), + LocalDateTime.of(2023, 10, 3, 8, 0), + products, + true, + 10000.0 + )); } } diff --git a/src/main/java/catering/order/CustomOrderRepository.java b/src/main/java/catering/order/CustomOrderRepository.java index 15776cc..065c6dc 100644 --- a/src/main/java/catering/order/CustomOrderRepository.java +++ b/src/main/java/catering/order/CustomOrderRepository.java @@ -1,11 +1,15 @@ package catering.order; +import org.springframework.stereotype.Component; + +import java.util.Collection; import java.util.HashSet; import java.util.Set; /** * This class is only used for the prototype to avoid using the bloated Salespoint API */ +@Component public class CustomOrderRepository { private Set orders; @@ -21,7 +25,7 @@ public class CustomOrderRepository { return this.orders.remove(order); } - public Set getOrders() { + public Collection getOrders() { return this.orders; } } diff --git a/src/main/java/catering/order/OrderController.java b/src/main/java/catering/order/OrderController.java index 533d5c9..307a24f 100644 --- a/src/main/java/catering/order/OrderController.java +++ b/src/main/java/catering/order/OrderController.java @@ -1,8 +1,21 @@ package catering.order; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; @Controller public class OrderController { + private final CustomOrderRepository orderRepository; + + public OrderController(CustomOrderRepository orderRepository) { + this.orderRepository = orderRepository; + } + + @GetMapping("/orders") + public String orders(Model model) { + model.addAttribute("total", orderRepository.getOrders().size()); + return "orders"; + } } diff --git a/src/main/java/catering/welcome/WelcomeController.java b/src/main/java/catering/welcome/WelcomeController.java index 03a9ac9..42ff58e 100644 --- a/src/main/java/catering/welcome/WelcomeController.java +++ b/src/main/java/catering/welcome/WelcomeController.java @@ -30,9 +30,4 @@ public class WelcomeController { public String catalog() { return "catalog"; } - - @GetMapping("/orders") - public String orders() { - return "orders"; - } } diff --git a/src/main/resources/templates/orders.html b/src/main/resources/templates/orders.html index 4fb9b8f..68289cb 100644 --- a/src/main/resources/templates/orders.html +++ b/src/main/resources/templates/orders.html @@ -16,11 +16,10 @@
-

Auftragsliste

+

Auftragsliste

-

Zukünftige Aufträge

@@ -66,11 +65,16 @@
Von
+ + + + +