Class HeaderModelAdvice

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

@ControllerAdvice public class HeaderModelAdvice extends Object
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

    Constructors
    Constructor
    Description
    HeaderModelAdvice(AthleteRepository athleteRepository, NotificationService notificationService)
    Constructs a HeaderModelAdvice with the required dependencies.
  • Method Summary

    Modifier and Type
    Method
    Description
    athlete(jakarta.servlet.http.HttpSession session)
    Makes the currently authenticated athlete available to all views as a model attribute named "athlete".
    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".
    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".

    Methods inherited from class java.lang.Object

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

    • HeaderModelAdvice

      public HeaderModelAdvice(AthleteRepository athleteRepository, NotificationService notificationService)
      Constructs a HeaderModelAdvice with the required dependencies.
      Parameters:
      athleteRepository - the repository for athlete data access
      notificationService - the service for notification queries
  • Method Details

    • athlete

      @ModelAttribute("athlete") public Athlete athlete(jakarta.servlet.http.HttpSession session)
      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 null if 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 0 if 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