feat: get queued packets from database

This commit is contained in:
andrekir 2023-01-12 17:47:59 -03:00
parent 5a07998b73
commit d23584c283
3 changed files with 18 additions and 12 deletions

View file

@ -18,6 +18,10 @@ class PacketRepository @Inject constructor(private val packetDaoLazy: dagger.Laz
packetDao.getAllPackets()
}
suspend fun getQueuedPackets(): List<DataPacket>? = withContext(Dispatchers.IO) {
packetDao.getQueuedPackets()
}
suspend fun insert(packet: Packet) = withContext(Dispatchers.IO) {
packetDao.insert(packet)
}

View file

@ -48,11 +48,15 @@ interface PacketDao {
findDataPacket(data)?.let { update(it.copy(data = new)) }
}
@Query("Select data from packet")
@Query("Select data from packet order by received_time asc")
fun getDataPackets(): List<DataPacket>
@Transaction
fun getDataPacketById(requestId: Int): DataPacket? {
return getDataPackets().firstOrNull { it.id == requestId }
}
@Transaction
fun getQueuedPackets(): List<DataPacket>? =
getDataPackets().filter { it.status in setOf(MessageStatus.ENROUTE, MessageStatus.QUEUED) }
}