-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: DiningTypeNotFoundException 클래스 구현 * feat: CoopShopService 클래스 diningType 찾는 메서드 구현 * feat: DiningNotifyCache Redis 클래스 생성 * feat: DiningNotifyCacheRepository Redis용 클래스 구현 * feat: DiningRepository 날짜, 타입, 장소 기준으로 이미지 업로드 여부 확인 메서드 구현 * feat: 식단 이미지 저장시 알림 발송 삭제, 스케줄러용 알림 발송 로직 구현 * feat: CoopScheduler 클래스 구현 * feat: LocalTime clock 추가 * feat: test 완성 * fix: 10분전 알림 로직 수정 * fix: 테스트용 코드 삭제 * fix: 테스트 수정 * fix: conflict 해결 * fix: 리뷰 반영
- Loading branch information
1 parent
885875d
commit b4a0e4c
Showing
10 changed files
with
351 additions
and
58 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
35 changes: 35 additions & 0 deletions
35
src/main/java/in/koreatech/koin/domain/coop/model/DiningNotifyCache.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 in.koreatech.koin.domain.coop.model; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.springframework.data.redis.core.RedisHash; | ||
import org.springframework.data.redis.core.TimeToLive; | ||
|
||
import jakarta.persistence.Id; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@RedisHash("DiningNotify") | ||
public class DiningNotifyCache { | ||
|
||
private static final long CACHE_EXPIRE_HOUR_BY_COOP = 3L; | ||
|
||
@Id | ||
private String id; | ||
|
||
@TimeToLive(unit = TimeUnit.HOURS) | ||
private final Long expiration; | ||
|
||
@Builder | ||
private DiningNotifyCache(String id, Long expiration){ | ||
this.id = id; | ||
this.expiration = CACHE_EXPIRE_HOUR_BY_COOP; | ||
} | ||
|
||
public static DiningNotifyCache from(String diningId){ | ||
return DiningNotifyCache.builder() | ||
.id(diningId) | ||
.build(); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/in/koreatech/koin/domain/coop/repository/DiningNotifyCacheRepository.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,22 @@ | ||
package in.koreatech.koin.domain.coop.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.repository.Repository; | ||
|
||
import in.koreatech.koin.domain.coop.exception.DiningCacheNotFoundException; | ||
import in.koreatech.koin.domain.coop.model.DiningNotifyCache; | ||
|
||
public interface DiningNotifyCacheRepository extends Repository<DiningNotifyCache, String> { | ||
|
||
DiningNotifyCache save(DiningNotifyCache diningNotifyCache); | ||
|
||
boolean existsById(String diningNotifyId); | ||
|
||
Optional<DiningNotifyCache> findById(String diningPlace); | ||
|
||
default DiningNotifyCache getById(String diningPlace) { | ||
return findById(diningPlace).orElseThrow( | ||
() -> DiningCacheNotFoundException.withDetail("diningSoldOutCache: " + diningPlace)); | ||
} | ||
} |
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
27 changes: 27 additions & 0 deletions
27
src/main/java/in/koreatech/koin/domain/coop/util/CoopScheduler.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,27 @@ | ||
package in.koreatech.koin.domain.coop.util; | ||
|
||
import org.springframework.scheduling.annotation.Scheduled; | ||
import org.springframework.stereotype.Component; | ||
|
||
import in.koreatech.koin.domain.coop.service.CoopService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class CoopScheduler { | ||
|
||
private final CoopService coopService; | ||
|
||
@Scheduled(cron = "0 0/6 7 * * *") | ||
@Scheduled(cron = "0 30/6 10-11 * * *") | ||
@Scheduled(cron = "0 30/6 16-17 * * *") | ||
public void notifyDiningImageUpload() { | ||
try { | ||
coopService.sendDiningNotify(); | ||
} catch (Exception e) { | ||
log.warn("식단 이미지 알림 과정에서 오류가 발생했습니다."); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/in/koreatech/koin/domain/coopshop/exception/DiningTypeNotFoundException.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,20 @@ | ||
package in.koreatech.koin.domain.coopshop.exception; | ||
|
||
import in.koreatech.koin.global.exception.DataNotFoundException; | ||
|
||
public class DiningTypeNotFoundException extends DataNotFoundException { | ||
|
||
private static final String DEFAULT_MESSAGE = "해당하는 식단 타입이 존재하지 않습니다."; | ||
|
||
public DiningTypeNotFoundException(String message) { | ||
super(message); | ||
} | ||
|
||
public DiningTypeNotFoundException(String message, String detail) { | ||
super(message, detail); | ||
} | ||
|
||
public static DiningTypeNotFoundException withDetail(String detail) { | ||
return new DiningTypeNotFoundException(DEFAULT_MESSAGE, detail); | ||
} | ||
} |
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.