From 7c5c586c3958f84535781d94d0294c32fc8c0775 Mon Sep 17 00:00:00 2001 From: wooyounggggg Date: Sat, 26 Aug 2023 17:04:17 +0900 Subject: [PATCH 1/2] =?UTF-8?q?review:=20customer=20=EC=9D=BC=EB=B6=80=20?= =?UTF-8?q?=EB=B0=8F=20restaurant=20=EB=A6=AC=EB=B7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../msa/customer/entity/member/Customer.java | 5 +++ .../exception/DeliveryCustomerException.java | 13 ++++++++ .../exception/store/StoreEmptyException.java | 18 +++++++++++ .../interceptor/StoreCheckInterceptor.java | 11 ++++--- .../controller/StoreController.java | 31 +++++++++++-------- .../restaurant/entity/order/OrderStatus.java | 11 ++++++- .../DeliveryRestaurantException.java | 13 ++++++++ .../OrderStatusUpdateFailedException.java | 15 +++++++++ .../store/InvalidManagerException.java | 13 ++++++++ .../store/StoreCreationFailedException.java | 13 ++++++++ .../exception/store/StoreEmptyException.java | 18 +++++++++++ .../StoreManagerCheckInterceptor.java | 17 +++++----- .../service/order/OrderService.java | 24 +++++++++----- .../order/OrderStatusUpdatePolicy.java | 25 +++++++++++++++ 14 files changed, 194 insertions(+), 33 deletions(-) create mode 100644 customer/src/main/java/msa/customer/exception/DeliveryCustomerException.java create mode 100644 customer/src/main/java/msa/customer/exception/store/StoreEmptyException.java create mode 100644 restaurant/src/main/java/msa/restaurant/exception/DeliveryRestaurantException.java create mode 100644 restaurant/src/main/java/msa/restaurant/exception/order/OrderStatusUpdateFailedException.java create mode 100644 restaurant/src/main/java/msa/restaurant/exception/store/InvalidManagerException.java create mode 100644 restaurant/src/main/java/msa/restaurant/exception/store/StoreCreationFailedException.java create mode 100644 restaurant/src/main/java/msa/restaurant/exception/store/StoreEmptyException.java create mode 100644 restaurant/src/main/java/msa/restaurant/service/order/OrderStatusUpdatePolicy.java diff --git a/customer/src/main/java/msa/customer/entity/member/Customer.java b/customer/src/main/java/msa/customer/entity/member/Customer.java index fdcc5dd4..9ea9f0e9 100644 --- a/customer/src/main/java/msa/customer/entity/member/Customer.java +++ b/customer/src/main/java/msa/customer/entity/member/Customer.java @@ -23,6 +23,11 @@ public class Customer { private String phoneNumber; private String address; private String addressDetail; + /* + (R) Spring 내장 클래스인 Point를 사용하고 계신데, Location 클래스를 직접 만들어주시는 것이 어떨까 싶습니다. + delivery-application 내에서 location은 비중이 큰 역할을 할텐데, 이를 spring 내장 클래스로 처리하니 + 제약 사항이 많고 도메인에 맞는 기능을 제공하는 것이 어려워울 것 같습니다. + */ private Point location; } \ No newline at end of file diff --git a/customer/src/main/java/msa/customer/exception/DeliveryCustomerException.java b/customer/src/main/java/msa/customer/exception/DeliveryCustomerException.java new file mode 100644 index 00000000..114b9d0e --- /dev/null +++ b/customer/src/main/java/msa/customer/exception/DeliveryCustomerException.java @@ -0,0 +1,13 @@ +package msa.customer.exception; + +public class DeliveryCustomerException extends RuntimeException { + + public DeliveryCustomerException(String message) { + super(message); + } + + public DeliveryCustomerException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/customer/src/main/java/msa/customer/exception/store/StoreEmptyException.java b/customer/src/main/java/msa/customer/exception/store/StoreEmptyException.java new file mode 100644 index 00000000..6e081f4e --- /dev/null +++ b/customer/src/main/java/msa/customer/exception/store/StoreEmptyException.java @@ -0,0 +1,18 @@ +package msa.customer.exception.store; + +import msa.customer.entity.store.Store; +import msa.customer.exception.DeliveryCustomerException; + +public class StoreEmptyException extends DeliveryCustomerException { + + private static final String EMPTY_STORE_MESSAGE = "Store is empty. (storeId = %s)"; + + public StoreEmptyException(Store store) { + super(String.format(EMPTY_STORE_MESSAGE, store.getStoreId())); + } + + public StoreEmptyException(String storeId) { + super(String.format(EMPTY_STORE_MESSAGE, storeId)); + } + +} diff --git a/customer/src/main/java/msa/customer/interceptor/StoreCheckInterceptor.java b/customer/src/main/java/msa/customer/interceptor/StoreCheckInterceptor.java index c085d3b6..1350fc56 100644 --- a/customer/src/main/java/msa/customer/interceptor/StoreCheckInterceptor.java +++ b/customer/src/main/java/msa/customer/interceptor/StoreCheckInterceptor.java @@ -3,6 +3,7 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import msa.customer.entity.store.Store; +import msa.customer.exception.store.StoreEmptyException; import msa.customer.service.store.StoreService; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerMapping; @@ -11,6 +12,7 @@ import java.util.Optional; public class StoreCheckInterceptor implements HandlerInterceptor { + private final StoreService storeService; public StoreCheckInterceptor(StoreService storeService) { @@ -19,13 +21,14 @@ public StoreCheckInterceptor(StoreService storeService) { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - Map pathVariables = (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); - String storeId = (String) pathVariables.get("storeId"); + Map pathVariables = (Map)request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); + String storeId = (String)pathVariables.get("storeId"); Optional storeOptional = storeService.getStore(storeId); - if(storeOptional.isEmpty()){ - throw new NullPointerException("Store doesn't exist. " + storeId + " is not correct store id."); + if (storeOptional.isEmpty()) { + throw new StoreEmptyException(storeId); } request.setAttribute("storeEntity", storeOptional.get()); return true; } + } diff --git a/restaurant/src/main/java/msa/restaurant/controller/StoreController.java b/restaurant/src/main/java/msa/restaurant/controller/StoreController.java index 5264061d..2ecd5863 100644 --- a/restaurant/src/main/java/msa/restaurant/controller/StoreController.java +++ b/restaurant/src/main/java/msa/restaurant/controller/StoreController.java @@ -6,6 +6,7 @@ import msa.restaurant.dto.store.StoreResponseDto; import msa.restaurant.entity.store.Store; import msa.restaurant.dto.store.StoreSqsDto; +import msa.restaurant.exception.store.StoreCreationFailedException; import msa.restaurant.service.member.MemberService; import msa.restaurant.sqs.SendingMessageConverter; import msa.restaurant.service.store.StoreService; @@ -26,7 +27,10 @@ public class StoreController { private final SendingMessageConverter sendingMessageConverter; private final SqsService sqsService; - public StoreController(StoreService storeService, SendingMessageConverter sendingMessageConverter, MemberService memberService, SqsService sqsService) { + public StoreController(StoreService storeService, + SendingMessageConverter sendingMessageConverter, + MemberService memberService, + SqsService sqsService) { this.storeService = storeService; this.sendingMessageConverter = sendingMessageConverter; this.sqsService = sqsService; @@ -34,8 +38,8 @@ public StoreController(StoreService storeService, SendingMessageConverter sendin @GetMapping @ResponseStatus(HttpStatus.OK) - public List storeList ( - @RequestAttribute("cognitoUsername") String managerId) { + public List storeList( + @RequestAttribute("cognitoUsername") String managerId) { List storeList = storeService.getStoreList(managerId); List storeListDto = new ArrayList<>(); storeList.forEach(store -> { @@ -46,12 +50,12 @@ public List storeList ( @PostMapping @ResponseStatus(HttpStatus.CREATED) - public void createStore (@RequestAttribute("cognitoUsername") String managerId, - @RequestBody StoreRequestDto data) { + public void createStore(@RequestAttribute("cognitoUsername") String managerId, + @RequestBody StoreRequestDto data) { String storeId = storeService.createStore(data, managerId); Optional storeOptional = storeService.getStore(storeId); - if (storeOptional.isEmpty()){ - throw new RuntimeException("Store creation failed."); + if (storeOptional.isEmpty()) { + throw new StoreCreationFailedException(storeId); } Store store = storeOptional.get(); StoreSqsDto storeSqsDto = new StoreSqsDto(store); @@ -62,8 +66,8 @@ public void createStore (@RequestAttribute("cognitoUsername") String managerId, @GetMapping("/{storeId}") @ResponseStatus(HttpStatus.OK) - public StoreResponseDto storeInfo (@RequestAttribute("cognitoUsername") String managerId, - @RequestAttribute("store") Store store) { + public StoreResponseDto storeInfo(@RequestAttribute("cognitoUsername") String managerId, + @RequestAttribute("store") Store store) { return new StoreResponseDto(store); } @@ -71,7 +75,7 @@ public StoreResponseDto storeInfo (@RequestAttribute("cognitoUsername") String m @ResponseStatus(HttpStatus.OK) public void updateStore(@RequestAttribute("cognitoUsername") String managerId, @PathVariable String storeId, - @RequestBody StoreRequestDto data) { + @RequestBody StoreRequestDto data) { storeService.updateStore(storeId, data); Optional storeOptional = storeService.getStore(storeId); Store store = storeOptional.get(); @@ -85,9 +89,9 @@ public void updateStore(@RequestAttribute("cognitoUsername") String managerId, @ResponseStatus(HttpStatus.CREATED) public void changeStoreStatus(@RequestAttribute("cognitoUsername") String managerId, @PathVariable String storeId, - @RequestBody boolean open){ + @RequestBody boolean open) { String messageToChangeStatus; - if (open){ + if (open) { storeService.openStore(storeId); messageToChangeStatus = sendingMessageConverter.createMessageToOpenStore(storeId); } else { @@ -101,11 +105,12 @@ public void changeStoreStatus(@RequestAttribute("cognitoUsername") String manage @DeleteMapping("/{storeId}") @ResponseStatus(HttpStatus.NO_CONTENT) public void deleteStore(@RequestAttribute("cognitoUsername") String managerId, - @PathVariable String storeId) { + @PathVariable String storeId) { storeService.deleteStore(storeId); String messageToDeleteStore = sendingMessageConverter.createMessageToDeleteStore(storeId); sqsService.sendToCustomer(messageToDeleteStore); sqsService.sendToRider(messageToDeleteStore); } + } diff --git a/restaurant/src/main/java/msa/restaurant/entity/order/OrderStatus.java b/restaurant/src/main/java/msa/restaurant/entity/order/OrderStatus.java index 9ec298f8..0348a078 100644 --- a/restaurant/src/main/java/msa/restaurant/entity/order/OrderStatus.java +++ b/restaurant/src/main/java/msa/restaurant/entity/order/OrderStatus.java @@ -1,5 +1,14 @@ package msa.restaurant.entity.order; public enum OrderStatus { - ORDER_REQUEST, ORDER_ACCEPT, ORDER_DENY, RIDER_ASSIGNED, FOOD_READY, DELIVERY_IN_PROGRESS, DELIVERY_COMPLETE, ORDER_CANCELED + + ORDER_REQUEST, + ORDER_ACCEPT, + ORDER_DENY, + RIDER_ASSIGNED, + FOOD_READY, + DELIVERY_IN_PROGRESS, + DELIVERY_COMPLETE, + ORDER_CANCELED + } diff --git a/restaurant/src/main/java/msa/restaurant/exception/DeliveryRestaurantException.java b/restaurant/src/main/java/msa/restaurant/exception/DeliveryRestaurantException.java new file mode 100644 index 00000000..03ca5d64 --- /dev/null +++ b/restaurant/src/main/java/msa/restaurant/exception/DeliveryRestaurantException.java @@ -0,0 +1,13 @@ +package msa.restaurant.exception; + +public class DeliveryRestaurantException extends RuntimeException { + + public DeliveryRestaurantException(String message) { + super(message); + } + + public DeliveryRestaurantException(String message, Throwable cause) { + super(message, cause); + } + +} diff --git a/restaurant/src/main/java/msa/restaurant/exception/order/OrderStatusUpdateFailedException.java b/restaurant/src/main/java/msa/restaurant/exception/order/OrderStatusUpdateFailedException.java new file mode 100644 index 00000000..8a5ba231 --- /dev/null +++ b/restaurant/src/main/java/msa/restaurant/exception/order/OrderStatusUpdateFailedException.java @@ -0,0 +1,15 @@ +package msa.restaurant.exception.order; + +import msa.restaurant.entity.order.OrderStatus; +import msa.restaurant.exception.DeliveryRestaurantException; +import msa.restaurant.service.order.OrderStatusUpdatePolicy; + +public class OrderStatusUpdateFailedException extends DeliveryRestaurantException { + + private static final String UPDATE_FAILED_MESSAGE = "Updating order status to %s failed. (OrderStatusUpdatePolicy = %s)"; + + public OrderStatusUpdateFailedException(OrderStatus status, OrderStatusUpdatePolicy policy) { + super(String.format(UPDATE_FAILED_MESSAGE, status, policy)); + } + +} diff --git a/restaurant/src/main/java/msa/restaurant/exception/store/InvalidManagerException.java b/restaurant/src/main/java/msa/restaurant/exception/store/InvalidManagerException.java new file mode 100644 index 00000000..ac82dfc5 --- /dev/null +++ b/restaurant/src/main/java/msa/restaurant/exception/store/InvalidManagerException.java @@ -0,0 +1,13 @@ +package msa.restaurant.exception.store; + +import msa.restaurant.exception.DeliveryRestaurantException; + +public class InvalidManagerException extends DeliveryRestaurantException { + + private static final String INVALID_MANAGER_MESSAGE = "This store doesn't belong to this manager. (managerId = %s)"; + + public InvalidManagerException(String managerId) { + super(String.format(INVALID_MANAGER_MESSAGE, managerId)); + } + +} diff --git a/restaurant/src/main/java/msa/restaurant/exception/store/StoreCreationFailedException.java b/restaurant/src/main/java/msa/restaurant/exception/store/StoreCreationFailedException.java new file mode 100644 index 00000000..1061bff9 --- /dev/null +++ b/restaurant/src/main/java/msa/restaurant/exception/store/StoreCreationFailedException.java @@ -0,0 +1,13 @@ +package msa.restaurant.exception.store; + +import msa.restaurant.exception.DeliveryRestaurantException; + +public class StoreCreationFailedException extends DeliveryRestaurantException { + + private static final String CREATION_FAILED_MESSAGE = "Store creation failed. (storeId = %s)"; + + public StoreCreationFailedException(String storeId) { + super(String.format(CREATION_FAILED_MESSAGE, storeId)); + } + +} \ No newline at end of file diff --git a/restaurant/src/main/java/msa/restaurant/exception/store/StoreEmptyException.java b/restaurant/src/main/java/msa/restaurant/exception/store/StoreEmptyException.java new file mode 100644 index 00000000..ad14733f --- /dev/null +++ b/restaurant/src/main/java/msa/restaurant/exception/store/StoreEmptyException.java @@ -0,0 +1,18 @@ +package msa.restaurant.exception.store; + +import msa.restaurant.entity.store.Store; +import msa.restaurant.exception.DeliveryRestaurantException; + +public class StoreEmptyException extends DeliveryRestaurantException { + + private static final String EMPTY_STORE_MESSAGE = "Store is empty. (storeId = %s)"; + + public StoreEmptyException(Store store) { + super(String.format(EMPTY_STORE_MESSAGE, store.getStoreId())); + } + + public StoreEmptyException(String storeId) { + super(String.format(EMPTY_STORE_MESSAGE, storeId)); + } + +} diff --git a/restaurant/src/main/java/msa/restaurant/interceptor/StoreManagerCheckInterceptor.java b/restaurant/src/main/java/msa/restaurant/interceptor/StoreManagerCheckInterceptor.java index 8ea87234..a37c4498 100644 --- a/restaurant/src/main/java/msa/restaurant/interceptor/StoreManagerCheckInterceptor.java +++ b/restaurant/src/main/java/msa/restaurant/interceptor/StoreManagerCheckInterceptor.java @@ -3,6 +3,8 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import msa.restaurant.entity.store.Store; +import msa.restaurant.exception.store.InvalidManagerException; +import msa.restaurant.exception.store.StoreEmptyException; import msa.restaurant.service.store.StoreService; import org.springframework.web.servlet.HandlerInterceptor; import org.springframework.web.servlet.HandlerMapping; @@ -20,18 +22,19 @@ public StoreManagerCheckInterceptor(StoreService storeService) { @Override public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { - String managerId = (String) request.getAttribute("cognitoUsername"); - Map pathVariables = (Map) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); - String storeId = (String) pathVariables.get("storeId"); + String managerId = (String)request.getAttribute("cognitoUsername"); + Map pathVariables = (Map)request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); + String storeId = (String)pathVariables.get("storeId"); Optional storeOptional = storeService.getStore(storeId); - if (storeOptional.isEmpty()){ - throw new NullPointerException("Store doesn't exist. " + storeId + " is not correct store id."); + if (storeOptional.isEmpty()) { + throw new StoreEmptyException(storeId); } Store store = storeOptional.get(); - if (!store.getManagerId().equals(managerId)){ - throw new RuntimeException("This store doesn't belong to this manager."); + if (!store.getManagerId().equals(managerId)) { + throw new InvalidManagerException(managerId); } request.setAttribute("store", store); return true; } + } diff --git a/restaurant/src/main/java/msa/restaurant/service/order/OrderService.java b/restaurant/src/main/java/msa/restaurant/service/order/OrderService.java index c84e3726..a4435f09 100644 --- a/restaurant/src/main/java/msa/restaurant/service/order/OrderService.java +++ b/restaurant/src/main/java/msa/restaurant/service/order/OrderService.java @@ -18,27 +18,34 @@ public OrderService(OrderRepository orderRepository) { this.orderRepository = orderRepository; } - public void createOrder(Order order){ + public void createOrder(Order order) { orderRepository.createOrder(order); } - public List getOrderList(String storeId){ + public List getOrderList(String storeId) { return orderRepository.readOrderList(storeId); } - public Optional getOrder(String orderId){ + public Optional getOrder(String orderId) { return orderRepository.readOrder(orderId); } - public OrderStatus changeOrderStatusToOrderAccept(String orderId, OrderStatus orderStatus){ - if(orderStatus.equals(OrderStatus.ORDER_REQUEST)){ + public OrderStatus changeOrderStatus(Order order, OrderStatus status, OrderStatusUpdatePolicy orderStatusUpdatePolicy) { + orderStatusUpdatePolicy.checkStatusUpdatable(status); + + return orderRepository.updateOrderStatus(order.getOrderId(), status); + + } + + public OrderStatus changeOrderStatusToOrderAccept(String orderId, OrderStatus orderStatus) { + if (orderStatus.equals(OrderStatus.ORDER_REQUEST)) { return orderRepository.updateOrderStatus(orderId, OrderStatus.ORDER_ACCEPT); } else { throw new IllegalStateException("The current order status is not changeable"); } } - public OrderStatus changeOrderStatusToFoodReady(String orderId, OrderStatus orderStatus){ + public OrderStatus changeOrderStatusToFoodReady(String orderId, OrderStatus orderStatus) { if (orderStatus.equals(OrderStatus.RIDER_ASSIGNED)) { return orderRepository.updateOrderStatus(orderId, OrderStatus.FOOD_READY); } else { @@ -46,11 +53,12 @@ public OrderStatus changeOrderStatusToFoodReady(String orderId, OrderStatus orde } } - public void assignRiderToOrder(String orderId, OrderStatus orderStatus, RiderPartDto riderPartDto){ + public void assignRiderToOrder(String orderId, OrderStatus orderStatus, RiderPartDto riderPartDto) { orderRepository.updateRiderInfo(orderId, orderStatus, riderPartDto); } - public void changeOrderStatusFromOtherServer(String orderId, OrderStatus orderStatus){ + public void changeOrderStatusFromOtherServer(String orderId, OrderStatus orderStatus) { orderRepository.updateOrderStatus(orderId, orderStatus); } + } diff --git a/restaurant/src/main/java/msa/restaurant/service/order/OrderStatusUpdatePolicy.java b/restaurant/src/main/java/msa/restaurant/service/order/OrderStatusUpdatePolicy.java new file mode 100644 index 00000000..9db45edb --- /dev/null +++ b/restaurant/src/main/java/msa/restaurant/service/order/OrderStatusUpdatePolicy.java @@ -0,0 +1,25 @@ +package msa.restaurant.service.order; + +import lombok.RequiredArgsConstructor; +import msa.restaurant.entity.order.OrderStatus; +import msa.restaurant.exception.order.OrderStatusUpdateFailedException; + +import java.util.Set; + +@RequiredArgsConstructor +public enum OrderStatusUpdatePolicy { + + ACCEPT_ORDER_POLICY(Set.of(OrderStatus.ORDER_ACCEPT)), + FOOD_READY_POLICY(Set.of(OrderStatus.FOOD_READY)); + + private final Set possibleStatuses; + + public void checkStatusUpdatable(OrderStatus nextStatus) { + final var isUpdatable = this.possibleStatuses.contains(nextStatus); + + if (!isUpdatable) { + throw new OrderStatusUpdateFailedException(nextStatus, this); + } + } + +} From 3ff39758d0a765976248023a5f5dfc3e96730ea4 Mon Sep 17 00:00:00 2001 From: wooyounggggg Date: Sun, 27 Aug 2023 11:43:49 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20change=20order=20status=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OrderController.java | 22 +++++++++++++------ .../service/order/OrderService.java | 17 -------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/restaurant/src/main/java/msa/restaurant/controller/OrderController.java b/restaurant/src/main/java/msa/restaurant/controller/OrderController.java index f746e987..c8f0a22b 100644 --- a/restaurant/src/main/java/msa/restaurant/controller/OrderController.java +++ b/restaurant/src/main/java/msa/restaurant/controller/OrderController.java @@ -2,6 +2,7 @@ import msa.restaurant.entity.order.Order; import msa.restaurant.entity.order.OrderStatus; +import msa.restaurant.service.order.OrderStatusUpdatePolicy; import msa.restaurant.sqs.SendingMessageConverter; import msa.restaurant.sqs.SqsService; import msa.restaurant.service.order.OrderService; @@ -22,7 +23,10 @@ public class OrderController { private final SqsService sqsService; @Autowired - public OrderController(OrderService orderService, SseService sseService, SendingMessageConverter sendingMessageConverter, SqsService sqsService) { + public OrderController(OrderService orderService, + SseService sseService, + SendingMessageConverter sendingMessageConverter, + SqsService sqsService) { this.orderService = orderService; this.sseService = sseService; this.sendingMessageConverter = sendingMessageConverter; @@ -31,17 +35,17 @@ public OrderController(OrderService orderService, SseService sseService, Sending @GetMapping(produces = MediaType.TEXT_EVENT_STREAM_VALUE) @ResponseStatus(HttpStatus.OK) - public SseEmitter showOrderList(@PathVariable String storeId){ + public SseEmitter showOrderList(@PathVariable String storeId) { SseEmitter sseEmitter = sseService.connectForList(storeId); sseService.showOrderList(storeId); return sseEmitter; } - @GetMapping(path="/{orderId}", produces = MediaType.TEXT_EVENT_STREAM_VALUE) + @GetMapping(path = "/{orderId}", produces = MediaType.TEXT_EVENT_STREAM_VALUE) @ResponseStatus(HttpStatus.OK) public SseEmitter showOrderInfo(@PathVariable String storeId, @PathVariable String orderId, - @RequestAttribute("order") Order order){ + @RequestAttribute("order") Order order) { SseEmitter sseEmitter = sseService.connectForInfo(storeId); sseService.showOrderInfo(storeId, orderId); return sseEmitter; @@ -51,7 +55,9 @@ public SseEmitter showOrderInfo(@PathVariable String storeId, @ResponseStatus(HttpStatus.OK) public void acceptOrder(@PathVariable String orderId, @RequestAttribute("order") Order order) { - OrderStatus changedOrderStatus = orderService.changeOrderStatusToOrderAccept(orderId, order.getOrderStatus()); + OrderStatus changedOrderStatus = orderService.changeOrderStatus(order, + OrderStatus.ORDER_ACCEPT, + OrderStatusUpdatePolicy.ACCEPT_ORDER_POLICY); order.setOrderStatus(changedOrderStatus); String messageToAcceptOrder = sendingMessageConverter.createMessageToAcceptOrder(order); String messageToRequestOrder = sendingMessageConverter.createMessageToRequestOrder(order); @@ -62,8 +68,10 @@ public void acceptOrder(@PathVariable String orderId, @PutMapping("/{orderId}") @ResponseStatus(HttpStatus.OK) public void changeOrderStatus(@PathVariable String orderId, - @RequestAttribute("order") Order order){ - OrderStatus changedOrderStatus = orderService.changeOrderStatusToFoodReady(orderId, order.getOrderStatus()); + @RequestAttribute("order") Order order) { + OrderStatus changedOrderStatus = orderService.changeOrderStatus(order, + OrderStatus.FOOD_READY, + OrderStatusUpdatePolicy.FOOD_READY_POLICY); order.setOrderStatus(changedOrderStatus); String messageToChangeOrderStatus = sendingMessageConverter.createMessageToChangeOrderStatus(order); sqsService.sendToCustomer(messageToChangeOrderStatus); diff --git a/restaurant/src/main/java/msa/restaurant/service/order/OrderService.java b/restaurant/src/main/java/msa/restaurant/service/order/OrderService.java index a4435f09..56833834 100644 --- a/restaurant/src/main/java/msa/restaurant/service/order/OrderService.java +++ b/restaurant/src/main/java/msa/restaurant/service/order/OrderService.java @@ -34,23 +34,6 @@ public OrderStatus changeOrderStatus(Order order, OrderStatus status, OrderStatu orderStatusUpdatePolicy.checkStatusUpdatable(status); return orderRepository.updateOrderStatus(order.getOrderId(), status); - - } - - public OrderStatus changeOrderStatusToOrderAccept(String orderId, OrderStatus orderStatus) { - if (orderStatus.equals(OrderStatus.ORDER_REQUEST)) { - return orderRepository.updateOrderStatus(orderId, OrderStatus.ORDER_ACCEPT); - } else { - throw new IllegalStateException("The current order status is not changeable"); - } - } - - public OrderStatus changeOrderStatusToFoodReady(String orderId, OrderStatus orderStatus) { - if (orderStatus.equals(OrderStatus.RIDER_ASSIGNED)) { - return orderRepository.updateOrderStatus(orderId, OrderStatus.FOOD_READY); - } else { - throw new IllegalStateException("The current order status is not changeable"); - } } public void assignRiderToOrder(String orderId, OrderStatus orderStatus, RiderPartDto riderPartDto) {