-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 쿠폰 보관함 조회 기능 구현 #149
Merged
Merged
Changes from 19 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
136eff2
style : Schedule 어노테이션 위치 변경
hongdosan bc837c1
refactor: 쿠폰 발행 기간 하루로 통일 및 쿠폰 정보 오픈 날짜 추가
hongdosan cebc707
feat: 쿠폰 발행 가능 날짜 중복 체크 기능 추가
hongdosan 9df5c45
refactor: Builder 삭제
hongdosan a5bb2a1
test: 쿠폰 관련 테스트 수정
hongdosan ab522fd
feat: 쿠폰 발행 및 등록 기능 구현 및 테스트
hongdosan d91d962
feat: 쿠폰 발행 관련 레포지토리 기능 구현 및 테스트
hongdosan a20a115
test: 쿠폰 발행 관련 문자열 레디스 기능 구현 및 테스트
hongdosan 9e3476b
feat: 쿠폰 발행 관련 ZSET 레디스 기능 구현 및 테스트
hongdosan e48c48e
test: 쿠폰 발행 컨트롤러 기능 테스트
hongdosan 82bcd37
test: RestDoc 업데이트
hongdosan 2b39b27
merge develop
hongdosan 74b5f93
merge develop
hongdosan fb5e3d0
test: Github Actions 시, Redis ZSET 명령어 못찾는 테스트 Disable
hongdosan 2e85aa0
refactor: 알림 및 쿠폰 테스트 코드 메서드명 변경 및 알림 콕 알림 키 변경
hongdosan 2084a27
feat: 쿠폰함 조회 서비스 기능 구현 및 테스트
hongdosan 90780d9
feat: 쿠폰 보관함 저장소 조회 기능 구현 및 테스트
hongdosan ba12cde
feat: 쿠폰 보관함 조회 기능 구현 및 테스트
hongdosan 82e54be
fix: temporal 에러 해결
hongdosan b9b7889
merge develop
hongdosan 37ed033
refactor: Stream 코드 리뷰 반영
hongdosan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
src/main/java/com/moabam/api/application/coupon/CouponManageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package com.moabam.api.application.coupon; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.moabam.api.domain.coupon.Coupon; | ||
import com.moabam.api.domain.coupon.CouponWallet; | ||
import com.moabam.api.domain.coupon.repository.CouponManageRepository; | ||
import com.moabam.api.domain.coupon.repository.CouponRepository; | ||
import com.moabam.api.domain.coupon.repository.CouponWalletRepository; | ||
import com.moabam.global.auth.model.AuthMember; | ||
import com.moabam.global.common.util.ClockHolder; | ||
import com.moabam.global.error.exception.BadRequestException; | ||
import com.moabam.global.error.model.ErrorMessage; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class CouponManageService { | ||
|
||
private static final long ISSUE_SIZE = 10; | ||
|
||
private final ClockHolder clockHolder; | ||
|
||
private final CouponRepository couponRepository; | ||
private final CouponManageRepository couponManageRepository; | ||
private final CouponWalletRepository couponWalletRepository; | ||
|
||
@Scheduled(fixedDelay = 1000) | ||
public void issue() { | ||
LocalDate now = LocalDate.from(clockHolder.times()); | ||
Optional<Coupon> isCoupon = couponRepository.findByStartAt(now); | ||
|
||
if (!canIssue(isCoupon)) { | ||
return; | ||
} | ||
|
||
Coupon coupon = isCoupon.get(); | ||
Set<Long> membersId = couponManageRepository.popMinQueue(coupon.getName(), ISSUE_SIZE); | ||
|
||
membersId.forEach(memberId -> { | ||
int nextStock = couponManageRepository.increaseIssuedStock(coupon.getName()); | ||
|
||
if (coupon.getStock() < nextStock) { | ||
return; | ||
} | ||
|
||
CouponWallet couponWallet = CouponWallet.create(memberId, coupon); | ||
couponWalletRepository.save(couponWallet); | ||
}); | ||
} | ||
|
||
public void register(AuthMember authMember, String couponName) { | ||
double registerTime = System.currentTimeMillis(); | ||
validateRegister(couponName); | ||
couponManageRepository.addIfAbsentQueue(couponName, authMember.id(), registerTime); | ||
} | ||
|
||
public void deleteCouponManage(String couponName) { | ||
couponManageRepository.deleteQueue(couponName); | ||
couponManageRepository.deleteIssuedStock(couponName); | ||
} | ||
|
||
private void validateRegister(String couponName) { | ||
LocalDate now = LocalDate.from(clockHolder.times()); | ||
Optional<Coupon> coupon = couponRepository.findByStartAt(now); | ||
|
||
if (coupon.isEmpty() || !coupon.get().getName().equals(couponName)) { | ||
throw new BadRequestException(ErrorMessage.INVALID_COUPON_PERIOD); | ||
} | ||
} | ||
|
||
private boolean canIssue(Optional<Coupon> coupon) { | ||
if (coupon.isEmpty()) { | ||
return false; | ||
} | ||
|
||
Coupon currentCoupon = coupon.get(); | ||
int currentStock = couponManageRepository.getIssuedStock(currentCoupon.getName()); | ||
int maxStock = currentCoupon.getStock(); | ||
|
||
return currentStock < maxStock; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 0 additions & 36 deletions
36
src/main/java/com/moabam/api/application/coupon/CouponQueueService.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: 맨처음 PR에도 있지 않았나요?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
연속으로 PR을 올려서 이전 것도 보이는 걸거에요 ㅎㅎ