NotificationRepository

@Repository
interface NotificationRepository : CrudRepository<Notification, Long>

DAO repository for working with "notification" db table

Functions

Link copied to clipboard
@Query(value = " SELECT EXISTS( SELECT * FROM notification WHERE user_id = (SELECT user_id FROM "user" WHERE token = :token) AND is_read = false ); ", nativeQuery = true)
abstract fun anyUnreadNotification(token: String): Boolean

Returns boolean whether there is any unread notification for a particular user token

Link copied to clipboard
abstract fun count(): Long
Link copied to clipboard
abstract fun delete(entity: Notification)
Link copied to clipboard
abstract fun deleteAll()
abstract fun deleteAll(entities: MutableIterable<Notification>)
Link copied to clipboard
abstract fun deleteAllById(ids: MutableIterable<Long>)
Link copied to clipboard
abstract fun deleteById(id: Long)
Link copied to clipboard
abstract fun existsById(id: Long): Boolean
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
@Query(value = " SELECT * FROM notification WHERE user_id = (SELECT user_id FROM "user" WHERE token = :token) order by "date" DESC; ", nativeQuery = true)
abstract fun findAllByToken(token: String): List<Notification>

Returns all notification for a particular user token

@Query(value = " SELECT * FROM notification WHERE user_id = (SELECT user_id FROM "user" WHERE token = :token) ", countQuery = " SELECT count(*) FROM notification WHERE user_id = (SELECT user_id FROM "user" WHERE token = :token); ", nativeQuery = true)
abstract fun findAllByToken(token: String, pageable: Pageable): Page<Notification>

Returns all notification for a particular user token with pagination

Link copied to clipboard
@Query(value = " SELECT * FROM notification WHERE "date" < current_timestamp + INTERVAL '- 2 WEEK'; ", nativeQuery = true)
abstract fun findAllExpiredNotifications(): List<Notification>

Returns notifications which are older than 2 weeks

Link copied to clipboard
abstract fun findById(id: Long): Optional<Notification>
Link copied to clipboard
abstract fun <S : Notification> save(entity: S): S
Link copied to clipboard
abstract fun <S : Notification> saveAll(entities: MutableIterable<S>): MutableIterable<S>