-
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.
* retactor : ClockHolder 메서드명 변경 * feat: ClockHolder 시간 추가 * style: ClockHolder 및 메서드명 변경 * feat : Cache 기능 추가 * docs : Reame 작성
- Loading branch information
Showing
27 changed files
with
228 additions
and
60 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,42 @@ | ||
# moabam-BE | ||
## 🐥 MOABAM 서비스 | ||
|
||
![img.png](readme-image/img.png) | ||
|
||
![img_1.png](readme-image/img_1.png) | ||
|
||
<br><br> | ||
|
||
## 👨👨👧 Backend Team 소개 | ||
|
||
| 김영명 | 김희빈 | 박세연(PO) | 신재윤 | 홍혁준(SM) | | ||
|:------------------------------------------------------------------------------:|:------------------------------------------------------------------------------:|:------------------------------------------------------------------------------:|:------------------------------------------------------------------------------:|:------------------------------------------------------------------------------:| | ||
| DEVELOPER | DEVELOPER | DEVELOPER | DEVELOPER | DEVELOPER | | ||
| <img src="https://avatars.githubusercontent.com/u/83266154?v=4" width="250" /> | <img src="https://avatars.githubusercontent.com/u/72112845?v=4" width="250" /> | <img src="https://avatars.githubusercontent.com/u/54196094?v=4" width="250" /> | <img src="https://avatars.githubusercontent.com/u/87688023?v=4" width="250" /> | <img src="https://avatars.githubusercontent.com/u/31675711?v=4" width="250" /> | | ||
| [ymkim97](https://github.com/ymkim97) | [kmebin](https://github.com/kmebin) | [parksey](https://github.com/parksey) | [DevUni](https://github.com/Shin-Jae-Yoon) | [HongDosan](https://github.com/HyuckJuneHong) | | ||
| 방 도메인, 루틴 인증(메인) | 상품 도메인, 결제, 에러 알림, BE 팀장 | 회원 도메인, 랭킹 어드민 페이지 | 방 도메인, 루틴 인증(서브), 인프라 (AWS, CI/CD) | 쿠폰 도메인, 알림, 선착순 이벤트, 캐싱 | | ||
|
||
<br><br> | ||
|
||
## 공통 협업 방식 | ||
|
||
![img.png](readme-image/협업.png) | ||
|
||
## 서비스 아키텍처 | ||
|
||
![img.png](readme-image/서비스-아키텍처.png) | ||
|
||
## CI/CD 파이프라인 | ||
|
||
![img.png](readme-image/파이프라인.png) | ||
|
||
## 컨벤션 | ||
|
||
![img_1.png](readme-image/컨벤션.png) | ||
|
||
## Config 관리 | ||
|
||
![img.png](readme-image/콘피그.png) | ||
|
||
## Test | ||
|
||
![img.png](readme-image/테스트.png) |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions
34
src/main/java/com/moabam/api/application/coupon/CouponCacheService.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,34 @@ | ||
package com.moabam.api.application.coupon; | ||
|
||
import java.time.LocalDate; | ||
import java.util.Optional; | ||
|
||
import org.springframework.cache.annotation.CacheConfig; | ||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.stereotype.Service; | ||
|
||
import com.moabam.api.domain.coupon.Coupon; | ||
import com.moabam.api.domain.coupon.repository.CouponRepository; | ||
import com.moabam.global.error.exception.NotFoundException; | ||
import com.moabam.global.error.model.ErrorMessage; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@CacheConfig(cacheNames = "coupons") | ||
public class CouponCacheService { | ||
|
||
private final CouponRepository couponRepository; | ||
|
||
@Cacheable(key = "#couponName + #now") | ||
public Coupon getByNameAndStartAt(String couponName, LocalDate now) { | ||
return couponRepository.findByNameAndStartAt(couponName, now) | ||
.orElseThrow(() -> new NotFoundException(ErrorMessage.INVALID_COUPON_PERIOD)); | ||
} | ||
|
||
@Cacheable(key = "#now") | ||
public Optional<Coupon> getByStartAt(LocalDate now) { | ||
return couponRepository.findByStartAt(now); | ||
} | ||
} |
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.moabam.global.config; | ||
|
||
import static org.springframework.data.redis.serializer.RedisSerializationContext.*; | ||
|
||
import java.time.Duration; | ||
import java.time.LocalTime; | ||
|
||
import org.springframework.cache.annotation.EnableCaching; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.cache.RedisCacheConfiguration; | ||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.SerializationFeature; | ||
import com.fasterxml.jackson.databind.json.JsonMapper; | ||
import com.fasterxml.jackson.databind.jsontype.BasicPolymorphicTypeValidator; | ||
import com.fasterxml.jackson.databind.jsontype.PolymorphicTypeValidator; | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | ||
import com.moabam.global.common.util.ClockHolder; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@EnableCaching | ||
@Configuration | ||
@RequiredArgsConstructor | ||
public class CacheConfig { | ||
|
||
private final ClockHolder clockHolder; | ||
|
||
@Bean | ||
public RedisCacheConfiguration redisCacheConfiguration() { | ||
var strSerializePair = SerializationPair.fromSerializer(new StringRedisSerializer()); | ||
var objSerializePair = SerializationPair.fromSerializer(new GenericJackson2JsonRedisSerializer(objectMapper())); | ||
|
||
return RedisCacheConfiguration.defaultCacheConfig() | ||
.entryTtl(getTtl()) | ||
.serializeKeysWith(strSerializePair) | ||
.serializeValuesWith(objSerializePair); | ||
} | ||
|
||
private Duration getTtl() { | ||
LocalTime now = clockHolder.time(); | ||
LocalTime end = clockHolder.endOfDay(); | ||
|
||
return Duration.between(now, end); | ||
} | ||
|
||
private ObjectMapper objectMapper() { | ||
PolymorphicTypeValidator polymorphicTypeValidator = BasicPolymorphicTypeValidator.builder() | ||
.allowIfSubType(Object.class) | ||
.build(); | ||
|
||
return JsonMapper.builder() | ||
.polymorphicTypeValidator(polymorphicTypeValidator) | ||
.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) | ||
.addModule(new JavaTimeModule()) | ||
.activateDefaultTyping(polymorphicTypeValidator, ObjectMapper.DefaultTyping.NON_FINAL) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.