Class SportController

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

@Controller @RequestMapping("/admin/sports") public class SportController extends Object
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

    Constructors
    Constructor
    Description
    SportController(SportService sportService, AdminService adminService)
    Constructs a SportController with the required services.
  • Method Summary

    Modifier and Type
    Method
    Description
    disable(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.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SportController

      public SportController(SportService sportService, AdminService adminService)
      Constructs a SportController with the required services.
      Parameters:
      sportService - the sport service
      adminService - 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 model
      auth - 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 model
      auth - 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 identifier
      model - the Spring MVC model
      redirectAttributes - flash attributes for error messaging
      auth - 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 data
      redirectAttributes - flash attributes for success/error messaging
      auth - 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 enable
      auth - 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 disable
      auth - the current security authentication
      Returns:
      a redirect to the sport list