Skip to content

Commit

Permalink
refactor: 리뷰 코드 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hongdosan committed Jul 3, 2024
1 parent ef24fe0 commit ecd4d84
Showing 1 changed file with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.moabam.api.domain.coupon.repository.CouponManageRepository;
import com.moabam.api.domain.coupon.repository.CouponWalletRepository;
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.model.ErrorMessage;

Expand Down Expand Up @@ -48,20 +49,18 @@ public void issue() {
String couponName = coupon.getName();
int maxCount = coupon.getMaxCount();
int currentCount = couponManageRepository.getCount(couponName);
Set<Long> membersId = couponManageRepository.rangeQueue(couponName, currentCount, currentCount + ISSUE_SIZE);

if (membersId == null || membersId.isEmpty()) {
if (maxCount <= currentCount) {
return;
}

for (Long memberId : membersId) {
int rank = couponManageRepository.rankQueue(couponName, memberId);
Set<Long> membersId = couponManageRepository.rangeQueue(couponName, currentCount, currentCount + ISSUE_SIZE);

if (maxCount <= rank) {
notificationService.sendCouponIssueResult(memberId, couponName, FAIL_ISSUE_BODY);
continue;
}
if (membersId.isEmpty()) {
return;
}

for (Long memberId : membersId) {
couponWalletRepository.save(CouponWallet.create(memberId, coupon));
notificationService.sendCouponIssueResult(memberId, couponName, SUCCESS_ISSUE_BODY);
}
Expand All @@ -82,12 +81,18 @@ public void registerQueue(String couponName, Long memberId) {

private void validateRegisterQueue(String couponName, Long memberId) {
LocalDate now = clockHolder.date();
couponCacheService.getByNameAndStartAt(couponName, now);
Coupon coupon = couponCacheService.getByNameAndStartAt(couponName, now);

if (couponManageRepository.hasValue(couponName, memberId)) {
throw new ConflictException(ErrorMessage.CONFLICT_COUPON_ISSUE);
}

notificationService.sendCouponIssueResult(memberId, couponName, FAIL_ISSUE_BODY);
int maxCount = coupon.getMaxCount();
int sizeQueue = couponManageRepository.sizeQueue(couponName);

if (maxCount <= sizeQueue) {
notificationService.sendCouponIssueResult(memberId, couponName, FAIL_ISSUE_BODY);
throw new BadRequestException(ErrorMessage.INVALID_COUPON_STOCK_END);
}
}
}

0 comments on commit ecd4d84

Please sign in to comment.