mirror of
https://github.com/st-tu-dresden-praktikum/swt23w23
synced 2024-07-19 21:04:36 +02:00
Add order backend for kundenwunsch
This checks if the requested product to add is suitable for the event. This works on #100
This commit is contained in:
parent
5736b49080
commit
44c9eb8f3a
|
@ -173,6 +173,11 @@ 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) {
|
||||||
|
// check if product is suitable
|
||||||
|
if (product.getCategories().stream().noneMatch(c -> c.equals(cart.getOrderType().toString()))) {
|
||||||
|
return "redirect:/event";
|
||||||
|
}
|
||||||
|
|
||||||
Quantity amount = Quantity.of(number > 0 ? number : 1);
|
Quantity amount = Quantity.of(number > 0 ? number : 1);
|
||||||
Quantity cartQuantity = cart.getQuantity(product);
|
Quantity cartQuantity = cart.getQuantity(product);
|
||||||
Quantity available;
|
Quantity available;
|
||||||
|
|
Loading…
Reference in a new issue