diff --git a/backend/order/src/main/java/org/samtuap/inong/domain/coupon/entity/Coupon.java b/backend/order/src/main/java/org/samtuap/inong/domain/coupon/entity/Coupon.java index ebb6e6c9..327c1d32 100644 --- a/backend/order/src/main/java/org/samtuap/inong/domain/coupon/entity/Coupon.java +++ b/backend/order/src/main/java/org/samtuap/inong/domain/coupon/entity/Coupon.java @@ -47,7 +47,7 @@ public void decreaseQuantity() { // 무제한 발급이므로 수량을 감소시키지 않음 return; } - if (this.quantity <= 0) { + if (this.quantity == 0) { throw new BaseCustomException(COUPON_SOLD_OUT); } this.quantity--; diff --git a/backend/order/src/main/java/org/samtuap/inong/domain/coupon/repository/CouponRedisRepository.java b/backend/order/src/main/java/org/samtuap/inong/domain/coupon/repository/CouponRedisRepository.java index b86a2d62..9b17bbff 100644 --- a/backend/order/src/main/java/org/samtuap/inong/domain/coupon/repository/CouponRedisRepository.java +++ b/backend/order/src/main/java/org/samtuap/inong/domain/coupon/repository/CouponRedisRepository.java @@ -1,11 +1,14 @@ package org.samtuap.inong.domain.coupon.repository; import lombok.RequiredArgsConstructor; +import org.samtuap.inong.common.exception.BaseCustomException; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Repository; import java.util.Set; +import static org.samtuap.inong.common.exceptionType.CouponExceptionType.COUPON_SOLD_OUT; + @Repository @RequiredArgsConstructor public class CouponRedisRepository { @@ -24,6 +27,9 @@ public void createCoupon(Long couponId, int quantity) { public Long decreaseCouponQuantity(Long couponId) { String key = getCouponQuantityKey(couponId); String currentValue = redisTemplate.opsForValue().get(key); + if("0".equals(currentValue)) { + throw new BaseCustomException(COUPON_SOLD_OUT); + } if ("-1".equals(currentValue)) { return -1L; }