Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package msa.customer.exception;

public class DeliveryCustomerException extends RuntimeException {
Comment thread
millwheel marked this conversation as resolved.

public DeliveryCustomerException(String message) {
super(message);
}

public DeliveryCustomerException(String message, Throwable cause) {
super(message, cause);
}

}
Original file line number Diff line number Diff line change
@@ -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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -11,6 +12,7 @@
import java.util.Optional;

public class StoreCheckInterceptor implements HandlerInterceptor {

private final StoreService storeService;

public StoreCheckInterceptor(StoreService storeService) {
Expand All @@ -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<Store> 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);
Comment thread
millwheel marked this conversation as resolved.
}
request.setAttribute("storeEntity", storeOptional.get());
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,16 +27,19 @@ 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;
}

@GetMapping
@ResponseStatus(HttpStatus.OK)
public List<StorePartResponseDto> storeList (
@RequestAttribute("cognitoUsername") String managerId) {
public List<StorePartResponseDto> storeList(
@RequestAttribute("cognitoUsername") String managerId) {
List<Store> storeList = storeService.getStoreList(managerId);
List<StorePartResponseDto> storeListDto = new ArrayList<>();
storeList.forEach(store -> {
Expand All @@ -46,12 +50,12 @@ public List<StorePartResponseDto> 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<Store> storeOptional = storeService.getStore(storeId);
if (storeOptional.isEmpty()){
throw new RuntimeException("Store creation failed.");
if (storeOptional.isEmpty()) {
throw new StoreCreationFailedException(storeId);
Comment thread
millwheel marked this conversation as resolved.
}
Store store = storeOptional.get();
StoreSqsDto storeSqsDto = new StoreSqsDto(store);
Expand All @@ -62,16 +66,16 @@ 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);
}

@PutMapping("/{storeId}")
@ResponseStatus(HttpStatus.OK)
public void updateStore(@RequestAttribute("cognitoUsername") String managerId,
@PathVariable String storeId,
@RequestBody StoreRequestDto data) {
@RequestBody StoreRequestDto data) {
storeService.updateStore(storeId, data);
Optional<Store> storeOptional = storeService.getStore(storeId);
Store store = storeOptional.get();
Expand All @@ -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 {
Expand All @@ -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);
}

}

Original file line number Diff line number Diff line change
@@ -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

}
Original file line number Diff line number Diff line change
@@ -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);
}

}
Original file line number Diff line number Diff line change
@@ -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));
}

}
Original file line number Diff line number Diff line change
@@ -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));
}

}
Original file line number Diff line number Diff line change
@@ -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));
}

}
Original file line number Diff line number Diff line change
@@ -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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<Store> 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;
}

}
Loading