mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add checkout and change of orderType
This commit is contained in:
parent
0cc3232db3
commit
6d8b8bd5ca
|
@ -1,5 +1,6 @@
|
|||
package catering.order;
|
||||
|
||||
import org.salespointframework.quantity.Quantity;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -9,7 +10,7 @@ import java.util.Map;
|
|||
@Component
|
||||
public class CustomCart {
|
||||
private CustomOrder.OrderType orderType;
|
||||
private Map<String, Integer> products;
|
||||
private Map<String, Quantity> products;
|
||||
|
||||
public CustomCart() {
|
||||
this.orderType = CustomOrder.OrderType.SOMETHING_ELSE;
|
||||
|
@ -25,15 +26,20 @@ public class CustomCart {
|
|||
return;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getProucts() {
|
||||
public Map<String, Quantity> getProucts() {
|
||||
return products;
|
||||
}
|
||||
|
||||
public void addProduct(String product, int number) {
|
||||
products.put(product, number);
|
||||
products.put(product, Quantity.of(number));
|
||||
}
|
||||
|
||||
public boolean removeProduct(String product) {
|
||||
return products.remove(product) != null;
|
||||
}
|
||||
|
||||
public void resetCart() {
|
||||
orderType = CustomOrder.OrderType.SOMETHING_ELSE;
|
||||
products = new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
package catering.order;
|
||||
|
||||
import org.salespointframework.quantity.Quantity;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Controller
|
||||
public class OrderController {
|
||||
|
@ -26,8 +30,8 @@ public class OrderController {
|
|||
|
||||
@GetMapping("/event")
|
||||
public String event(Model model) {
|
||||
model.addAttribute("orderType", cart.getOrderType());
|
||||
model.addAttribute("items", cart.getProucts());
|
||||
model.addAttribute("type", cart.getOrderType());
|
||||
model.addAttribute("productForm", new ProductForm());
|
||||
return "event";
|
||||
}
|
||||
|
@ -40,11 +44,49 @@ public class OrderController {
|
|||
|
||||
|
||||
@PostMapping("/event/addProduct")
|
||||
public String addProduct(@ModelAttribute ProductForm product, Model model) {
|
||||
cart.addProduct(product.getProduct(), product.getNumber());
|
||||
public String addProduct(@ModelAttribute ProductForm productForm, Model model) {
|
||||
cart.addProduct(productForm.getProduct(), productForm.getNumber());
|
||||
model.addAttribute("orderType", cart.getOrderType());
|
||||
model.addAttribute("items", cart.getProucts());
|
||||
model.addAttribute("type", cart.getOrderType());
|
||||
model.addAttribute("productForm", new ProductForm());
|
||||
return "redirect:/event";
|
||||
}
|
||||
|
||||
@PostMapping("/event/checkout")
|
||||
public String checkout(Model model) {
|
||||
System.out.println(cart);
|
||||
CustomOrder myOrder = new CustomOrder(
|
||||
cart.getOrderType(),
|
||||
LocalDateTime.MIN,
|
||||
LocalDateTime.MAX,
|
||||
cart.getProucts(),
|
||||
false,
|
||||
Double.MAX_VALUE
|
||||
);
|
||||
|
||||
orderRepository.addOrder(myOrder);
|
||||
model.addAttribute("orders", orderRepository.getOrders());
|
||||
model.addAttribute("total", orderRepository.getOrders().size());
|
||||
cart.resetCart();
|
||||
return "redirect:/orders";
|
||||
}
|
||||
|
||||
@PostMapping("/event/changeOrderType")
|
||||
public String changeOrderType(@RequestParam(name = "orderType") Optional<String> optionalOrderType, Model model) {
|
||||
String orderType = optionalOrderType.orElse("DEINE_FETTE_MUTTER");
|
||||
switch (orderType) {
|
||||
case "RaK":
|
||||
cart.setOrderType(CustomOrder.OrderType.RENT_A_COOK);
|
||||
break;
|
||||
case "EK":
|
||||
cart.setOrderType(CustomOrder.OrderType.EVENT_CATERING);
|
||||
break;
|
||||
case "SN":
|
||||
cart.setOrderType(CustomOrder.OrderType.SUSHI_NIGHT);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return "redirect:/event";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<head>
|
||||
<meta charset="utf-8">
|
||||
<link rel="stylesheet" th:href="@{/resources/css/style.css}">
|
||||
<title th:text="Katalog">Katalog</title>
|
||||
<title th:text="Eventplaner">Katalog</title>
|
||||
</head>
|
||||
<body>
|
||||
<div class="topnav"> <!-- später für css -->
|
||||
|
@ -18,10 +18,21 @@
|
|||
|
||||
<h1>Eventplaner (planen Sie Ihr Event)</h1>
|
||||
|
||||
<span th:text="'Typ: ' + ${type}"/>
|
||||
<span th:text="'Typ: ' + ${orderType}"/>
|
||||
|
||||
<form th:action="@{/event/changeOrderType}" method="post">
|
||||
<select name="orderType">
|
||||
<option disabled="disabled" selected value="NULL" th:text="' -- Wählen Sie eine Option -- '"/>
|
||||
<option th:value="'SE'" th:text="'Something else'"/>
|
||||
<option th:value="'RaK'" th:text="Rent-a-Cook"/>
|
||||
<option th:value="'EK'" th:text="Eventcatering"/>
|
||||
<option th:value="'SN'" th:text="'Sushi Night'"/>
|
||||
</select>
|
||||
<input type="submit" value="Eventtypen ändern"/>
|
||||
</form>
|
||||
|
||||
<table style="width:100%; text-align:left">
|
||||
<tr>
|
||||
<tr>
|
||||
<th>Produkt</th>
|
||||
<th>Anzahl</th>
|
||||
</tr>
|
||||
|
@ -47,6 +58,12 @@
|
|||
<input type="submit" value="Submit"/>
|
||||
</form>
|
||||
|
||||
<div>
|
||||
<form method="post" th:action="@{/event/checkout}">
|
||||
<input type="submit" th:value="'Kostenpflichtig bestellen'"/>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
||||
<footer style="bottom: 0; position: absolute;">
|
||||
|
|
Loading…
Reference in a new issue