package com.elorating.scheduler;

import com.elorating.model.League;
import com.elorating.repository.LeagueRepository;
import com.elorating.repository.MatchRepository;
import com.elorating.repository.PlayerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class LeagueScheduler {

    @Autowired
    private MatchRepository matchRepository;

    @Autowired
    private PlayerRepository playerRepository;

    @Autowired
    private LeagueRepository leagueRepository;

    @Scheduled(cron = "0 5 23 * * *")
    public void removeUnassignedLeagues() {
        List<League> leaguesToRemove = leagueRepository.findByUsersNull();
        for (League league : leaguesToRemove) {
            String leagueId = league.getId();
            matchRepository.deleteByLeagueId(leagueId);
            playerRepository.deleteByLeagueId(leagueId);
            leagueRepository.delete(leagueId);
        }
    }
}

@@ -207,24 +207,113 @@
 Repository;%0A
+import com.elorating.service.GenericService;%0Aimport com.elorating.service.LeagueService;%0A
 import org.s
@@ -359,24 +359,24 @@
 .Autowired;%0A
-
 import org.s
@@ -695,41 +695,44 @@
 ate 
-LeagueRepository leagueRepository
+GenericService%3CLeague%3E leagueService
 ;%0A%0A 
@@ -855,40 +855,61 @@
 e = 
-leagueRepository.findByUsersNull
+((LeagueService) leagueService).findUnassignedLeagues
 ();%0A
@@ -1133,33 +1133,34 @@
   league
-Repository
+Service
 .delete
+ById
 (leagueI

Refactor League scheduler to use LeagueService