DELETE /admins/coupons/33 HTTP/1.1
+DELETE /admins/coupons/36 HTTP/1.1
Host: localhost:8080
diff --git a/src/main/java/com/moabam/api/application/coupon/CouponManageService.java b/src/main/java/com/moabam/api/application/coupon/CouponManageService.java index 67e3bac7..3cda6f9a 100644 --- a/src/main/java/com/moabam/api/application/coupon/CouponManageService.java +++ b/src/main/java/com/moabam/api/application/coupon/CouponManageService.java @@ -16,6 +16,7 @@ import com.moabam.global.common.util.ClockHolder; import com.moabam.global.error.exception.BadRequestException; import com.moabam.global.error.exception.ConflictException; +import com.moabam.global.error.exception.NotFoundException; import com.moabam.global.error.model.ErrorMessage; import lombok.RequiredArgsConstructor; @@ -75,7 +76,7 @@ public void registerQueue(String couponName, Long memberId) { couponManageRepository.addIfAbsentQueue(couponName, memberId, registerTime); } - public void deleteQueue(String couponName) { + public void delete(String couponName) { couponManageRepository.deleteQueue(couponName); couponManageRepository.deleteCount(couponName); } @@ -83,7 +84,7 @@ public void deleteQueue(String couponName) { private void validateRegisterQueue(String couponName, Long memberId) { LocalDate now = clockHolder.date(); Coupon coupon = couponRepository.findByNameAndStartAt(couponName, now) - .orElseThrow(() -> new BadRequestException(ErrorMessage.INVALID_COUPON_PERIOD)); + .orElseThrow(() -> new NotFoundException(ErrorMessage.INVALID_COUPON_PERIOD)); if (couponManageRepository.hasValue(couponName, memberId)) { throw new ConflictException(ErrorMessage.CONFLICT_COUPON_ISSUE); diff --git a/src/main/java/com/moabam/api/application/coupon/CouponService.java b/src/main/java/com/moabam/api/application/coupon/CouponService.java index 43b289fb..3a765dff 100644 --- a/src/main/java/com/moabam/api/application/coupon/CouponService.java +++ b/src/main/java/com/moabam/api/application/coupon/CouponService.java @@ -60,7 +60,7 @@ public void delete(Long couponId, Role role) { .orElseThrow(() -> new NotFoundException(ErrorMessage.NOT_FOUND_COUPON)); couponRepository.delete(coupon); - couponManageService.deleteQueue(coupon.getName()); + couponManageService.delete(coupon.getName()); } @Transactional diff --git a/src/main/java/com/moabam/api/domain/coupon/repository/CouponManageRepository.java b/src/main/java/com/moabam/api/domain/coupon/repository/CouponManageRepository.java index 44e2c150..0381f236 100644 --- a/src/main/java/com/moabam/api/domain/coupon/repository/CouponManageRepository.java +++ b/src/main/java/com/moabam/api/domain/coupon/repository/CouponManageRepository.java @@ -58,7 +58,13 @@ public int rankQueue(String couponName, Long memberId) { public int getCount(String couponName) { String couponCountKey = String.format(COUPON_COUNT_KEY, requireNonNull(couponName)); - return Integer.parseInt(valueRedisRepository.get(couponCountKey)); + String count = valueRedisRepository.get(couponCountKey); + + if (isNull(count)) { + return 0; + } + + return Integer.parseInt(count); } public void increase(String couponName, long count) { diff --git a/src/main/resources/static/docs/coupon.html b/src/main/resources/static/docs/coupon.html index d7435ce2..af8593f3 100644 --- a/src/main/resources/static/docs/coupon.html +++ b/src/main/resources/static/docs/coupon.html @@ -498,7 +498,7 @@
DELETE /admins/coupons/33 HTTP/1.1
+DELETE /admins/coupons/36 HTTP/1.1
Host: localhost:8080
GET /coupons/21 HTTP/1.1
+GET /coupons/24 HTTP/1.1
Host: localhost:8080
HTTP/1.1 400 Bad Request
+HTTP/1.1 409 Conflict
Access-Control-Allow-Origin:
Access-Control-Allow-Methods: GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, PATCH
Access-Control-Allow-Headers: Origin, Accept, Access-Control-Request-Method, Access-Control-Request-Headers, X-Requested-With,Content-Type, Referer
Access-Control-Allow-Credentials: true
Access-Control-Max-Age: 3600
Content-Type: application/json
-Content-Length: 64
+Content-Length: 63
{
- "message" : "쿠폰 발급 가능 기간이 아닙니다."
+ "message" : "이미 쿠폰 발급에 성공했습니다!"
}