Skip to content

Commit

Permalink
Merge branch 'master' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
GodCipher committed May 28, 2024
2 parents c36df24 + 23cc693 commit 370dcf0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dev.luzifer.data.repository;

import dev.luzifer.data.entity.BannedChamp;
import org.springframework.data.jpa.repository.JpaRepository;

public interface BannedChampRepository extends JpaRepository<BannedChamp, Integer> {}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

import dev.luzifer.data.converter.EntityConverter;
import dev.luzifer.data.dto.GameDto;
import dev.luzifer.data.entity.BannedChamp;
import dev.luzifer.data.entity.Map;
import dev.luzifer.data.entity.Match;
import dev.luzifer.data.repository.BannedChampRepository;
import dev.luzifer.data.repository.MapRepository;
import dev.luzifer.data.repository.MatchRepository;
import java.util.Arrays;
Expand All @@ -19,21 +21,25 @@ public class MatchService extends BaseService {

private final MatchRepository matchRepository;
private final MapRepository mapRepository;
private final BannedChampRepository bannedChampRepository;

@Autowired
public MatchService(
MatchRepository matchRepository,
MapRepository mapRepository,
BannedChampRepository bannedChampRepository,
EntityConverter entityConverter) {
super(entityConverter);
this.matchRepository = matchRepository;
this.mapRepository = mapRepository;
this.bannedChampRepository = bannedChampRepository;
}

@Transactional
public void processMatchData(GameDto[] gameDtoArray) {
saveMatches(gameDtoArray);
saveMaps(gameDtoArray);
saveBannedChamps(gameDtoArray);
}

private void saveMatches(GameDto[] gameDtoArray) {
Expand All @@ -50,6 +56,13 @@ private void saveMaps(GameDto[] gameDtoArray) {
mapRepository.saveAll(mapsToSave);
}

private void saveBannedChamps(GameDto[] gameDtoArray) {
Set<BannedChamp> bannedChampsToSave = new HashSet<>();
Arrays.stream(gameDtoArray)
.forEach(game -> bannedChampsToSave.addAll(entityConverter.convertBannedChamps(game)));
bannedChampRepository.saveAll(bannedChampsToSave);
}

@Cacheable("matchCount")
public long countMatches() {
return matchRepository.count();
Expand Down

0 comments on commit 370dcf0

Please sign in to comment.