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);