From 54ffdbb3531275cbfffbccb620574ee47e0352bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8E=E1=85=A1=E1=86=AB=E1=84=8C?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 22 May 2023 15:37:11 +0900 Subject: [PATCH 1/4] feat : order refuse --- .../controller/OrderAdminController.java | 10 ++++++- .../api/order/service/RefuseOrderUseCase.java | 26 +++++++++++++++++++ .../domain/domains/order/domain/Order.java | 8 ++++++ .../order/service/WithdrawOrderService.java | 7 +++++ 4 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 DuDoong-Api/src/main/java/band/gosrock/api/order/service/RefuseOrderUseCase.java diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/order/controller/OrderAdminController.java b/DuDoong-Api/src/main/java/band/gosrock/api/order/controller/OrderAdminController.java index 5aa59054..5933d174 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/order/controller/OrderAdminController.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/order/controller/OrderAdminController.java @@ -52,7 +52,7 @@ public OrderResponse cancelOrder( return cancelOrderUseCase.execute(eventId, orderUuid); } - @Operation(summary = "주문 승인하기 . 호스트 관리자가 티켓 주문을 승인합니다. ( 어드민 이벤트쪽으로 이동예정 )") + @Operation(summary = "주문 승인하기 . 호스트 관리자가 티켓 주문을 승인합니다.") @ApiErrorExceptionsExample(ApproveOrderExceptionDocs.class) @PostMapping("/{order_uuid}/approve") public OrderResponse confirmOrder( @@ -60,6 +60,14 @@ public OrderResponse confirmOrder( return approveOrderUseCase.execute(eventId, orderUuid); } + @Operation(summary = "승인 주문 거절하기 . 호스트 관리자가 승인 대기중인 주문을 거절합니다.") + @PostMapping("/{order_uuid}/refuse") + public OrderResponse refuseOrder( + @PathVariable Long eventId, @PathVariable("order_uuid") String orderUuid) { + return approveOrderUseCase.execute(eventId, orderUuid); + } + + @Operation(summary = "주문관리 리스트 페이지에서 주문 상세정보 조회할때") @GetMapping("/{order_uuid}") public OrderResponse getEventOrderDetail( diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/order/service/RefuseOrderUseCase.java b/DuDoong-Api/src/main/java/band/gosrock/api/order/service/RefuseOrderUseCase.java new file mode 100644 index 00000000..ffede5e4 --- /dev/null +++ b/DuDoong-Api/src/main/java/band/gosrock/api/order/service/RefuseOrderUseCase.java @@ -0,0 +1,26 @@ +package band.gosrock.api.order.service; + +import static band.gosrock.api.common.aop.hostRole.FindHostFrom.EVENT_ID; +import static band.gosrock.api.common.aop.hostRole.HostQualification.MANAGER; + +import band.gosrock.api.common.aop.hostRole.HostRolesAllowed; +import band.gosrock.api.order.model.dto.response.OrderResponse; +import band.gosrock.api.order.model.mapper.OrderMapper; +import band.gosrock.common.annotation.UseCase; +import band.gosrock.domain.domains.order.service.WithdrawOrderService; +import lombok.RequiredArgsConstructor; + +@UseCase +@RequiredArgsConstructor +public class RefuseOrderUseCase { + + private final WithdrawOrderService withdrawOrderService; + + private final OrderMapper orderMapper; + + @HostRolesAllowed(role = MANAGER, findHostFrom = EVENT_ID, applyTransaction = false) + public OrderResponse execute(Long eventId, String orderUuid) { + withdrawOrderService.refuseOrder(orderUuid); + return orderMapper.toOrderResponse(orderUuid); + } +} diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/Order.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/Order.java index 3604e3c0..967b8bb7 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/Order.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/Order.java @@ -239,6 +239,14 @@ public void cancel(OrderValidator orderValidator) { Events.raise(WithDrawOrderEvent.from(this)); } + /** 관리자가 주문을 취소 시킵니다 */ + public void refuse(OrderValidator orderValidator) { + orderValidator.validCanCancel(this); + this.orderStatus = OrderStatus.CANCELED; + this.withDrawAt = LocalDateTime.now(); + Events.raise(WithDrawOrderEvent.from(this)); + } + /** 사용자가 주문을 환불 시킵니다. */ public void refund(Long currentUserId, OrderValidator orderValidator) { orderValidator.validOwner(this, currentUserId); diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/service/WithdrawOrderService.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/service/WithdrawOrderService.java index c7aac782..44994cd8 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/service/WithdrawOrderService.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/service/WithdrawOrderService.java @@ -33,4 +33,11 @@ public String refundOrder(String orderUuid, Long userId) { order.refund(userId, orderValidator); return orderUuid; } + + @RedissonLock(LockName = "주문", identifier = "orderUuid") + public String refuseOrder(String orderUuid) { + Order order = orderAdaptor.findByOrderUuid(orderUuid); + order.refuse(orderValidator); + return orderUuid; + } } From f47d6d436e3cbb0175e762b9bde1a59b9a7dd193 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8E=E1=85=A1=E1=86=AB=E1=84=8C?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 22 May 2023 15:42:44 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat=20:=20refuse=20=EB=A9=94=EC=84=9C?= =?UTF-8?q?=EB=93=9C=20=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/domains/order/domain/Order.java | 4 ++-- .../domain/validator/OrderValidator.java | 20 +++++++++++++++++++ .../exception/CanNotRefuseOrderException.java | 13 ++++++++++++ .../order/exception/OrderErrorCode.java | 3 ++- 4 files changed, 37 insertions(+), 3 deletions(-) create mode 100644 DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/exception/CanNotRefuseOrderException.java diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/Order.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/Order.java index 967b8bb7..dfa6e18a 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/Order.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/Order.java @@ -239,9 +239,9 @@ public void cancel(OrderValidator orderValidator) { Events.raise(WithDrawOrderEvent.from(this)); } - /** 관리자가 주문을 취소 시킵니다 */ + /** 관리자가 승인 대기 중인 주문을 거절합니다. */ public void refuse(OrderValidator orderValidator) { - orderValidator.validCanCancel(this); + orderValidator.validCanRefuse(this); this.orderStatus = OrderStatus.CANCELED; this.withDrawAt = LocalDateTime.now(); Events.raise(WithDrawOrderEvent.from(this)); diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/validator/OrderValidator.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/validator/OrderValidator.java index 3bb54f8e..9d6d75e1 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/validator/OrderValidator.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/validator/OrderValidator.java @@ -121,6 +121,15 @@ public void validCanCancel(Order order) { validCanWithDraw(order); } + /** 거절할 수 있는 승인 대기중인 주문인지 검증합니다. */ + public void validCanRefuse(Order order) { + validAvailableRefundDate(order); + validStatusCanRefuse(getOrderStatus(order)); + validCanWithDraw(order); + } + + + /** 환불 할 수 있는 주문인지 검증합니다. */ public void validCanRefund(Order order) { validAvailableRefundDate(order); @@ -280,6 +289,11 @@ public Boolean isStatusCanWithDraw(OrderStatus orderStatus) { || Objects.equals(orderStatus, OrderStatus.APPROVED); } + /** 주문상태가 철회가능한 상태인지를 반환합니다. */ + public Boolean isStatusCanRefuse(OrderStatus orderStatus) { + return Objects.equals(orderStatus, OrderStatus.PENDING_APPROVE); + } + /** 주문 상태가 취소가능한 상태인지 검증합니다. */ public void validStatusCanCancel(OrderStatus orderStatus) { if (!isStatusCanWithDraw(orderStatus)) { @@ -293,6 +307,12 @@ public void validStatusCanRefund(OrderStatus orderStatus) { throw CanNotRefundOrderException.EXCEPTION; } } + /** 주문 상태가 관리자 취소가능한 상태인지 검증합니다. */ + public void validStatusCanRefuse(OrderStatus orderStatus) { + if (!isStatusCanRefuse(orderStatus)) { + throw CanNotCancelOrderException.EXCEPTION; + } + } /** 주문 상태가 결제방식의 승인 가능한 상태인지 검증합니다. */ public void validStatusCanPaymentConfirm(OrderStatus orderStatus) { diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/exception/CanNotRefuseOrderException.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/exception/CanNotRefuseOrderException.java new file mode 100644 index 00000000..2c1cd43e --- /dev/null +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/exception/CanNotRefuseOrderException.java @@ -0,0 +1,13 @@ +package band.gosrock.domain.domains.order.exception; + + +import band.gosrock.common.exception.DuDoongCodeException; + +public class CanNotRefuseOrderException extends DuDoongCodeException { + + public static final DuDoongCodeException EXCEPTION = new CanNotRefuseOrderException(); + + private CanNotRefuseOrderException() { + super(OrderErrorCode.ORDER_CANNOT_REFUSE); + } +} diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/exception/OrderErrorCode.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/exception/OrderErrorCode.java index e0cff47d..6880d9cc 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/exception/OrderErrorCode.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/exception/OrderErrorCode.java @@ -39,7 +39,8 @@ public enum OrderErrorCode implements BaseErrorCode { APPROVE_WAITING_PURCHASE_LIMIT( BAD_REQUEST, "Order_400_15", - "승인 대기중인 주문으로 인해 티켓 최대 구매 가능 횟수를 넘겼습니다." + "이미 신청한 주문이 승인 될 때까지 기다려주세요."); + "승인 대기중인 주문으로 인해 티켓 최대 구매 가능 횟수를 넘겼습니다." + "이미 신청한 주문이 승인 될 때까지 기다려주세요."), + ORDER_CANNOT_REFUSE(BAD_REQUEST, "Order_400_16", "승인 대기중인 주문을 거절할 수 없는 상태입니다."); private Integer status; private String code; From 68483d9621f0dcb8ed22aaac3b2a232e18abf95b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8E=E1=85=A1=E1=86=AB=E1=84=8C?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 22 May 2023 15:43:02 +0900 Subject: [PATCH 3/4] style : spotlesS --- .../gosrock/api/order/controller/OrderAdminController.java | 3 +-- .../domain/domains/order/domain/validator/OrderValidator.java | 2 -- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/order/controller/OrderAdminController.java b/DuDoong-Api/src/main/java/band/gosrock/api/order/controller/OrderAdminController.java index 5933d174..2320a100 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/order/controller/OrderAdminController.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/order/controller/OrderAdminController.java @@ -63,11 +63,10 @@ public OrderResponse confirmOrder( @Operation(summary = "승인 주문 거절하기 . 호스트 관리자가 승인 대기중인 주문을 거절합니다.") @PostMapping("/{order_uuid}/refuse") public OrderResponse refuseOrder( - @PathVariable Long eventId, @PathVariable("order_uuid") String orderUuid) { + @PathVariable Long eventId, @PathVariable("order_uuid") String orderUuid) { return approveOrderUseCase.execute(eventId, orderUuid); } - @Operation(summary = "주문관리 리스트 페이지에서 주문 상세정보 조회할때") @GetMapping("/{order_uuid}") public OrderResponse getEventOrderDetail( diff --git a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/validator/OrderValidator.java b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/validator/OrderValidator.java index 9d6d75e1..25b62c37 100644 --- a/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/validator/OrderValidator.java +++ b/DuDoong-Domain/src/main/java/band/gosrock/domain/domains/order/domain/validator/OrderValidator.java @@ -128,8 +128,6 @@ public void validCanRefuse(Order order) { validCanWithDraw(order); } - - /** 환불 할 수 있는 주문인지 검증합니다. */ public void validCanRefund(Order order) { validAvailableRefundDate(order); From e10b740cbb48a0a2d03da5b584da3709ae168373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8E=E1=85=A1=E1=86=AB=E1=84=8C?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 22 May 2023 15:52:08 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix=20:=20=EC=A3=BC=EB=AC=B8=20=EA=B1=B0?= =?UTF-8?q?=EC=A0=88=20=EA=B8=B0=EB=8A=A5=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=EC=97=90=EC=84=9C=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gosrock/api/order/controller/OrderAdminController.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/DuDoong-Api/src/main/java/band/gosrock/api/order/controller/OrderAdminController.java b/DuDoong-Api/src/main/java/band/gosrock/api/order/controller/OrderAdminController.java index 2320a100..d083df50 100644 --- a/DuDoong-Api/src/main/java/band/gosrock/api/order/controller/OrderAdminController.java +++ b/DuDoong-Api/src/main/java/band/gosrock/api/order/controller/OrderAdminController.java @@ -10,6 +10,7 @@ import band.gosrock.api.order.service.ApproveOrderUseCase; import band.gosrock.api.order.service.CancelOrderUseCase; import band.gosrock.api.order.service.ReadOrderUseCase; +import band.gosrock.api.order.service.RefuseOrderUseCase; import band.gosrock.common.annotation.ApiErrorExceptionsExample; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.security.SecurityRequirement; @@ -35,6 +36,8 @@ public class OrderAdminController { private final ReadOrderUseCase readOrderUseCase; private final CancelOrderUseCase cancelOrderUseCase; + private final RefuseOrderUseCase refuseOrderUseCase; + @Operation(summary = "어드민 목록 내 테이블 조회 OrderStage 는 꼭 보내주삼!") @GetMapping public PageResponse getEventOrders( @@ -64,7 +67,7 @@ public OrderResponse confirmOrder( @PostMapping("/{order_uuid}/refuse") public OrderResponse refuseOrder( @PathVariable Long eventId, @PathVariable("order_uuid") String orderUuid) { - return approveOrderUseCase.execute(eventId, orderUuid); + return refuseOrderUseCase.execute(eventId, orderUuid); } @Operation(summary = "주문관리 리스트 페이지에서 주문 상세정보 조회할때")