Skip to content

Commit

Permalink
Merge pull request #576 from Gosrock/dev
Browse files Browse the repository at this point in the history
Release Api-v1.0.7
  • Loading branch information
ImNM authored Jan 20, 2025
2 parents 3b29e95 + d6ad31e commit 7bf6455
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ public Long countPaidTicket(Long userId, Long itemId) {
return issuedTicketRepository.countPaidTicket(userId, itemId);
}

public Long countIssuedTicketByItemId(Long itemId) {
return issuedTicketRepository.countIssuedTicketByItemId(itemId);
}

public IssuedTicket queryByIssuedTicketNo(String issuedTicketNo) {
return issuedTicketRepository
.findByIssuedTicketNo(issuedTicketNo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface IssuedTicketCustomRepository {
Optional<IssuedTicket> find(Long issuedTicketId);

Long countPaidTicket(Long userId, Long issuedTicketId);

Long countIssuedTicketByItemId(Long ticketItemId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,29 @@ public Optional<IssuedTicket> find(Long issuedTicketId) {
}

@Override
public Long countPaidTicket(Long userId, Long issuedTicketId) {
public Long countPaidTicket(Long userId, Long ticketItemId) {
return queryFactory
.select(count(issuedTicket))
.from(issuedTicket)
.where(eqUserId(userId), eqEventId(issuedTicketId), filterPaidTickets())
.where(eqUserId(userId), eqTicketItemId(ticketItemId), filterPaidTickets())
.fetchOne();
}

@Override
public Long countIssuedTicketByItemId(Long ticketItemId) {
return queryFactory
.select(count(issuedTicket))
.from(issuedTicket)
.where(eqTicketItemId(ticketItemId), filterPaidTickets())
.fetchOne();
}

private BooleanExpression filterPaidTickets() {
return issuedTicket.issuedTicketStatus.in(ENTRANCE_COMPLETED, ENTRANCE_INCOMPLETE);
}

private BooleanExpression eqEventId(Long issuedTicketId) {
return issuedTicket.itemInfo.ticketItemId.eq(issuedTicketId);
private BooleanExpression eqTicketItemId(Long ticketItemId) {
return issuedTicket.itemInfo.ticketItemId.eq(ticketItemId);
}

private BooleanExpression eqUserId(Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public Page<Order> findEventOrders(FindEventOrdersCondition condition, Pageable
return orderRepository.findEventOrders(condition, pageable);
}

public List<Order> findByEventIdAndOrderStatus(Long eventId, OrderStatus orderStatus) {
return orderRepository.findByEventIdAndOrderStatus(eventId, orderStatus);
}

public List<Order> findByEventIdAndOrderStatusAndUserId(
Long eventId, Long userId, OrderStatus orderStatus) {
return orderRepository.findByEventIdAndUserIdAndOrderStatus(eventId, userId, orderStatus);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public static Order createApproveOrder(
.build();
orderValidator.validCanCreate(order);
orderValidator.validApproveStatePurchaseLimit(order);
orderValidator.validApproveOrderCreateTotalStock(order);
order.calculatePaymentInfo();
return order;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,23 @@ public void validApproveStatePurchaseLimit(Order order) {
}
}

public void validApproveOrderCreateTotalStock(Order order) {
TicketItem item = getItem(order);

List<Order> approveWaitingOrders =
orderAdaptor.findByEventIdAndOrderStatus(
order.getEventId(), OrderStatus.PENDING_APPROVE);
Long approveWaitingTicketCount =
approveWaitingOrders.stream().map(Order::getTotalQuantity).reduce(0L, Long::sum);

Long alreadyIssuedCount = issuedTicketAdaptor.countIssuedTicketByItemId(order.getItemId());

Long expectQuantity =
alreadyIssuedCount + approveWaitingTicketCount + order.getTotalQuantity();

item.validEnoughQuantity(expectQuantity);
}

/** 이벤트가 열려있는 상태인지 */
public void validEventIsOpen(Event event) {
event.validateNotOpenStatus();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ public interface OrderRepository extends CrudRepository<Order, Long>, OrderCusto

List<Order> findByEventId(Long eventId);

List<Order> findByEventIdAndOrderStatus(Long eventId, OrderStatus orderStatus);

List<Order> findByEventIdAndUserIdAndOrderStatus(
Long eventId, Long userId, OrderStatus orderStatus);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public enum TicketItemErrorCode implements BaseErrorCode {
@ExplainError("요청에서 보내준 옵션 id 값이 올바르지 않을 때 발생하는 오류입니다.")
OPTION_NOT_FOUND(NOT_FOUND, "Option_404_1", "옵션을 찾을 수 없습니다."),
@ExplainError("주문 요청한 티켓 상품 재고가 부족할 때 발생하는 오류입니다.")
TICKET_ITEM_QUANTITY_LACK(BAD_REQUEST, "Ticket_Item_400_1", "티켓 상품 재고가 부족합니다."),
TICKET_ITEM_QUANTITY_LACK(
BAD_REQUEST,
"Ticket_Item_400_1",
"티켓 상품 재고가 부족합니다. ( 승인 대기 또는 앞선 주문으로 인해, 재고가 있어도 주문이 불가할 수 있습니다.)"),
@ExplainError("주문 및 승인 요청 시 티켓 상품 재고보다 많은 양을 주문 시 발생하는 오류입니다.")
TICKET_ITEM_QUANTITY_LESS_THAN_ZERO(
BAD_REQUEST, "Ticket_Item_400_2", "티켓 아이템 재고가 0보다 작을 수 없습니다."),
Expand Down

0 comments on commit 7bf6455

Please sign in to comment.