From 43785cde3d3a3ae6d0c4658701261ec3e75176e9 Mon Sep 17 00:00:00 2001 From: Mathis Kral Date: Sun, 19 Nov 2023 13:37:08 +0100 Subject: [PATCH] fixup! Update basics of order package to salespoint --- .../java/catering/order/OrderController.java | 16 ++++++++++------ src/main/resources/templates/orders.html | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/catering/order/OrderController.java b/src/main/java/catering/order/OrderController.java index 28f7106..d294d95 100644 --- a/src/main/java/catering/order/OrderController.java +++ b/src/main/java/catering/order/OrderController.java @@ -8,6 +8,7 @@ import org.salespointframework.order.Order; import org.salespointframework.order.OrderManagement; import org.salespointframework.quantity.Quantity; import org.salespointframework.time.Interval; +import org.salespointframework.useraccount.Role; import org.salespointframework.useraccount.UserAccount; import org.salespointframework.useraccount.web.LoggedIn; import org.springframework.data.domain.Pageable; @@ -92,11 +93,15 @@ public class OrderController { } @PostMapping("/allOrders/remove") - @PreAuthorize("hasRole('BOSS')") - public String removeOrder(@RequestParam Order.OrderIdentifier orderID) { - CustomOrder myOrder = orderManagement.get(orderID).get(); // TODO - orderManagement.cancelOrder(myOrder, "I have my own reasons."); - return "redirect:/allOrders"; + public String removeOrder(@RequestParam Order.OrderIdentifier orderID, @LoggedIn Optional userAccount) { + return userAccount.map(account -> { + if (account.hasRole(Role.of("ADMIN"))) { + CustomOrder myOrder = orderManagement.get(orderID).get(); // FIXME + orderManagement.cancelOrder(myOrder, "I have my own reasons."); + return "redirect:/allOrders"; + } + return "redirect:/"; + }).orElse("redirect:/"); } @@ -114,7 +119,6 @@ public class OrderController { return userAccount.map(account -> { CustomOrder myOrder = new CustomOrder(account.getId(), cart); orderManagement.payOrder(myOrder); // TODO: change this later - orderManagement.completeOrder(myOrder); // TODO: change this later cart.clear(); List myOrders = orderManagement.findBy(account).stream().collect(Collectors.toList()); diff --git a/src/main/resources/templates/orders.html b/src/main/resources/templates/orders.html index a1d29bc..1116d70 100644 --- a/src/main/resources/templates/orders.html +++ b/src/main/resources/templates/orders.html @@ -13,7 +13,7 @@ Kunde Produktdetails Rechnung - Bezahlt + Status Preis @@ -37,7 +37,7 @@ Keine Rechnung verfügbar - ☒ +