From 98fc8a91211ccfba39cad198e74ad5c1e2316e58 Mon Sep 17 00:00:00 2001 From: kimchijinju Date: Sat, 23 Nov 2024 20:11:35 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B0=90=EC=8B=9C=EC=A4=91=EC=9D=B8=20?= =?UTF-8?q?=EC=86=8C=ED=99=98=EC=82=AC=201=EC=8B=9C=EA=B0=84=EB=A7=88?= =?UTF-8?q?=EB=8B=A4=20=EC=A0=84=EC=A0=81=20=EA=B0=B1=EC=8B=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mejaigg/app/user/service/UserService.java | 11 +++++++++++ .../mejaigg/app/watch/service/WatchService.java | 14 +++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/mejai/mejaigg/app/user/service/UserService.java b/src/main/java/mejai/mejaigg/app/user/service/UserService.java index 9ee5b9c..e376888 100644 --- a/src/main/java/mejai/mejaigg/app/user/service/UserService.java +++ b/src/main/java/mejai/mejaigg/app/user/service/UserService.java @@ -1,5 +1,8 @@ package mejai.mejaigg.app.user.service; +import java.util.List; +import java.util.Objects; + import org.springframework.stereotype.Service; import lombok.RequiredArgsConstructor; @@ -35,4 +38,12 @@ public void addWatchSummoner(long userId, Summoner summoner, Relationship relati public AppUser findUserById(long userId) { return appUserRepository.findById(userId).orElseThrow(); } + + public List findAllWatchSummoner() { + return appUserRepository.findAll().stream() + .map(AppUser::getWatchSummoner) + .filter(Objects::nonNull) + .distinct() + .toList(); + } } diff --git a/src/main/java/mejai/mejaigg/app/watch/service/WatchService.java b/src/main/java/mejai/mejaigg/app/watch/service/WatchService.java index 88974a8..6d30a38 100644 --- a/src/main/java/mejai/mejaigg/app/watch/service/WatchService.java +++ b/src/main/java/mejai/mejaigg/app/watch/service/WatchService.java @@ -6,6 +6,7 @@ import java.util.ArrayList; import java.util.List; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -41,7 +42,9 @@ public class WatchService { private final UserService userService; @Transactional - public CreateSummonerResponse watchSummoner(long userId, String summonerName, String tag, + public CreateSummonerResponse watchSummoner(long userId, + String summonerName, + String tag, Relationship relationship) { Summoner summoner = summonerRepository.findBySummonerNameAndTagLineAllIgnoreCase(summonerName, tag) .orElse(null); @@ -56,6 +59,15 @@ public CreateSummonerResponse watchSummoner(long userId, String summonerName, St return new CreateSummonerResponse(summoner.getId()); } + @Scheduled(cron = "0 0 0/1 * * *") + @Transactional + public void renewal() { + List watchSummoners = userService.findAllWatchSummoner(); + for (Summoner summoner : watchSummoners) { + matchService.createMatches(summoner.getPuuid()); + } + } + public SearchSummonerResponse getSummoner(String summonerName, String tag) { Summoner summoner = profileService.findOrCreateSummoner(summonerName, tag);