Interface NotificationRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<Notification,,Integer> org.springframework.data.jpa.repository.JpaRepository<Notification,,Integer> org.springframework.data.repository.ListCrudRepository<Notification,,Integer> org.springframework.data.repository.ListPagingAndSortingRepository<Notification,,Integer> org.springframework.data.repository.PagingAndSortingRepository<Notification,,Integer> org.springframework.data.repository.query.QueryByExampleExecutor<Notification>,org.springframework.data.repository.Repository<Notification,Integer>
@Repository
public interface NotificationRepository
extends org.springframework.data.jpa.repository.JpaRepository<Notification,Integer>
Spring Data JPA repository for
Notification entities.
Provides standard CRUD operations as well as custom query methods for retrieving, counting, and marking notifications for a specific recipient.
- Author:
- SportTrack Team
-
Method Summary
Modifier and TypeMethodDescriptionlongcountByRecipientIdAndSeenFalse(Integer recipientId) Counts the number of unseen notifications for the specified recipient.findByIdAndRecipientId(Integer id, Integer recipientId) Finds a notification by its identifier and the identifier of its recipient.findByRecipientIdAndSeenFalseOrderByCreatedAtDesc(Integer recipientId) Finds all unseen notifications for the specified recipient, ordered by creation time descending.findByRecipientIdOrderByCreatedAtDesc(Integer recipientId) Finds all notifications for the specified recipient, ordered by creation time descending.findTop10ByRecipientIdOrderByCreatedAtDesc(Integer recipientId) Finds the ten most recent notifications for the specified recipient.intmarkAllAsSeen(Integer recipientId) Marks all notifications for the specified recipient as seen.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, saveMethods inherited from interface org.springframework.data.jpa.repository.JpaRepository
deleteAllByIdInBatch, deleteAllInBatch, deleteAllInBatch, deleteInBatch, findAll, findAll, flush, getById, getOne, getReferenceById, saveAllAndFlush, saveAndFlushMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.PagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findByRecipientIdOrderByCreatedAtDesc
Finds all notifications for the specified recipient, ordered by creation time descending.- Parameters:
recipientId- the unique identifier of the recipient- Returns:
- a list of notifications, newest first
-
findTop10ByRecipientIdOrderByCreatedAtDesc
Finds the ten most recent notifications for the specified recipient.- Parameters:
recipientId- the unique identifier of the recipient- Returns:
- a list of up to ten notifications, newest first
-
findByRecipientIdAndSeenFalseOrderByCreatedAtDesc
Finds all unseen notifications for the specified recipient, ordered by creation time descending.- Parameters:
recipientId- the unique identifier of the recipient- Returns:
- a list of unseen notifications, newest first
-
countByRecipientIdAndSeenFalse
Counts the number of unseen notifications for the specified recipient.- Parameters:
recipientId- the unique identifier of the recipient- Returns:
- the count of unseen notifications
-
findByIdAndRecipientId
Finds a notification by its identifier and the identifier of its recipient.- Parameters:
id- the unique identifier of the notificationrecipientId- the unique identifier of the recipient- Returns:
- an
Optionalcontaining the notification if found, empty otherwise
-
markAllAsSeen
@Modifying @Query("UPDATE Notification n SET n.seen = true WHERE n.recipient.id = :recipientId") int markAllAsSeen(@Param("recipientId") Integer recipientId) Marks all notifications for the specified recipient as seen.- Parameters:
recipientId- the unique identifier of the recipient whose notifications should be marked- Returns:
- the number of notifications that were updated
-