Class HeaderModelAdvice
java.lang.Object
fr.utc.miage.sporttrack.controller.HeaderModelAdvice
Controller advice that populates the Spring MVC model with common header
attributes for all views in the SportTrack application.
Automatically resolves the currently authenticated athlete from the
HTTP session or Spring Security context and makes the athlete profile,
unread notification count, and recent notifications available to every
Thymeleaf template via @ModelAttribute methods.
- Author:
- SportTrack Team
-
Constructor Summary
ConstructorsConstructorDescriptionHeaderModelAdvice(AthleteRepository athleteRepository, NotificationService notificationService) Constructs aHeaderModelAdvicewith the required dependencies. -
Method Summary
Modifier and TypeMethodDescriptionathlete(jakarta.servlet.http.HttpSession session) Makes the currently authenticated athlete available to all views as a model attribute named"athlete".longnotificationUnreadCount(jakarta.servlet.http.HttpSession session) Computes the number of unread notifications for the current athlete and makes it available to all views as"notificationUnreadCount".recentNotifications(jakarta.servlet.http.HttpSession session) Retrieves the ten most recent notifications for the current athlete and makes them available to all views as"recentNotifications".
-
Constructor Details
-
HeaderModelAdvice
public HeaderModelAdvice(AthleteRepository athleteRepository, NotificationService notificationService) Constructs aHeaderModelAdvicewith the required dependencies.- Parameters:
athleteRepository- the repository for athlete data accessnotificationService- the service for notification queries
-
-
Method Details
-
athlete
Makes the currently authenticated athlete available to all views as a model attribute named"athlete".- Parameters:
session- the HTTP session used for athlete caching- Returns:
- the authenticated athlete, or
nullif not logged in
-
notificationUnreadCount
@ModelAttribute("notificationUnreadCount") public long notificationUnreadCount(jakarta.servlet.http.HttpSession session) Computes the number of unread notifications for the current athlete and makes it available to all views as"notificationUnreadCount".- Parameters:
session- the HTTP session used for athlete resolution- Returns:
- the count of unread notifications, or
0if not authenticated
-
recentNotifications
@ModelAttribute("recentNotifications") public List<Notification> recentNotifications(jakarta.servlet.http.HttpSession session) Retrieves the ten most recent notifications for the current athlete and makes them available to all views as"recentNotifications".- Parameters:
session- the HTTP session used for athlete resolution- Returns:
- a list of recent notifications, or an empty list if not authenticated
-