Class AdminBadgeController
java.lang.Object
fr.utc.miage.sporttrack.controller.AdminBadgeController
Spring MVC controller for administrator badge management.
Provides CRUD endpoints for badges, accessible only to authenticated admins.
- Author:
- SportTrack Team
-
Constructor Summary
ConstructorsConstructorDescriptionAdminBadgeController(BadgeService badgeService, SportService sportService, AdminService adminService, SportRepository sportRepository) Constructs anAdminBadgeControllerwith the required dependencies. -
Method Summary
Modifier and TypeMethodDescriptiondeleteBadge(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.
-
Constructor Details
-
AdminBadgeController
public AdminBadgeController(BadgeService badgeService, SportService sportService, AdminService adminService, SportRepository sportRepository) Constructs anAdminBadgeControllerwith the required dependencies.- Parameters:
badgeService- the badge servicesportService- the sport serviceadminService- the admin servicesportRepository- 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 modelauth- 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 modelauth- 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 identifiermodel- the Spring MVC modelredirectAttributes- flash attributes for error messagingauth- 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 dataredirectAttributes- flash attributes for success/error messagingauth- 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 deleteredirectAttributes- flash attributes for success/error messagingauth- the current security authentication- Returns:
- a redirect to the badge list
-