Class AdminBadgeController

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

@Controller @RequestMapping("/admin/badges") public class AdminBadgeController extends Object
Spring MVC controller for administrator badge management.

Provides CRUD endpoints for badges, accessible only to authenticated admins.

Author:
SportTrack Team
  • Constructor Summary

    Constructors
    Constructor
    Description
    AdminBadgeController(BadgeService badgeService, SportService sportService, AdminService adminService, SportRepository sportRepository)
    Constructs an AdminBadgeController with the required dependencies.
  • Method Summary

    Modifier and Type
    Method
    Description
    deleteBadge(int id, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes, org.springframework.security.core.Authentication auth)
    Deletes the badge with the given identifier.
    listBadges(org.springframework.ui.Model model, org.springframework.security.core.Authentication auth)
    Lists all badges for the admin dashboard.
    saveBadge(BadgeFormDTO badgeForm, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes, org.springframework.security.core.Authentication auth)
    Creates or updates a badge from the submitted form data.
    showCreateForm(org.springframework.ui.Model model, org.springframework.security.core.Authentication auth)
    Displays the form for creating a new badge.
    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 badge.

    Methods inherited from class java.lang.Object

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

    • AdminBadgeController

      public AdminBadgeController(BadgeService badgeService, SportService sportService, AdminService adminService, SportRepository sportRepository)
      Constructs an AdminBadgeController with the required dependencies.
      Parameters:
      badgeService - the badge service
      sportService - the sport service
      adminService - the admin service
      sportRepository - the sport repository
  • Method Details

    • listBadges

      @GetMapping public String listBadges(org.springframework.ui.Model model, org.springframework.security.core.Authentication auth)
      Lists all badges for the admin dashboard.
      Parameters:
      model - the Spring MVC model
      auth - the current security authentication
      Returns:
      the view name "admin/badge/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 badge.
      Parameters:
      model - the Spring MVC model
      auth - the current security authentication
      Returns:
      the view name "admin/badge/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 badge.
      Parameters:
      id - the badge identifier
      model - the Spring MVC model
      redirectAttributes - flash attributes for error messaging
      auth - the current security authentication
      Returns:
      the view name "admin/badge/create", or a redirect on failure
    • saveBadge

      @PostMapping("/save") public String saveBadge(@ModelAttribute BadgeFormDTO badgeForm, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes, org.springframework.security.core.Authentication auth)
      Creates or updates a badge from the submitted form data.

      Global (universal) badges without a sport are only allowed for COUNT and DURATION metrics. Sport-specific badges can use any metric.

      Parameters:
      badgeForm - the form DTO containing badge data
      redirectAttributes - flash attributes for success/error messaging
      auth - the current security authentication
      Returns:
      a redirect to the badge list or create form on error
    • deleteBadge

      @PostMapping("/delete/{id}") public String deleteBadge(@PathVariable int id, org.springframework.web.servlet.mvc.support.RedirectAttributes redirectAttributes, org.springframework.security.core.Authentication auth)
      Deletes the badge with the given identifier.
      Parameters:
      id - the badge identifier to delete
      redirectAttributes - flash attributes for success/error messaging
      auth - the current security authentication
      Returns:
      a redirect to the badge list