mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add data initialization and total count of orders
This commit is contained in:
parent
6ce60ec3de
commit
dcae05cd24
|
@ -51,7 +51,7 @@ public class CustomOrder {
|
|||
return totalCost;
|
||||
}
|
||||
|
||||
private enum OrderType {
|
||||
enum OrderType {
|
||||
RENT_A_COOK,
|
||||
EVENT_CATERING,
|
||||
SUSHI_NIGHT,
|
||||
|
|
|
@ -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<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
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<CustomOrder> orders;
|
||||
|
||||
|
@ -21,7 +25,7 @@ public class CustomOrderRepository {
|
|||
return this.orders.remove(order);
|
||||
}
|
||||
|
||||
public Set<CustomOrder> getOrders() {
|
||||
public Collection<CustomOrder> getOrders() {
|
||||
return this.orders;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,9 +30,4 @@ public class WelcomeController {
|
|||
public String catalog() {
|
||||
return "catalog";
|
||||
}
|
||||
|
||||
@GetMapping("/orders")
|
||||
public String orders() {
|
||||
return "orders";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,11 +16,10 @@
|
|||
</div>
|
||||
|
||||
<div>
|
||||
<h1>Auftragsliste</h1>
|
||||
<h1>Auftragsliste</h1>
|
||||
</div>
|
||||
|
||||
<div> <!--th:unless"${cart.empty}"-->
|
||||
<h2>Zukünftige Aufträge</h2>
|
||||
<table style="width:100%; text-align:left">
|
||||
<tr>
|
||||
<th>Von</th>
|
||||
|
@ -66,11 +65,16 @@
|
|||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<span>
|
||||
<th:block th:text="Total:"/>
|
||||
<th:block th:text="${total}"/>
|
||||
</span>
|
||||
</body>
|
||||
|
||||
<footer style="bottom: 0; position: absolute;">
|
||||
<p>© Hannes Wurst @ Mampf GmbH</p>
|
||||
<p>
|
||||
<p>© Hannes Wurst @ Mampf GmbH</p>
|
||||
<p>
|
||||
<a href="mailto:catering@mampf.com">catering@mampf.com</a>
|
||||
</p>
|
||||
</footer>
|
||||
|
|
Loading…
Reference in a new issue