Skip to content

Commit

Permalink
feat: 감시중인 소환사 1시간마다 전적 갱신
Browse files Browse the repository at this point in the history
  • Loading branch information
kimchijinju committed Nov 23, 2024
1 parent b086409 commit 98fc8a9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/main/java/mejai/mejaigg/app/user/service/UserService.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<Summoner> findAllWatchSummoner() {
return appUserRepository.findAll().stream()
.map(AppUser::getWatchSummoner)
.filter(Objects::nonNull)
.distinct()
.toList();
}
}
14 changes: 13 additions & 1 deletion src/main/java/mejai/mejaigg/app/watch/service/WatchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand All @@ -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<Summoner> watchSummoners = userService.findAllWatchSummoner();
for (Summoner summoner : watchSummoners) {
matchService.createMatches(summoner.getPuuid());
}
}

public SearchSummonerResponse getSummoner(String summonerName, String tag) {
Summoner summoner = profileService.findOrCreateSummoner(summonerName, tag);

Expand Down

0 comments on commit 98fc8a9

Please sign in to comment.