From a6faa677dd66c02b3a09e80211f45a1659b6e9b2 Mon Sep 17 00:00:00 2001 From: Mathis Kral Date: Sun, 5 Nov 2023 15:36:46 +0100 Subject: [PATCH] Add orderRepositoryIterator in orders.html --- src/main/java/catering/order/CustomOrder.java | 13 ++++- .../order/CustomOrderDataInitializer.java | 4 +- .../catering/order/CustomOrderRepository.java | 3 +- .../java/catering/order/OrderController.java | 3 ++ src/main/resources/templates/orders.html | 49 ++++++++----------- 5 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/main/java/catering/order/CustomOrder.java b/src/main/java/catering/order/CustomOrder.java index e4cc5f0..ab5a865 100644 --- a/src/main/java/catering/order/CustomOrder.java +++ b/src/main/java/catering/order/CustomOrder.java @@ -4,6 +4,7 @@ import org.aspectj.weaver.ast.Or; import org.salespointframework.quantity.Quantity; import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.Map; /** @@ -17,6 +18,7 @@ public class CustomOrder { private Map products; private boolean invoiceAvailable; private double totalCost; // this is in € + private DateTimeFormatter formatter; public CustomOrder(OrderType orderType, LocalDateTime start, LocalDateTime finish, Map products, boolean invoiceAvailable, double totalCost) { this.orderType = orderType; @@ -25,6 +27,7 @@ public class CustomOrder { this.products = products; this.invoiceAvailable = invoiceAvailable; this.totalCost = totalCost; + this.formatter = DateTimeFormatter.ofPattern("MM.dd.yyy, HH:mm 'Uhr'"); } public OrderType getOrderType() { @@ -35,15 +38,23 @@ public class CustomOrder { return start; } + public String getFormattedStart() { + return start.format(formatter); + } + public LocalDateTime getFinish() { return finish; } + public String getFormattedFinish() { + return finish.format(formatter); + } + public Map getProducts() { return products; } - public boolean isInvoiceAvailable() { + public boolean invoiceAvailable() { return invoiceAvailable; } diff --git a/src/main/java/catering/order/CustomOrderDataInitializer.java b/src/main/java/catering/order/CustomOrderDataInitializer.java index d5359e8..44caf7d 100644 --- a/src/main/java/catering/order/CustomOrderDataInitializer.java +++ b/src/main/java/catering/order/CustomOrderDataInitializer.java @@ -28,7 +28,7 @@ public class CustomOrderDataInitializer implements DataInitializer { LocalDateTime.of(2023, 12, 5, 18, 0), LocalDateTime.of(2023, 12, 5, 23, 0), products, - true, + false, 2000.0 )); @@ -38,7 +38,7 @@ public class CustomOrderDataInitializer implements DataInitializer { products.put("Käseplatte", Quantity.of(1000)); products.put("Wiener Würstchen", Quantity.of(150)); orderRepository.addOrder(new CustomOrder( - CustomOrder.OrderType.SUSHI_NIGHT, + CustomOrder.OrderType.EVENT_CATERING, LocalDateTime.of(2023, 10, 2, 11, 0), LocalDateTime.of(2023, 10, 3, 8, 0), products, diff --git a/src/main/java/catering/order/CustomOrderRepository.java b/src/main/java/catering/order/CustomOrderRepository.java index 065c6dc..0f39efa 100644 --- a/src/main/java/catering/order/CustomOrderRepository.java +++ b/src/main/java/catering/order/CustomOrderRepository.java @@ -2,6 +2,7 @@ package catering.order; import org.springframework.stereotype.Component; +import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.Set; @@ -26,6 +27,6 @@ public class CustomOrderRepository { } public Collection getOrders() { - return this.orders; + return new ArrayList<>(this.orders); } } diff --git a/src/main/java/catering/order/OrderController.java b/src/main/java/catering/order/OrderController.java index 307a24f..b6705c1 100644 --- a/src/main/java/catering/order/OrderController.java +++ b/src/main/java/catering/order/OrderController.java @@ -4,6 +4,8 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import java.util.ArrayList; + @Controller public class OrderController { @@ -15,6 +17,7 @@ public class OrderController { @GetMapping("/orders") public String orders(Model model) { + model.addAttribute("orders", orderRepository.getOrders()); model.addAttribute("total", orderRepository.getOrders().size()); return "orders"; } diff --git a/src/main/resources/templates/orders.html b/src/main/resources/templates/orders.html index 68289cb..a49e580 100644 --- a/src/main/resources/templates/orders.html +++ b/src/main/resources/templates/orders.html @@ -16,7 +16,7 @@
-

Auftragsliste

+

Auftragsliste

@@ -25,56 +25,49 @@ Von Bis Kunde - Produkt + Produktdetails Rechnung Bezahlt Preis - - 01.10.2024 0:00Uhr - 30.10.2023 23:59Uhr - Hans Käse + + + + - Mobile Breakfast + - noch keine Rechnung verfügbar + +
+ Keine Rechnung verfügbar +
- 10550,99€ + + + + - - 24.11.2023 10:00Uhr - 24.11.2023 15:00Uhr - Hans Käse - - Rent-a-Cook - - - Rechnung - - ☑ - 350,99 - - - -
- + +