Class ChallengeController
java.lang.Object
fr.utc.miage.sporttrack.controller.ChallengeController
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 Summary
ConstructorsConstructorDescriptionChallengeController(SportRepository sportRepository, AthleteRepository athleteRepository, ChallengeRepository challengeRepository, SportService sportService, ChallengeRankingService challengeRankingService) Constructs aChallengeControllerwith the required dependencies. -
Method Summary
Modifier and TypeMethodDescriptioncreateChallenge(ChallengeFormDTO challengeDto, 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.listAllChallenges(jakarta.servlet.http.HttpSession session, org.springframework.ui.Model model) Lists all challenges in the system, available for browsing and participation.listChallenges(jakarta.servlet.http.HttpSession session, org.springframework.ui.Model model) Lists all challenges organised by or participated in by the authenticated athlete.participateInChallenge(int id, jakarta.servlet.http.HttpSession session) Adds the authenticated athlete as a participant to the specified challenge.showCreateChallengeForm(jakarta.servlet.http.HttpSession session, org.springframework.ui.Model model) Displays the form for creating a new challenge.
-
Constructor Details
-
ChallengeController
public ChallengeController(SportRepository sportRepository, AthleteRepository athleteRepository, ChallengeRepository challengeRepository, SportService sportService, ChallengeRankingService challengeRankingService) Constructs aChallengeControllerwith the required dependencies.- Parameters:
sportRepository- the sport repositoryathleteRepository- the athlete repositorychallengeRepository- the challenge repositorysportService- the sport servicechallengeRankingService- 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 resolutionmodel- 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 datasportId- the identifier of the selected sportsession- the HTTP session for athlete resolutionmodel- 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 resolutionmodel- 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 identifiersession- 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 resolutionmodel- the Spring MVC model- Returns:
- the view name "challenge/challenges", or a redirect to login
-