Skip to content

Commit 0cd4814

Browse files
committed
refactor: 쿠폰 재고 차감 로직 수정
1 parent b9b2d3a commit 0cd4814

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

apps/commerce-api/src/main/java/com/loopers/application/order/OrderFacade.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.loopers.application.order;
22

33
import com.loopers.application.orderitem.OrderItemInfo;
4+
import com.loopers.application.product.UserActionEvent;
45
import com.loopers.domain.coupon.Coupon;
56
import com.loopers.domain.coupon.CouponRepository;
67
import com.loopers.domain.order.Order;
@@ -80,14 +81,16 @@ public OrderResultInfo createOrder(OrderV1Dto.OrderRequest request) {
8081
() -> new CoreException(ErrorType.NOT_FOUND, "존재하지 않는 쿠폰입니다.")
8182
);
8283

83-
if (coupon.getQuantity() > 0) {
84-
int rate = coupon.getCouponType().getRate();
85-
86-
totalPrice = totalPrice
87-
.multiply(BigDecimal.valueOf(100 - rate))
88-
.divide(BigDecimal.valueOf(100));
84+
if (coupon.getQuantity() <= 0) {
85+
throw new CoreException(ErrorType.BAD_REQUEST, "남은 쿠폰이 존재하지 않습니다.");
8986
}
9087

88+
int rate = coupon.getCouponType().getRate();
89+
90+
totalPrice = totalPrice
91+
.multiply(BigDecimal.valueOf(100 - rate))
92+
.divide(BigDecimal.valueOf(100));
93+
9194
publisher.publishEvent(new OrderCreatedEvent(couponId));
9295

9396
Order order = request.toEntity(totalPrice);

0 commit comments

Comments
 (0)