Skip to content

Commit

Permalink
fix : order approve not delete user (#477)
Browse files Browse the repository at this point in the history
* fix : 주문 승인 조회시에만 지워진 유저 안보이게

* fix : 주문 승인간 유저 탈퇴여부 검증

* style : spotless

* test : 테스트 돌아가게 수정
  • Loading branch information
ImNM authored Feb 27, 2023
1 parent c3e7653 commit c804fdc
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import band.gosrock.domain.domains.order.domain.Order;
import band.gosrock.domain.domains.order.domain.OrderLineItem;
import band.gosrock.domain.domains.order.domain.OrderStatus;
import band.gosrock.domain.domains.order.exception.CanNotApproveDeletedUserOrderException;
import band.gosrock.domain.domains.order.exception.CanNotCancelOrderException;
import band.gosrock.domain.domains.order.exception.CanNotRefundOrderException;
import band.gosrock.domain.domains.order.exception.InvalidOrderException;
Expand All @@ -24,6 +25,8 @@
import band.gosrock.domain.domains.ticket_item.adaptor.TicketItemAdaptor;
import band.gosrock.domain.domains.ticket_item.domain.Option;
import band.gosrock.domain.domains.ticket_item.domain.TicketItem;
import band.gosrock.domain.domains.user.adaptor.UserAdaptor;
import band.gosrock.domain.domains.user.domain.User;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
Expand All @@ -42,6 +45,8 @@ public class OrderValidator {
private final IssuedTicketAdaptor issuedTicketAdaptor;
private final OptionAdaptor optionAdaptor;

private final UserAdaptor userAdaptor;

/** 주문을 생성할 수 있는지에 대한검증 */
public void validCanCreate(Order order) {
TicketItem item = getItem(order);
Expand Down Expand Up @@ -74,16 +79,21 @@ public void validOptionNotChange(Order order, TicketItem item) {
});
}

public void validOptionNotChangeAfterDoneOrderEvent(Order order) {
TicketItem item = getItem(order);
validOptionNotChange(order, item);
}

/** 승인 가능한 주문인지 검증합니다. */
public void validCanApproveOrder(Order order) {
validMethodIsCanApprove(order);
validStatusCanApprove(getOrderStatus(order));
validCanDone(order);
// 유저가 탈퇴를 안했는지 확인.
validUserNotDeleted(order);
}

/** 주문 승인 간에 유저가 탈퇴를 했는지 조회합니다. */
public void validUserNotDeleted(Order order) {
User user = userAdaptor.queryUser(order.getUserId());
if (user.isDeletedUser()) {
throw CanNotApproveDeletedUserOrderException.EXCEPTION;
}
}

/** 결제 방식의 주문을 승인할수있는지 확인합니다. */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package band.gosrock.domain.domains.order.exception;


import band.gosrock.common.exception.DuDoongCodeException;

public class CanNotApproveDeletedUserOrderException extends DuDoongCodeException {

public static final DuDoongCodeException EXCEPTION =
new CanNotApproveDeletedUserOrderException();

private CanNotApproveDeletedUserOrderException() {
super(OrderErrorCode.CAN_NOT_DELETED_USER_APPROVE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public enum OrderErrorCode implements BaseErrorCode {
ORDER_LESS_THAN_MINIMUM(BAD_REQUEST, "Order_400_11", "최소 결제금액인 1000원보다 낮은 주문입니다."),
@ExplainError("한 장바구니엔 관련된 한 아이템만 올수 있음")
ORDER_INVALID_ITEM_KIND_POLICY(BAD_REQUEST, "Order_400_12", "장바구니에 아이템을 담는 정책을 위반하였습니다."),
ORDER_OPTION_CHANGED(BAD_REQUEST, "Order_400_13", "주문 과정중 아이템의 옵션이 변화했습니다.");
ORDER_OPTION_CHANGED(BAD_REQUEST, "Order_400_13", "주문 과정중 아이템의 옵션이 변화했습니다."),
CAN_NOT_DELETED_USER_APPROVE(BAD_REQUEST, "Order_400_14", "유저가 탈퇴를 했습니다.");

private Integer status;
private String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import band.gosrock.domain.domains.order.domain.OrderStatus;
import band.gosrock.domain.domains.order.repository.condition.FindEventOrdersCondition;
import band.gosrock.domain.domains.order.repository.condition.FindMyPageOrderCondition;
import band.gosrock.domain.domains.user.domain.AccountState;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.DateTemplate;
import com.querydsl.core.types.dsl.Expressions;
Expand Down Expand Up @@ -73,6 +74,8 @@ public Page<Order> findEventOrders(FindEventOrdersCondition condition, Pageable
.join(user)
.on(user.id.eq(order.userId))
.where(
// 주문 승인 요청 보여질 때만 지워진 유저를 보이게 하지 않습니다.
condition.showDeleteUserExpression(),
eqEventId(condition.getEventId()),
condition.getOrderStatusFilter(),
condition.getSearchStringFilter())
Expand All @@ -88,6 +91,7 @@ public Page<Order> findEventOrders(FindEventOrdersCondition condition, Pageable
.join(user)
.on(user.id.eq(order.userId))
.where(
condition.showDeleteUserExpression(),
eqEventId(condition.getEventId()),
condition.getOrderStatusFilter(),
condition.getSearchStringFilter());
Expand Down Expand Up @@ -131,4 +135,8 @@ private BooleanExpression openingState(Boolean isShowing) {
? eventEndAtTemplate.after(now)
: eventEndAtTemplate.before(now);
}

private BooleanExpression notDeletedUser() {
return user.accountState.ne(AccountState.DELETED);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,32 @@
import static band.gosrock.domain.domains.order.domain.OrderStatus.PENDING_APPROVE;
import static band.gosrock.domain.domains.order.domain.OrderStatus.REFUND;
import static band.gosrock.domain.domains.order.domain.QOrder.order;
import static band.gosrock.domain.domains.user.domain.QUser.user;

import band.gosrock.domain.domains.user.domain.AccountState;
import com.querydsl.core.types.dsl.BooleanExpression;

/** 어드민 테이블의 주문 상태 검색 조건 지정을 위함. */
public enum AdminTableOrderFilterType {
APPROVE_WAITING(order.orderStatus.eq(PENDING_APPROVE)),
CONFIRMED(order.orderStatus.in(CONFIRM, APPROVED, CANCELED, REFUND));
APPROVE_WAITING(
order.orderStatus.eq(PENDING_APPROVE), user.accountState.ne(AccountState.DELETED)),
// 완료된 주문을 가져오는건 지워진 유저도 불러와야한다.
CONFIRMED(order.orderStatus.in(CONFIRM, APPROVED, CANCELED, REFUND), null);

private final BooleanExpression expression;
private final BooleanExpression showDeleteUserExpression;

AdminTableOrderFilterType(BooleanExpression expression) {
AdminTableOrderFilterType(
BooleanExpression expression, BooleanExpression showDeleteUserExpression) {
this.expression = expression;
this.showDeleteUserExpression = showDeleteUserExpression;
}

public BooleanExpression getFilter() {
return expression;
}

public BooleanExpression showDeleteUserExpression() {
return showDeleteUserExpression;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ public BooleanExpression getOrderStatusFilter() {
return filterType.getFilter();
}

public BooleanExpression showDeleteUserExpression() {
return filterType.showDeleteUserExpression();
}

public BooleanExpression getSearchStringFilter() {
if (searchType == null) return null;
return searchType.getContains(searchString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,8 @@ public void toggleReceiveEmail() {
public void toggleMarketingAgree() {
marketingAgree = !marketingAgree;
}

public Boolean isDeletedUser() {
return accountState == AccountState.DELETED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import band.gosrock.domain.domains.ticket_item.domain.TicketItem;
import band.gosrock.domain.domains.ticket_item.exception.TicketItemQuantityLackException;
import band.gosrock.domain.domains.ticket_item.exception.TicketPurchaseLimitException;
import band.gosrock.domain.domains.user.adaptor.UserAdaptor;
import java.util.Arrays;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -55,6 +56,7 @@ class OrderValidatorTest {
@Mock TicketItemAdaptor ticketItemAdaptor;
@Mock IssuedTicketAdaptor issuedTicketAdaptor;
@Mock OptionAdaptor optionAdaptor;
@Mock UserAdaptor userAdaptor;
@Mock Option optionOfGroup1;
@Mock Option optionOfGroup2;
@Mock OrderLineItem orderLineItem;
Expand All @@ -67,7 +69,11 @@ class OrderValidatorTest {
void setUp() {
orderValidator =
new OrderValidator(
eventAdaptor, ticketItemAdaptor, issuedTicketAdaptor, optionAdaptor);
eventAdaptor,
ticketItemAdaptor,
issuedTicketAdaptor,
optionAdaptor,
userAdaptor);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ void setUp() {
.build();
order.addUUID();
willDoNothing().given(orderValidator).validCanDone(any());
willDoNothing().given(orderValidator).validUserNotDeleted(any());
willCallRealMethod().given(orderValidator).validCanApproveOrder(any());
willCallRealMethod().given(orderValidator).validStatusCanApprove(any());
given(orderAdaptor.findByOrderUuid(any())).willReturn(order);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ void setUp() {
.build();
order.addUUID();
willDoNothing().given(orderValidator).validCanDone(any());
willDoNothing().given(orderValidator).validUserNotDeleted(any());
willCallRealMethod().given(orderValidator).validCanApproveOrder(any());
willCallRealMethod().given(orderValidator).validStatusCanApprove(any());
given(orderAdaptor.findByOrderUuid(any())).willReturn(order);
Expand Down

0 comments on commit c804fdc

Please sign in to comment.