mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
fixup! Update basics of order package to salespoint
This commit is contained in:
parent
43785cde3d
commit
bd0df0c9b4
|
@ -88,6 +88,7 @@ public class OrderController {
|
|||
@PreAuthorize("hasRole('CUSTOMER')")
|
||||
public String event(Model model, @ModelAttribute("event") CustomCart cart) {
|
||||
model.addAttribute("items", cart.stream().collect(Collectors.toList()));
|
||||
model.addAttribute("totalPrice", cart.getPrice());
|
||||
model.addAttribute("invItems", inventory.findAll().stream().collect(Collectors.toList()));
|
||||
return "event";
|
||||
}
|
||||
|
@ -108,7 +109,20 @@ public class OrderController {
|
|||
@PostMapping("/event/addProduct")
|
||||
@PreAuthorize("hasRole('CUSTOMER')")
|
||||
public String addProduct(@RequestParam("pid") Product product, @RequestParam("number") int number, @ModelAttribute("event") CustomCart cart) {
|
||||
cart.addOrUpdateItem(product, Quantity.of(number));
|
||||
|
||||
Quantity amount = Quantity.of(number);
|
||||
Quantity invAmount = inventory.findByProduct(product).get().getQuantity(); // TODO ERROR HANDLING
|
||||
Quantity cartQuantity = cart.getQuantity(product);
|
||||
|
||||
// check for possible miss-inputs
|
||||
if (amount.add(cartQuantity).isGreaterThan(invAmount)) {
|
||||
cart.addOrUpdateItem(product, cartQuantity.negate().add(invAmount));
|
||||
} else if (amount.add(cartQuantity).isLessThan(Quantity.of(0))) {
|
||||
cart.addOrUpdateItem(product, cartQuantity.negate());
|
||||
} else {
|
||||
cart.addOrUpdateItem(product, amount);
|
||||
}
|
||||
|
||||
return "redirect:/event";
|
||||
}
|
||||
|
||||
|
@ -122,7 +136,6 @@ public class OrderController {
|
|||
cart.clear();
|
||||
|
||||
List<CustomOrder> myOrders = orderManagement.findBy(account).stream().collect(Collectors.toList());
|
||||
System.out.println(myOrders);
|
||||
|
||||
return "redirect:/myOrders";
|
||||
}).orElse("redirect:/event");
|
||||
|
|
|
@ -33,14 +33,37 @@
|
|||
</tr>
|
||||
</table>
|
||||
|
||||
<h4>Product hinzufügen</h4>
|
||||
|
||||
<table class="table">
|
||||
<!-- TODO -->
|
||||
</table>
|
||||
<span th:text="'Gesamt: ' + ${totalPrice}">Price</span>
|
||||
|
||||
<form method="post" th:action="@{/event/checkout}">
|
||||
<button class="btn btn-primary" type="submit">Kostenpflichtig bestellen</button>
|
||||
</form>
|
||||
|
||||
<!-- I NEED SPACE -->
|
||||
<br>
|
||||
<br>
|
||||
|
||||
<h4>Produkt hinzufügen</h4>
|
||||
|
||||
<table class="table">
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Preis/Stück</th>
|
||||
<th>Verfügbar</th>
|
||||
<th>Menge</th>
|
||||
</tr>
|
||||
<tr th:each="item : ${invItems}">
|
||||
<td th:text="${item.getProduct().getName()}">Name</td>
|
||||
<td th:text="${item.getProduct().getPrice()}">Preis</td>
|
||||
<td th:text="${item.getQuantity()}">Verfügbar</td>
|
||||
<td>
|
||||
<form th:action="@{/event/addProduct}" method="post">
|
||||
<input id="number" type="number" name="number" th:min="${item.getQuantity().negate()}" th:max="${item.getQuantity()}" value="1"/>
|
||||
<input type="hidden" name="pid" th:value="${item.getProduct().getId()}"/>
|
||||
<input class="btn btn-primary" type="submit" th:value="Hinzufügen"/>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</html>
|
||||
|
|
Loading…
Reference in a new issue