-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: 쿠폰 및 토큰 패키지 및 클래스명 변경 * refactor: 알림 패키지 및 클래스명 변경, Fcm 로직 분리 * feat: 쿠폰 발급 요청 기능 구현 * test: 쿠폰 발급 요청 기능 테스트 * test: Syntax 에러로 쿠폰 발급 관련 테스트 임시 Disabled 처리 * fix: Redis Yaml 추가 설정 * test: 중복 저장에 대한 테스트 코드 추가 * refactor: SystemClockHolder -> ClockHolder 변경
- Loading branch information
Showing
31 changed files
with
578 additions
and
100 deletions.
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
36 changes: 36 additions & 0 deletions
36
src/main/java/com/moabam/api/application/coupon/CouponQueueService.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,36 @@ | ||
package com.moabam.api.application.coupon; | ||
|
||
import org.springframework.stereotype.Service; | ||
|
||
import com.moabam.api.domain.coupon.Coupon; | ||
import com.moabam.api.domain.coupon.repository.CouponQueueRepository; | ||
import com.moabam.global.auth.model.AuthorizationMember; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class CouponQueueService { | ||
|
||
private final CouponService couponService; | ||
private final CouponQueueRepository couponQueueRepository; | ||
|
||
public void register(AuthorizationMember member, String couponName) { | ||
double registerTime = System.currentTimeMillis(); | ||
|
||
if (canRegister(couponName)) { | ||
log.info("{} 쿠폰이 모두 발급되었습니다.", couponName); | ||
return; | ||
} | ||
|
||
couponQueueRepository.addQueue(couponName, member.nickname(), registerTime); | ||
} | ||
|
||
private boolean canRegister(String couponName) { | ||
Coupon coupon = couponService.validateCouponPeriod(couponName); | ||
|
||
return coupon.getStock() <= couponQueueRepository.queueSize(coupon.getName()); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/moabam/api/domain/coupon/repository/CouponQueueRepository.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,24 @@ | ||
package com.moabam.api.domain.coupon.repository; | ||
|
||
import static java.util.Objects.*; | ||
|
||
import org.springframework.stereotype.Repository; | ||
|
||
import com.moabam.api.infrastructure.redis.ZSetRedisRepository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class CouponQueueRepository { | ||
|
||
private final ZSetRedisRepository zSetRedisRepository; | ||
|
||
public void addQueue(String couponName, String memberNickname, double score) { | ||
zSetRedisRepository.addIfAbsent(requireNonNull(couponName), requireNonNull(memberNickname), score); | ||
} | ||
|
||
public Long queueSize(String couponName) { | ||
return zSetRedisRepository.size(requireNonNull(couponName)); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/moabam/api/domain/coupon/repository/CouponRepository.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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
package com.moabam.api.domain.coupon.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.moabam.api.domain.coupon.Coupon; | ||
|
||
public interface CouponRepository extends JpaRepository<Coupon, Long> { | ||
|
||
Optional<Coupon> findByName(String couponName); | ||
|
||
boolean existsByName(String name); | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/moabam/api/infrastructure/redis/ZSetRedisRepository.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,35 @@ | ||
package com.moabam.api.infrastructure.redis; | ||
|
||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class ZSetRedisRepository { | ||
|
||
private final RedisTemplate<String, Object> redisTemplate; | ||
|
||
public void addIfAbsent(String key, String value, double score) { | ||
if (redisTemplate.opsForZSet().score(key, value) == null) { | ||
redisTemplate | ||
.opsForZSet() | ||
.add(key, value, score); | ||
} | ||
} | ||
|
||
public Long size(String key) { | ||
return redisTemplate | ||
.opsForZSet() | ||
.size(key); | ||
} | ||
|
||
public Boolean hasKey(String key) { | ||
return redisTemplate.hasKey(key); | ||
} | ||
|
||
public void delete(String key) { | ||
redisTemplate.delete(key); | ||
} | ||
} |
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.