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')")
|
@PreAuthorize("hasRole('CUSTOMER')")
|
||||||
public String event(Model model, @ModelAttribute("event") CustomCart cart) {
|
public String event(Model model, @ModelAttribute("event") CustomCart cart) {
|
||||||
model.addAttribute("items", cart.stream().collect(Collectors.toList()));
|
model.addAttribute("items", cart.stream().collect(Collectors.toList()));
|
||||||
|
model.addAttribute("totalPrice", cart.getPrice());
|
||||||
model.addAttribute("invItems", inventory.findAll().stream().collect(Collectors.toList()));
|
model.addAttribute("invItems", inventory.findAll().stream().collect(Collectors.toList()));
|
||||||
return "event";
|
return "event";
|
||||||
}
|
}
|
||||||
|
@ -108,7 +109,20 @@ public class OrderController {
|
||||||
@PostMapping("/event/addProduct")
|
@PostMapping("/event/addProduct")
|
||||||
@PreAuthorize("hasRole('CUSTOMER')")
|
@PreAuthorize("hasRole('CUSTOMER')")
|
||||||
public String addProduct(@RequestParam("pid") Product product, @RequestParam("number") int number, @ModelAttribute("event") CustomCart cart) {
|
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";
|
return "redirect:/event";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +136,6 @@ public class OrderController {
|
||||||
cart.clear();
|
cart.clear();
|
||||||
|
|
||||||
List<CustomOrder> myOrders = orderManagement.findBy(account).stream().collect(Collectors.toList());
|
List<CustomOrder> myOrders = orderManagement.findBy(account).stream().collect(Collectors.toList());
|
||||||
System.out.println(myOrders);
|
|
||||||
|
|
||||||
return "redirect:/myOrders";
|
return "redirect:/myOrders";
|
||||||
}).orElse("redirect:/event");
|
}).orElse("redirect:/event");
|
||||||
|
|
|
@ -33,14 +33,37 @@
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
<h4>Product hinzufügen</h4>
|
<span th:text="'Gesamt: ' + ${totalPrice}">Price</span>
|
||||||
|
|
||||||
<table class="table">
|
|
||||||
<!-- TODO -->
|
|
||||||
</table>
|
|
||||||
|
|
||||||
<form method="post" th:action="@{/event/checkout}">
|
<form method="post" th:action="@{/event/checkout}">
|
||||||
<button class="btn btn-primary" type="submit">Kostenpflichtig bestellen</button>
|
<button class="btn btn-primary" type="submit">Kostenpflichtig bestellen</button>
|
||||||
</form>
|
</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>
|
</div>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue