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;
|
return totalCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
private enum OrderType {
|
enum OrderType {
|
||||||
RENT_A_COOK,
|
RENT_A_COOK,
|
||||||
EVENT_CATERING,
|
EVENT_CATERING,
|
||||||
SUSHI_NIGHT,
|
SUSHI_NIGHT,
|
||||||
|
|
|
@ -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
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,4 @@ public class WelcomeController {
|
||||||
public String catalog() {
|
public String catalog() {
|
||||||
return "catalog";
|
return "catalog";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/orders")
|
|
||||||
public String orders() {
|
|
||||||
return "orders";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue