challenges
LocationBasedServices/sumoc-backend/pipeline/head This commit looks good

This commit is contained in:
2026-02-03 20:07:47 +01:00
parent 4fe86b6845
commit 60d335f16d
13 changed files with 1028 additions and 3 deletions
@@ -2,6 +2,7 @@ package SuMoC.backend.user.stats;
import SuMoC.backend.gamification.Timeframe;
import SuMoC.backend.gamification.badges.BadgeService;
import SuMoC.backend.gamification.challenges.ChallengeService;
import SuMoC.backend.user.dtos.StatScope;
import SuMoC.backend.user.models.User;
import SuMoC.backend.user.repository.UserRepository;
@@ -21,14 +22,17 @@ public class StatsService {
@Autowired
private UserRepository userRepository;
private final BadgeService badgeService;
private final ChallengeService challengeService;
private final CurrentUserService currentUserService;
public StatsService(CurrentUserService currentUserService,
UserRepository userRepository,
BadgeService badgeService) {
BadgeService badgeService,
ChallengeService challengeService) {
this.currentUserService = currentUserService;
this.userRepository = userRepository;
this.badgeService = badgeService;
this.challengeService = challengeService;
}
@Scheduled(cron = "0 0 0 ? * MON")
@@ -60,7 +64,7 @@ public class StatsService {
);
@Transactional
public void addStatsToCurrentUser(String statField, long value, StatScope scope, boolean awardBadges) {
public void addStatsToCurrentUser(String statField, long value, StatScope scope, boolean awardBadges, boolean awardChallenges) {
if (!ALLOWED_STATS.contains(statField)) {
throw new ResponseStatusException(
HttpStatus.BAD_REQUEST,
@@ -89,6 +93,10 @@ public class StatsService {
if (awardBadges) {
badgeService.checkAndAwardBadges();
}
if (awardChallenges) {
challengeService.checkAndAwardChallenges(statField, value);
}
}
public StatsList getStats() {