Class ObjectiveController
java.lang.Object
fr.utc.miage.sporttrack.controller.ObjectiveController
Spring MVC controller for objective management.
Manages objective listing, creation, completion, and deletion for the authenticated athlete.
- Author:
- SportTrack Team
-
Constructor Summary
ConstructorsConstructorDescriptionObjectiveController(ObjectiveService objectiveService, SportRepository sportRepository, AthleteRepository athleteRepository, SportService sportService) Constructs anObjectiveControllerwith the required dependencies. -
Method Summary
Modifier and TypeMethodDescriptioncompleteObjective(int id, jakarta.servlet.http.HttpSession session, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes) Marks the specified objective as completed for the authenticated athlete.createObjective(jakarta.servlet.http.HttpSession session, String name, String description, Integer sportId) Creates a new objective for the authenticated athlete.deleteObjective(int id) Deletes the objective with the given identifier.getObjectives(jakarta.servlet.http.HttpSession session, org.springframework.ui.Model model) Shows the list of objectives for the authenticated athlete.showObjectivesForm(jakarta.servlet.http.HttpSession session, org.springframework.ui.Model model) Displays the form for creating a new objective.
-
Constructor Details
-
ObjectiveController
public ObjectiveController(ObjectiveService objectiveService, SportRepository sportRepository, AthleteRepository athleteRepository, SportService sportService) Constructs anObjectiveControllerwith the required dependencies.- Parameters:
objectiveService- the objective servicesportRepository- the sport repositoryathleteRepository- the athlete repositorysportService- the sport service
-
-
Method Details
-
getObjectives
@GetMapping("/objectives") public String getObjectives(jakarta.servlet.http.HttpSession session, org.springframework.ui.Model model) Shows the list of objectives for the authenticated athlete.- Parameters:
session- the current HTTP sessionmodel- the model used by the view template- Returns:
- the objectives view or a redirect to login
-
createObjective
@PostMapping("/objectives") public String createObjective(jakarta.servlet.http.HttpSession session, @RequestParam String name, @RequestParam String description, @RequestParam Integer sportId) Creates a new objective for the authenticated athlete.- Parameters:
session- the current HTTP sessionname- the objective titledescription- the objective descriptionsportId- the selected sport identifier- Returns:
- a redirect to the objectives list, add form, or login page
-
deleteObjective
Deletes the objective with the given identifier.- Parameters:
id- the objective identifier to delete- Returns:
- a redirect to the objectives list
-
completeObjective
@PostMapping("/objectives/complete/{id}") public String completeObjective(@PathVariable("id") int id, jakarta.servlet.http.HttpSession session, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes) Marks the specified objective as completed for the authenticated athlete.- Parameters:
id- the objective identifiersession- the HTTP session for athlete resolutionredirectAttributes- flash attributes for success/error messaging- Returns:
- a redirect to the objectives list
-
showObjectivesForm
@GetMapping("/objectives/add") public String showObjectivesForm(jakarta.servlet.http.HttpSession session, org.springframework.ui.Model model) Displays the form for creating a new objective.- Parameters:
session- the HTTP session for athlete resolutionmodel- the Spring MVC model- Returns:
- the view name "objective/objective_form", or a redirect to login
-