Class NotificationService

java.lang.Object
fr.utc.miage.sporttrack.service.user.communication.NotificationService

@Service public class NotificationService extends Object
Service layer component responsible for managing Notification entities within the SportTrack application.

Provides business logic for creating, querying, marking as read, and dispatching typed notifications for various application events such as messages, friend requests, badge awards, objectives, and challenge endings.

Author:
SportTrack Team
  • Constructor Details

    • NotificationService

      public NotificationService(NotificationRepository notificationRepository)
      Constructs a new NotificationService with the given repository.
      Parameters:
      notificationRepository - the notification repository
  • Method Details

    • createNotification

      public Notification createNotification(Athlete recipient, Athlete actor, NotificationType type, String title, String content, String targetUrl)
      Creates and persists a new notification.
      Parameters:
      recipient - the athlete who will receive the notification
      actor - the athlete who triggered the notification (may be null)
      type - the type of notification
      title - the notification title
      content - the notification body text
      targetUrl - the URL to navigate to when the notification is clicked
      Returns:
      the persisted Notification, or null if the recipient is invalid
    • getNotificationsForAthlete

      @Transactional(readOnly=true) public List<Notification> getNotificationsForAthlete(Integer athleteId)
      Returns all notifications for the specified athlete, ordered newest first.
      Parameters:
      athleteId - the identifier of the athlete
      Returns:
      a list of notifications, or an empty list if the identifier is null
    • getNotificationForRecipient

      @Transactional(readOnly=true) public Notification getNotificationForRecipient(Integer notificationId, Integer recipientId)
      Returns a specific notification if it belongs to the specified recipient.
      Parameters:
      notificationId - the notification identifier
      recipientId - the recipient identifier
      Returns:
      the matching notification, or null if not found or parameters are null
    • getRecentNotifications

      @Transactional(readOnly=true) public List<Notification> getRecentNotifications(Integer athleteId)
      Returns the ten most recent notifications for the specified athlete.
      Parameters:
      athleteId - the identifier of the athlete
      Returns:
      a list of up to ten notifications, newest first
    • countUnreadNotifications

      @Transactional(readOnly=true) public long countUnreadNotifications(Integer athleteId)
      Counts the number of unread notifications for the specified athlete.
      Parameters:
      athleteId - the identifier of the athlete
      Returns:
      the count of unread notifications, or 0 if the identifier is null
    • markAsRead

      @Transactional public void markAsRead(Integer notificationId, Integer recipientId)
      Marks a single notification as read for the specified recipient.
      Parameters:
      notificationId - the notification identifier
      recipientId - the recipient identifier
      Throws:
      IllegalArgumentException - if the notification is not found
    • markAllAsRead

      @Transactional public void markAllAsRead(Integer recipientId)
      Marks all notifications as read for the specified recipient.
      Parameters:
      recipientId - the recipient identifier
    • notifyMessageReceived

      @Transactional public void notifyMessageReceived(Message message)
      Sends a notification to the message recipient that a new message has been received.
      Parameters:
      message - the message that was received
    • notifyFriendRequest

      @Transactional public void notifyFriendRequest(Friendship friendship)
      Sends a notification to the friendship recipient that a friend request has been received.
      Parameters:
      friendship - the friendship representing the request
    • notifyFriendRequestAccepted

      @Transactional public void notifyFriendRequestAccepted(Friendship friendship)
      Sends a notification to the friendship initiator that their request has been accepted.
      Parameters:
      friendship - the accepted friendship
    • notifyActivityPublished

      @Transactional public void notifyActivityPublished(Athlete actor, Activity activity, List<Athlete> recipients)
      Sends a notification to multiple recipients that a friend has published a new activity.
      Parameters:
      actor - the athlete who published the activity
      activity - the newly published activity
      recipients - the list of friends to notify
    • notifyBadgeEarned

      @Transactional public void notifyBadgeEarned(Athlete athlete, Badge badge)
      Sends a notification to the athlete that they have earned a badge.
      Parameters:
      athlete - the athlete who earned the badge
      badge - the badge that was earned
    • notifyObjectiveCompleted

      @Transactional public void notifyObjectiveCompleted(Athlete athlete, Objective objective)
      Sends a notification to the athlete that an objective has been completed.
      Parameters:
      athlete - the athlete who completed the objective
      objective - the completed objective
    • notifyChallengeEnded

      @Transactional public void notifyChallengeEnded(Challenge challenge)
      Sends notifications to all participants and the organiser that a challenge has ended.
      Parameters:
      challenge - the challenge that has ended