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 9ff2809 commit ef24fe0
Showing 1 changed file with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
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 @@ -49,18 +48,20 @@ public void issue() {
String couponName = coupon.getName();
int maxCount = coupon.getMaxCount();
int currentCount = couponManageRepository.getCount(couponName);

if (maxCount <= currentCount) {
return;
}

Set<Long> membersId = couponManageRepository.rangeQueue(couponName, currentCount, currentCount + ISSUE_SIZE);

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

for (Long memberId : membersId) {
int rank = couponManageRepository.rankQueue(couponName, memberId);

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

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

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

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

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);
}
notificationService.sendCouponIssueResult(memberId, couponName, FAIL_ISSUE_BODY);
}
}

0 comments on commit ef24fe0

Please sign in to comment.