Implement scheduled tasks to reset weekly and monthly stats in StatsService
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good
This commit is contained in:
@@ -3,25 +3,26 @@ package SuMoC.backend.user.stats;
|
||||
import SuMoC.backend.gamification.Timeframe;
|
||||
import SuMoC.backend.user.repository.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class StatsService {
|
||||
|
||||
@Autowired
|
||||
private StatsListRepository statsListRepository;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
public void addToWeeklyStats(Long userId, String name, int value) {
|
||||
/*StatsList statsList = this.statsListRepository.findByUserId(userId)
|
||||
.orElseGet(() -> new StatsList(userRepository.getReferenceById(userId)));
|
||||
|
||||
statsList.getStat(Timeframe.WEEKLY, name).;
|
||||
this.statsListRepository.save(statsList);
|
||||
|
||||
*/
|
||||
@Scheduled(cron = "0 0 0 ? * MON")
|
||||
public void resetWeeklyStats() {
|
||||
userRepository.findAll().forEach( user -> {
|
||||
user.getStats().resetStats(Timeframe.WEEKLY);
|
||||
});
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0 0 0 1 * ?")
|
||||
public void resetMonthlyStats() {
|
||||
userRepository.findAll().forEach( user -> {
|
||||
user.getStats().resetStats(Timeframe.MONTHLY);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user