Class ChallengeRankingService
java.lang.Object
fr.utc.miage.sporttrack.service.event.ChallengeRankingService
Service layer component responsible for computing and persisting
ChallengeRanking entries for Challenge entities.
Rankings are recalculated whenever an activity is created, updated, or deleted
that impacts an active challenge. Scores are computed based on the challenge's
chosen Metric.
- Author:
- SportTrack Team
-
Constructor Summary
ConstructorsConstructorDescriptionChallengeRankingService(ChallengeRepository challengeRepository, ActivityRepository activityRepository) Constructs a newChallengeRankingServicewith the required repositories. -
Method Summary
Modifier and TypeMethodDescriptionvoidrecomputeRanking(Challenge challenge) Recomputes and persists the full ranking for the given challenge.voidrecomputeRankingsForActivity(Integer athleteId, Integer sportId, LocalDate activityDate) Recomputes rankings for all challenges impacted by a new or modified activity.
-
Constructor Details
-
ChallengeRankingService
public ChallengeRankingService(ChallengeRepository challengeRepository, ActivityRepository activityRepository) Constructs a newChallengeRankingServicewith the required repositories.- Parameters:
challengeRepository- the challenge repositoryactivityRepository- the activity repository
-
-
Method Details
-
recomputeRankingsForActivity
@Transactional public void recomputeRankingsForActivity(Integer athleteId, Integer sportId, LocalDate activityDate) Recomputes rankings for all challenges impacted by a new or modified activity.- Parameters:
athleteId- the identifier of the athlete whose activity changedsportId- the identifier of the sport associated with the activityactivityDate- the date of the activity
-
recomputeRanking
Recomputes and persists the full ranking for the given challenge.- Parameters:
challenge- the challenge whose rankings should be recomputed- Throws:
IllegalArgumentException- if the challenge uses COUNT as a metric, which is not allowed for challenges
-