Class SportController
java.lang.Object
fr.utc.miage.sporttrack.controller.SportController
Spring MVC controller for administrator sport management.
Provides CRUD endpoints for sports, including creation, editing, and enabling/disabling, accessible only to authenticated admins.
- Author:
- SportTrack Team
-
Constructor Summary
ConstructorsConstructorDescriptionSportController(SportService sportService, AdminService adminService) Constructs aSportControllerwith the required services. -
Method Summary
Modifier and TypeMethodDescriptiondisable(int id, org.springframework.security.core.Authentication auth) Disables the sport with the given identifier, hiding it from athlete selection.enable(int id, org.springframework.security.core.Authentication auth) Enables the sport with the given identifier, making it available for athlete use.listSports(org.springframework.ui.Model model, org.springframework.security.core.Authentication auth) Lists all sports for the admin dashboard.saveSport(SportFormDTO dto, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes, org.springframework.security.core.Authentication auth) Creates or updates a sport from the submitted form data.showCreateForm(org.springframework.ui.Model model, org.springframework.security.core.Authentication auth) Displays the form for creating a new sport.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 sport.
-
Constructor Details
-
SportController
Constructs aSportControllerwith the required services.- Parameters:
sportService- the sport serviceadminService- the admin service
-
-
Method Details
-
listSports
@GetMapping public String listSports(org.springframework.ui.Model model, org.springframework.security.core.Authentication auth) Lists all sports for the admin dashboard.- Parameters:
model- the Spring MVC modelauth- the current security authentication- Returns:
- the view name "admin/sport/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 sport.- Parameters:
model- the Spring MVC modelauth- the current security authentication- Returns:
- the view name "admin/sport/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 sport.- Parameters:
id- the sport identifiermodel- the Spring MVC modelredirectAttributes- flash attributes for error messagingauth- the current security authentication- Returns:
- the edit view, or a redirect on failure
-
saveSport
@PostMapping("/save") public String saveSport(@ModelAttribute SportFormDTO dto, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes, org.springframework.security.core.Authentication auth) Creates or updates a sport from the submitted form data.- Parameters:
dto- the form DTO containing sport dataredirectAttributes- flash attributes for success/error messagingauth- the current security authentication- Returns:
- a redirect to the sport list or create form on error
-
enable
@PostMapping("/enable/{id}") public String enable(@PathVariable int id, org.springframework.security.core.Authentication auth) Enables the sport with the given identifier, making it available for athlete use.- Parameters:
id- the sport identifier to enableauth- the current security authentication- Returns:
- a redirect to the sport list
-
disable
@PostMapping("/disable/{id}") public String disable(@PathVariable int id, org.springframework.security.core.Authentication auth) Disables the sport with the given identifier, hiding it from athlete selection.- Parameters:
id- the sport identifier to disableauth- the current security authentication- Returns:
- a redirect to the sport list
-