Class ChallengeRankingService

java.lang.Object
fr.utc.miage.sporttrack.service.event.ChallengeRankingService

@Service public class ChallengeRankingService extends Object
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 Details

    • ChallengeRankingService

      public ChallengeRankingService(ChallengeRepository challengeRepository, ActivityRepository activityRepository)
      Constructs a new ChallengeRankingService with the required repositories.
      Parameters:
      challengeRepository - the challenge repository
      activityRepository - 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 changed
      sportId - the identifier of the sport associated with the activity
      activityDate - the date of the activity
    • recomputeRanking

      public void recomputeRanking(Challenge challenge)
      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