Class ObjectiveService
java.lang.Object
fr.utc.miage.sporttrack.service.event.ObjectiveService
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 Summary
ConstructorsConstructorDescriptionObjectiveService(ObjectiveRepository objectiveRepository) Constructs anObjectiveServicewithout notification support.ObjectiveService(ObjectiveRepository objectiveRepository, NotificationService notificationService) Constructs anObjectiveServicewith full notification support. -
Method Summary
Modifier and TypeMethodDescriptionvoiddeleteById(int id) Deletes the objective with the given identifier.getObjectivesByUser(Athlete athlete) Returns all objectives belonging to the specified athlete.booleanisObjectiveCompleted(Objective objective, List<Activity> activities) Determines whether an objective is considered completed based on the provided list of activities.markAsCompleted(int id, Athlete athlete) Marks the specified objective as completed for the given athlete.voidsaveObjective(Objective objective, Athlete athlete, Sport sport) Saves a new objective associated with the given athlete and sport.
-
Constructor Details
-
ObjectiveService
Constructs anObjectiveServicewithout notification support.- Parameters:
objectiveRepository- the objective repository
-
ObjectiveService
@Autowired public ObjectiveService(ObjectiveRepository objectiveRepository, NotificationService notificationService) Constructs anObjectiveServicewith full notification support.- Parameters:
objectiveRepository- the objective repositorynotificationService- the notification service for completion events
-
-
Method Details
-
saveObjective
Saves a new objective associated with the given athlete and sport. The objective is initialised as not completed.- Parameters:
objective- the objective entity to saveathlete- the athlete who owns the objectivesport- the sport to which the objective applies
-
markAsCompleted
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 objectiveathlete- the athlete who owns the objective- Returns:
- the updated
Objective - Throws:
IllegalArgumentException- if the athlete is null or the objective is not found
-
getObjectivesByUser
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
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 evaluateactivities- the list of activities to check against the objective- Returns:
trueif at least one activity satisfies the objective criteria
-