From eb99d90cbdb97bc1f65ca85e4186b8a2f768181f Mon Sep 17 00:00:00 2001 From: Kevin Boulongne Date: Wed, 9 Oct 2024 11:47:53 +0200 Subject: [PATCH] feat: Add `UploadController.getUploadsCount()` function --- .../database/cache/setting/AppSettingsController.kt | 2 ++ .../database/cache/setting/TransfersController.kt | 3 +-- .../database/cache/setting/UploadController.kt | 12 +++++++++--- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/AppSettingsController.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/AppSettingsController.kt index 822f5775..f666cb92 100644 --- a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/AppSettingsController.kt +++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/AppSettingsController.kt @@ -37,6 +37,7 @@ class AppSettingsController(private val realmProvider: RealmProvider) { private val appSettingsQuery get() = realm.query().first() + @Throws(IllegalArgumentException::class, CancellationException::class) suspend fun initAppSettings() { if (appSettingsQuery.find() == null) { realm.write { @@ -46,6 +47,7 @@ class AppSettingsController(private val realmProvider: RealmProvider) { } //region Get data + @Throws(IllegalArgumentException::class, CancellationException::class) fun getAppSettingsFlow(): Flow { return appSettingsQuery.asFlow().mapLatest { it.obj } } diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/TransfersController.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/TransfersController.kt index 0a6a7b74..b1c8dd73 100644 --- a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/TransfersController.kt +++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/TransfersController.kt @@ -21,15 +21,14 @@ import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider import com.infomaniak.multiplatform_swisstransfer.database.models.transfers.TransferDB import io.realm.kotlin.ext.query import io.realm.kotlin.query.RealmResults -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlin.coroutines.cancellation.CancellationException -@OptIn(ExperimentalCoroutinesApi::class) class TransfersController(private val realmProvider: RealmProvider) { private val realm by lazy { realmProvider.realmTransfers } //region Get data + @Throws(IllegalArgumentException::class, CancellationException::class) fun getTransfers(): RealmResults? = realm?.query()?.find() //endregion diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/UploadController.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/UploadController.kt index c818d49c..c4cb3c64 100644 --- a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/UploadController.kt +++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/UploadController.kt @@ -21,16 +21,22 @@ import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider import com.infomaniak.multiplatform_swisstransfer.database.models.upload.Upload import io.realm.kotlin.ext.query import io.realm.kotlin.query.RealmResults -import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlin.coroutines.cancellation.CancellationException -@OptIn(ExperimentalCoroutinesApi::class) class UploadController(private val realmProvider: RealmProvider) { private val realm by lazy { realmProvider.realmUploads } + //region Queries + private fun getUploadsQuery() = realm.query() + //endregion + //region Get data - fun getUploads(): RealmResults = realm.query().find() + @Throws(IllegalArgumentException::class, CancellationException::class) + fun getUploads(): RealmResults = getUploadsQuery().find() + + @Throws(IllegalArgumentException::class, CancellationException::class) + fun getUploadsCount(): Long = getUploadsQuery().count().find() //endregion //region Update data