Add data initialization and total count of orders

This commit is contained in:
Mathis Kral 2023-11-05 12:33:43 +01:00 committed by Simon Bruder
parent 6ce60ec3de
commit dcae05cd24
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
6 changed files with 59 additions and 12 deletions

View file

@ -51,7 +51,7 @@ public class CustomOrder {
return totalCost; return totalCost;
} }
private enum OrderType { enum OrderType {
RENT_A_COOK, RENT_A_COOK,
EVENT_CATERING, EVENT_CATERING,
SUSHI_NIGHT, SUSHI_NIGHT,

View file

@ -1,8 +1,13 @@
package catering.order; package catering.order;
import org.salespointframework.core.DataInitializer; import org.salespointframework.core.DataInitializer;
import org.salespointframework.quantity.Quantity;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
@Component @Component
public class CustomOrderDataInitializer implements DataInitializer { public class CustomOrderDataInitializer implements DataInitializer {
private CustomOrderRepository orderRepository; private CustomOrderRepository orderRepository;
@ -13,6 +18,32 @@ public class CustomOrderDataInitializer implements DataInitializer {
@Override @Override
public void initialize() { public void initialize() {
// initialize custom orders System.out.println("Initialize OrderRepository");
Map<String, Quantity> 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
));
} }
} }

View file

@ -1,11 +1,15 @@
package catering.order; package catering.order;
import org.springframework.stereotype.Component;
import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
/** /**
* This class is only used for the prototype to avoid using the bloated Salespoint API * This class is only used for the prototype to avoid using the bloated Salespoint API
*/ */
@Component
public class CustomOrderRepository { public class CustomOrderRepository {
private Set<CustomOrder> orders; private Set<CustomOrder> orders;
@ -21,7 +25,7 @@ public class CustomOrderRepository {
return this.orders.remove(order); return this.orders.remove(order);
} }
public Set<CustomOrder> getOrders() { public Collection<CustomOrder> getOrders() {
return this.orders; return this.orders;
} }
} }

View file

@ -1,8 +1,21 @@
package catering.order; package catering.order;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller @Controller
public class OrderController { 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";
}
} }

View file

@ -30,9 +30,4 @@ public class WelcomeController {
public String catalog() { public String catalog() {
return "catalog"; return "catalog";
} }
@GetMapping("/orders")
public String orders() {
return "orders";
}
} }

View file

@ -16,11 +16,10 @@
</div> </div>
<div> <div>
<h1>Auftragsliste</h1> <h1>Auftragsliste</h1>
</div> </div>
<div> <!--th:unless"${cart.empty}"--> <div> <!--th:unless"${cart.empty}"-->
<h2>Zukünftige Aufträge</h2>
<table style="width:100%; text-align:left"> <table style="width:100%; text-align:left">
<tr> <tr>
<th>Von</th> <th>Von</th>
@ -66,11 +65,16 @@
</tr> </tr>
</table> </table>
</div> </div>
<span>
<th:block th:text="Total:"/>
<th:block th:text="${total}"/>
</span>
</body> </body>
<footer style="bottom: 0; position: absolute;"> <footer style="bottom: 0; position: absolute;">
<p>© Hannes Wurst @ Mampf GmbH</p> <p>© Hannes Wurst @ Mampf GmbH</p>
<p> <p>
<a href="mailto:catering@mampf.com">catering@mampf.com</a> <a href="mailto:catering@mampf.com">catering@mampf.com</a>
</p> </p>
</footer> </footer>