mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add order removal
This commit is contained in:
parent
895b68c028
commit
f5454ddab5
|
@ -12,6 +12,7 @@ import java.util.Map;
|
||||||
*/
|
*/
|
||||||
public class CustomOrder {
|
public class CustomOrder {
|
||||||
|
|
||||||
|
private int id;
|
||||||
private OrderType orderType;
|
private OrderType orderType;
|
||||||
private LocalDateTime start;
|
private LocalDateTime start;
|
||||||
private LocalDateTime finish;
|
private LocalDateTime finish;
|
||||||
|
@ -21,6 +22,7 @@ public class CustomOrder {
|
||||||
private DateTimeFormatter formatter;
|
private DateTimeFormatter formatter;
|
||||||
|
|
||||||
public CustomOrder(OrderType orderType, LocalDateTime start, LocalDateTime finish, Map<String, Quantity> products, boolean invoiceAvailable, double totalCost) {
|
public CustomOrder(OrderType orderType, LocalDateTime start, LocalDateTime finish, Map<String, Quantity> products, boolean invoiceAvailable, double totalCost) {
|
||||||
|
this.id = (int) (Math.random() * Integer.MAX_VALUE);
|
||||||
this.orderType = orderType;
|
this.orderType = orderType;
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.finish = finish;
|
this.finish = finish;
|
||||||
|
@ -30,6 +32,10 @@ public class CustomOrder {
|
||||||
this.formatter = DateTimeFormatter.ofPattern("MM.dd.yyy, HH:mm 'Uhr'");
|
this.formatter = DateTimeFormatter.ofPattern("MM.dd.yyy, HH:mm 'Uhr'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
public OrderType getOrderType() {
|
public OrderType getOrderType() {
|
||||||
return orderType;
|
return orderType;
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,5 +45,19 @@ public class CustomOrderDataInitializer implements DataInitializer {
|
||||||
true,
|
true,
|
||||||
10000.0
|
10000.0
|
||||||
));
|
));
|
||||||
|
|
||||||
|
products = new HashMap<>();
|
||||||
|
products.put("Koch", Quantity.of(2));
|
||||||
|
products.put("Wiener Schnitzel (vegan)", Quantity.of(1000));
|
||||||
|
products.put("Wiener Würstchen", Quantity.of(150));
|
||||||
|
products.put("Weißwurst (vegan)", Quantity.of(300));
|
||||||
|
orderRepository.addOrder(new CustomOrder(
|
||||||
|
CustomOrder.OrderType.RENT_A_COOK,
|
||||||
|
LocalDateTime.of(2023, 12, 24, 11, 0),
|
||||||
|
LocalDateTime.of(2023, 12, 25, 14, 0),
|
||||||
|
products,
|
||||||
|
true,
|
||||||
|
4000.0
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,8 +22,13 @@ public class CustomOrderRepository {
|
||||||
return this.orders.add(order);
|
return this.orders.add(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean removeOrder(CustomOrder order) {
|
public boolean removeOrder(int orderID) {
|
||||||
return this.orders.remove(order);
|
for (CustomOrder order : orders) {
|
||||||
|
if (order.getId() == orderID) {
|
||||||
|
return this.orders.remove(order);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection<CustomOrder> getOrders() {
|
public Collection<CustomOrder> getOrders() {
|
||||||
|
|
|
@ -3,6 +3,8 @@ package catering.order;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
@ -21,4 +23,10 @@ public class OrderController {
|
||||||
model.addAttribute("total", orderRepository.getOrders().size());
|
model.addAttribute("total", orderRepository.getOrders().size());
|
||||||
return "orders";
|
return "orders";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/orders/remove")
|
||||||
|
public String removeOrder(@RequestParam int orderID) {
|
||||||
|
orderRepository.removeOrder(orderID);
|
||||||
|
return "redirect:/orders";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h1>Auftragsliste</h1>
|
<h1>Auftragsliste</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div> <!--th:unless"${cart.empty}"-->
|
<div> <!--th:unless"${cart.empty}"-->
|
||||||
|
@ -31,7 +31,7 @@
|
||||||
<th>Preis</th>
|
<th>Preis</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
<tr th:each="order : ${orders}"> <!--später th:each="cart.products"-->
|
<tr th:each="order : ${orders}">
|
||||||
<td th:text="${order.getFormattedStart()}">
|
<td th:text="${order.getFormattedStart()}">
|
||||||
<td th:text="${order.getFormattedFinish()}">
|
<td th:text="${order.getFormattedFinish()}">
|
||||||
<td th:text="BeispielKunde"/>
|
<td th:text="BeispielKunde"/>
|
||||||
|
@ -51,8 +51,11 @@
|
||||||
<th:block th:text="${order.getTotalCost()}"/>
|
<th:block th:text="${order.getTotalCost()}"/>
|
||||||
<th:block th:text="€"/>
|
<th:block th:text="€"/>
|
||||||
</td>
|
</td>
|
||||||
<td> <!--th:if="product.isRemovable"-->
|
<td>
|
||||||
<button type="button">Entfernen</button>
|
<form method="post" th:action="@{/orders/remove}">
|
||||||
|
<input type="hidden" name="orderID" value="0" th:value="${order.getId()}"/>
|
||||||
|
<input type="submit" value="remove" th:value="Entfernen"/>
|
||||||
|
</form>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
@ -66,8 +69,8 @@
|
||||||
</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