diff --git a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/TransferManager.kt b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/TransferManager.kt index 98f76188..5883b5fe 100644 --- a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/TransferManager.kt +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/TransferManager.kt @@ -76,6 +76,11 @@ class TransferManager internal constructor( .flowOn(Dispatchers.IO) } + @Throws(RealmException::class) + fun getTransferFlow(transferUUID: String): Flow { + return transferController.getTransferFlow(transferUUID) + } + /** * Update all pending transfers in database, most transfers are in [TransferStatus.WAIT_VIRUS_CHECK] status. */ diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/TransferController.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/TransferController.kt index 2ba6ff63..9003ceba 100644 --- a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/TransferController.kt +++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/TransferController.kt @@ -25,9 +25,11 @@ import com.infomaniak.multiplatform_swisstransfer.common.models.TransferStatus import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider import com.infomaniak.multiplatform_swisstransfer.database.models.transfers.TransferDB import com.infomaniak.multiplatform_swisstransfer.database.utils.RealmUtils.runThrowingRealm +import io.realm.kotlin.Realm import io.realm.kotlin.UpdatePolicy import io.realm.kotlin.ext.query import io.realm.kotlin.query.RealmResults +import io.realm.kotlin.query.RealmSingleQuery import io.realm.kotlin.query.Sort import io.realm.kotlin.query.TRUE_PREDICATE import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -55,9 +57,14 @@ class TransferController(private val realmProvider: RealmProvider) { return getTransfers(transferDirection).asFlow().mapLatest { it.list } } + @Throws(RealmException::class) + fun getTransferFlow(linkUUID: String): Flow = runThrowingRealm { + return getTransferQuery(realm, linkUUID).asFlow().mapLatest { it.obj } + } + @Throws(RealmException::class) fun getTransfer(linkUUID: String): Transfer? = runThrowingRealm { - return realm.query("${TransferDB::linkUUID.name} == '$linkUUID'").first().find() + return getTransferQuery(realm, linkUUID).find() } @Throws(RealmException::class) @@ -93,4 +100,11 @@ class TransferController(private val realmProvider: RealmProvider) { realm.write { deleteAll() } } //endregion + + private companion object { + + private fun getTransferQuery(realm: Realm, linkUUID: String): RealmSingleQuery { + return realm.query("${TransferDB::linkUUID.name} == '$linkUUID'").first() + } + } }