Skip to content

Commit

Permalink
Merge pull request #342 from samtuap/fix/341
Browse files Browse the repository at this point in the history
fix: 쿠폰이 맀진 λ˜μ—ˆμ„ λ•Œλ„ λ°œκΈ‰ λ˜λŠ” 였λ₯˜
  • Loading branch information
vydndrl authored Nov 4, 2024
2 parents 3786720 + c5d9d1c commit 22e6eda
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void decreaseQuantity() {
// λ¬΄μ œν•œ λ°œκΈ‰μ΄λ―€λ‘œ μˆ˜λŸ‰μ„ κ°μ†Œμ‹œν‚€μ§€ μ•ŠμŒ
return;
}
if (this.quantity <= 0) {
if (this.quantity == 0) {
throw new BaseCustomException(COUPON_SOLD_OUT);
}
this.quantity--;
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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;
}
Expand Down

0 comments on commit 22e6eda

Please sign in to comment.