Class AthleteActivityController
java.lang.Object
fr.utc.miage.sporttrack.controller.AthleteActivityController
@Controller
@RequestMapping("/athlete/activities")
public class AthleteActivityController
extends Object
Spring MVC controller for athlete activity management.
Provides endpoints for listing, creating, editing, and deleting the authenticated athlete's own activities, including automatic weather report fetching and badge award checks.
- Author:
- SportTrack Team
-
Constructor Summary
ConstructorsConstructorDescriptionAthleteActivityController(ActivityService activityService, SportService sportService, WeatherReportService weatherReportService, AthleteService athleteService, BadgeService badgeService, CommentService commentService) Constructs anAthleteActivityControllerwith the required services. -
Method Summary
Modifier and TypeMethodDescriptiondeleteActivity(int id, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes, org.springframework.security.core.Authentication auth) Deletes an activity owned by the authenticated athlete.listMyActivities(org.springframework.ui.Model model, org.springframework.security.core.Authentication auth) Lists all activities of the authenticated athlete with weather and comment data.saveActivity(ActivityFormDTO activity, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes, org.springframework.security.core.Authentication auth) Creates or updates an activity from the submitted form data.showCreateForm(org.springframework.ui.Model model, org.springframework.security.core.Authentication auth) Displays the form for creating a new activity.showEditForm(int id, org.springframework.ui.Model model, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes, org.springframework.security.core.Authentication auth) Displays the form for editing an existing activity owned by the current athlete.
-
Constructor Details
-
AthleteActivityController
public AthleteActivityController(ActivityService activityService, SportService sportService, WeatherReportService weatherReportService, AthleteService athleteService, BadgeService badgeService, CommentService commentService) Constructs anAthleteActivityControllerwith the required services.- Parameters:
activityService- the activity servicesportService- the sport serviceweatherReportService- the weather report serviceathleteService- the athlete servicebadgeService- the badge servicecommentService- the comment service
-
-
Method Details
-
listMyActivities
@GetMapping public String listMyActivities(org.springframework.ui.Model model, org.springframework.security.core.Authentication auth) Lists all activities of the authenticated athlete with weather and comment data.- Parameters:
model- the Spring MVC modelauth- the current security authentication- Returns:
- the view name "athlete/activity/list", or a redirect to login
-
showCreateForm
@GetMapping("/create") public String showCreateForm(org.springframework.ui.Model model, org.springframework.security.core.Authentication auth) Displays the form for creating a new activity.- Parameters:
model- the Spring MVC modelauth- the current security authentication- Returns:
- the view name "athlete/activity/create", or a redirect to login
-
showEditForm
@GetMapping("/edit/{id}") public String showEditForm(@PathVariable int id, org.springframework.ui.Model model, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes, org.springframework.security.core.Authentication auth) Displays the form for editing an existing activity owned by the current athlete.- Parameters:
id- the activity identifiermodel- the Spring MVC modelredirectAttributes- flash attributes for error messagingauth- the current security authentication- Returns:
- the view name "athlete/activity/create", or a redirect on failure
-
saveActivity
@PostMapping("/save") public String saveActivity(@ModelAttribute("activity") ActivityFormDTO activity, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes, org.springframework.security.core.Authentication auth) Creates or updates an activity from the submitted form data. After saving, triggers weather report refresh and badge award checks.- Parameters:
activity- the form DTO containing the activity dataredirectAttributes- flash attributes for success/error messagingauth- the current security authentication- Returns:
- a redirect to the activity list, create, or edit page
-
deleteActivity
@PostMapping("/delete/{id}") public String deleteActivity(@PathVariable int id, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes, org.springframework.security.core.Authentication auth) Deletes an activity owned by the authenticated athlete.- Parameters:
id- the activity identifier to deleteredirectAttributes- flash attributes for success/error messagingauth- the current security authentication- Returns:
- a redirect to the activity list
-