Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature : 승인 대기중인 주문 관리자 취소 기능 추가 #559

Merged
merged 4 commits into from
May 22, 2023
Merged
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 @@ -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;
Expand All @@ -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<OrderAdminTableElement> getEventOrders(
Expand All @@ -52,14 +55,21 @@ public OrderResponse cancelOrder(
return cancelOrderUseCase.execute(eventId, orderUuid);
}

@Operation(summary = "주문 승인하기 . 호스트 관리자가 티켓 주문을 승인합니다. ( 어드민 이벤트쪽으로 이동예정 )")
@Operation(summary = "주문 승인하기 . 호스트 관리자가 티켓 주문을 승인합니다.")
@ApiErrorExceptionsExample(ApproveOrderExceptionDocs.class)
@PostMapping("/{order_uuid}/approve")
public OrderResponse confirmOrder(
@PathVariable Long eventId, @PathVariable("order_uuid") String orderUuid) {
return approveOrderUseCase.execute(eventId, orderUuid);
}

@Operation(summary = "승인 주문 거절하기 . 호스트 관리자가 승인 대기중인 주문을 거절합니다.")
@PostMapping("/{order_uuid}/refuse")
public OrderResponse refuseOrder(
@PathVariable Long eventId, @PathVariable("order_uuid") String orderUuid) {
return refuseOrderUseCase.execute(eventId, orderUuid);
}

@Operation(summary = "주문관리 리스트 페이지에서 주문 상세정보 조회할때")
@GetMapping("/{order_uuid}")
public OrderResponse getEventOrderDetail(
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,14 @@ public void cancel(OrderValidator orderValidator) {
Events.raise(WithDrawOrderEvent.from(this));
}

/** 관리자가 승인 대기 중인 주문을 거절합니다. */
public void refuse(OrderValidator orderValidator) {
orderValidator.validCanRefuse(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ 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);
Expand Down Expand Up @@ -280,6 +287,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)) {
Expand All @@ -293,6 +305,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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}