Class ChallengeController

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

@Controller public class ChallengeController extends Object
Spring MVC controller for challenge management and participation.

Provides endpoints for creating, listing, and joining challenges, as well as viewing all available challenges.

Author:
SportTrack Team
  • Constructor Details

    • ChallengeController

      public ChallengeController(SportRepository sportRepository, AthleteRepository athleteRepository, ChallengeRepository challengeRepository, SportService sportService, ChallengeRankingService challengeRankingService)
      Constructs a ChallengeController with the required dependencies.
      Parameters:
      sportRepository - the sport repository
      athleteRepository - the athlete repository
      challengeRepository - the challenge repository
      sportService - the sport service
      challengeRankingService - the challenge ranking service
  • Method Details

    • showCreateChallengeForm

      @GetMapping("/challenges/new") public String showCreateChallengeForm(jakarta.servlet.http.HttpSession session, org.springframework.ui.Model model)
      Displays the form for creating a new challenge.
      Parameters:
      session - the HTTP session for athlete resolution
      model - the Spring MVC model
      Returns:
      the view name "challenge/challenge_form", or a redirect to login
    • createChallenge

      @PostMapping("/challenges") public String createChallenge(@ModelAttribute ChallengeFormDTO challengeDto, @RequestParam(required=false) Integer sportId, jakarta.servlet.http.HttpSession session, org.springframework.ui.Model model)
      Creates a new challenge from the submitted form data and initialises its ranking.
      Parameters:
      challengeDto - the form DTO containing challenge data
      sportId - the identifier of the selected sport
      session - the HTTP session for athlete resolution
      model - the Spring MVC model for error rendering
      Returns:
      a redirect to the challenge list, or the form view on error
    • listChallenges

      @GetMapping("/challenges") public String listChallenges(jakarta.servlet.http.HttpSession session, org.springframework.ui.Model model)
      Lists all challenges organised by or participated in by the authenticated athlete.
      Parameters:
      session - the HTTP session for athlete resolution
      model - the Spring MVC model
      Returns:
      the view name "challenge/challenge_list", or a redirect to login
    • participateInChallenge

      @GetMapping("/challenges/participate") public String participateInChallenge(@RequestParam int id, jakarta.servlet.http.HttpSession session)
      Adds the authenticated athlete as a participant to the specified challenge.
      Parameters:
      id - the challenge identifier
      session - the HTTP session for athlete resolution
      Returns:
      a redirect to the challenge list
    • listAllChallenges

      @GetMapping("/challenges/list") public String listAllChallenges(jakarta.servlet.http.HttpSession session, org.springframework.ui.Model model)
      Lists all challenges in the system, available for browsing and participation.
      Parameters:
      session - the HTTP session for athlete resolution
      model - the Spring MVC model
      Returns:
      the view name "challenge/challenges", or a redirect to login