MessageRepository

@Repository
interface MessageRepository : JpaRepository<Message, String> (source)

Functions

Link copied to clipboard
abstract fun count(): Long
abstract fun <S : Message> count(example: Example<S>): Long
Link copied to clipboard
@Query(value = "SELECT COUNT(m) FROM Message m WHERE m.contactId = :contactId AND m.direction = 'INBOUND' AND m.status != 'READ'")
abstract fun countUnreadByContactId(contactId: String): Long
Link copied to clipboard
abstract fun delete(entity: Message)
Link copied to clipboard
abstract fun deleteAll()
abstract fun deleteAll(entities: MutableIterable<Message>)
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
abstract fun deleteAllInBatch()
abstract fun deleteAllInBatch(entities: MutableIterable<Message>)
Link copied to clipboard
abstract fun deleteById(id: String)
Link copied to clipboard
Link copied to clipboard
abstract fun <S : Message> exists(example: Example<S>): Boolean
Link copied to clipboard
abstract fun existsById(id: String): Boolean
Link copied to clipboard
abstract override fun <S : Message> findAll(example: Example<S>): MutableList<S>
abstract override fun <S : Message> findAll(example: Example<S>, sort: Sort): MutableList<S>
abstract override fun findAll(): MutableList<Message>
abstract override fun findAll(sort: Sort): MutableList<Message>
abstract fun findAll(pageable: Pageable): Page<Message>
abstract fun <S : Message> findAll(example: Example<S>, pageable: Pageable): Page<S>
Link copied to clipboard
abstract override fun findAllById(ids: MutableIterable<String>): MutableList<Message>
Link copied to clipboard
abstract fun <S : Message, R : Any> findBy(example: Example<S>, queryFunction: Function<FluentQuery.FetchableFluentQuery<S>, R>): R
Link copied to clipboard
abstract fun findByContactIdOrderByCreatedAtDesc(contactId: String, pageable: Pageable): Page<Message>
Link copied to clipboard
abstract fun findById(id: String): Optional<Message>
Link copied to clipboard
abstract fun findByWamid(wamid: String): Optional<Message>
Link copied to clipboard
@Query(value = " SELECT * FROM flow_messages m WHERE m.id IN ( SELECT id FROM ( SELECT id, ROW_NUMBER() OVER (PARTITION BY contact_id ORDER BY created_at DESC) as rn FROM flow_messages WHERE tenant_id = :tenantId ) t WHERE t.rn = 1 ) ORDER BY m.created_at DESC ", nativeQuery = true)
abstract fun findLatestMessagesByTenant(tenantId: String, pageable: Pageable): Page<Message>

Busca a última mensagem de cada contato do Tenant. Essa query usa Window Function (ROW_NUMBER) para performance extrema no PostgreSQL. Retorna apenas a mensagem mais recente de cada contact_id.

Link copied to clipboard
abstract fun <S : Message> findOne(example: Example<S>): Optional<S>
Link copied to clipboard
abstract fun flush()
Link copied to clipboard
abstract fun getById(id: String): Message
Link copied to clipboard
abstract fun getOne(id: String): Message
Link copied to clipboard
abstract fun getReferenceById(id: String): Message
Link copied to clipboard
@Modifying
@Query(value = "UPDATE Message m SET m.status = 'READ' WHERE m.contactId = :contactId AND m.direction = 'INBOUND' AND m.status != 'READ'")
abstract fun markAllAsReadForContact(contactId: String)
Link copied to clipboard
abstract fun <S : Message> save(entity: S): S
Link copied to clipboard
abstract override fun <S : Message> saveAll(entities: MutableIterable<S>): MutableList<S>
Link copied to clipboard
abstract fun <S : Message> saveAllAndFlush(entities: MutableIterable<S>): MutableList<S>
Link copied to clipboard
abstract fun <S : Message> saveAndFlush(entity: S): S