File tree Expand file tree Collapse file tree
apps/commerce-api/src/main/java/com/loopers/application/order Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package com .loopers .application .order ;
22
33import com .loopers .application .orderitem .OrderItemInfo ;
4+ import com .loopers .application .product .UserActionEvent ;
45import com .loopers .domain .coupon .Coupon ;
56import com .loopers .domain .coupon .CouponRepository ;
67import 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 );
You can’t perform that action at this time.
0 commit comments