Class ObjectiveController

java.lang.Object
fr.utc.miage.sporttrack.controller.ObjectiveController

@Controller public class ObjectiveController extends Object
Spring MVC controller for objective management.

Manages objective listing, creation, completion, and deletion for the authenticated athlete.

Author:
SportTrack Team
  • Constructor Details

    • ObjectiveController

      public ObjectiveController(ObjectiveService objectiveService, SportRepository sportRepository, AthleteRepository athleteRepository, SportService sportService)
      Constructs an ObjectiveController with the required dependencies.
      Parameters:
      objectiveService - the objective service
      sportRepository - the sport repository
      athleteRepository - the athlete repository
      sportService - 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 session
      model - 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 session
      name - the objective title
      description - the objective description
      sportId - the selected sport identifier
      Returns:
      a redirect to the objectives list, add form, or login page
    • deleteObjective

      @PostMapping("/objectives/delete/{id}") public String deleteObjective(@PathVariable("id") int id)
      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 identifier
      session - the HTTP session for athlete resolution
      redirectAttributes - 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 resolution
      model - the Spring MVC model
      Returns:
      the view name "objective/objective_form", or a redirect to login