Class ObjectiveService

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

@Service public class ObjectiveService extends Object
Service layer component responsible for managing Objective entities within the SportTrack application.

Provides business logic for creating, completing, querying, and deleting objectives. When an objective is completed, a notification is sent to the athlete.

Author:
SportTrack Team
  • Constructor Details

    • ObjectiveService

      public ObjectiveService(ObjectiveRepository objectiveRepository)
      Constructs an ObjectiveService without notification support.
      Parameters:
      objectiveRepository - the objective repository
    • ObjectiveService

      @Autowired public ObjectiveService(ObjectiveRepository objectiveRepository, NotificationService notificationService)
      Constructs an ObjectiveService with full notification support.
      Parameters:
      objectiveRepository - the objective repository
      notificationService - the notification service for completion events
  • Method Details

    • saveObjective

      @Transactional public void saveObjective(Objective objective, Athlete athlete, Sport sport)
      Saves a new objective associated with the given athlete and sport. The objective is initialised as not completed.
      Parameters:
      objective - the objective entity to save
      athlete - the athlete who owns the objective
      sport - the sport to which the objective applies
    • markAsCompleted

      @Transactional public Objective markAsCompleted(int id, Athlete athlete)
      Marks the specified objective as completed for the given athlete. A notification is sent if the notification service is available.
      Parameters:
      id - the unique identifier of the objective
      athlete - the athlete who owns the objective
      Returns:
      the updated Objective
      Throws:
      IllegalArgumentException - if the athlete is null or the objective is not found
    • getObjectivesByUser

      public Iterable<Objective> getObjectivesByUser(Athlete athlete)
      Returns all objectives belonging to the specified athlete.
      Parameters:
      athlete - the athlete whose objectives should be retrieved
      Returns:
      an iterable of objectives owned by the athlete
    • deleteById

      public void deleteById(int id)
      Deletes the objective with the given identifier.
      Parameters:
      id - the unique identifier of the objective to delete
    • isObjectiveCompleted

      public boolean isObjectiveCompleted(Objective objective, List<Activity> activities)
      Determines whether an objective is considered completed based on the provided list of activities. Completion is evaluated by matching the sport and checking whether the relevant metric (distance or repetition) is positive.
      Parameters:
      objective - the objective to evaluate
      activities - the list of activities to check against the objective
      Returns:
      true if at least one activity satisfies the objective criteria