diff --git a/STCommon/src/androidMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/ext/JavaDateExt.kt b/STCommon/src/androidMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/ext/JavaDateExt.kt index d8d52726..283f1282 100644 --- a/STCommon/src/androidMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/ext/JavaDateExt.kt +++ b/STCommon/src/androidMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/ext/JavaDateExt.kt @@ -19,4 +19,4 @@ package com.infomaniak.multiplatform_swisstransfer.common.ext import java.util.Date -fun Long.toDateFromSeconds() = Date(this * 1000) +fun Long.toDateFromSeconds() = Date(this * 1_000L) diff --git a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/transfers/File.kt b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/transfers/File.kt index 1eba5336..085ccf66 100644 --- a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/transfers/File.kt +++ b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/transfers/File.kt @@ -32,4 +32,3 @@ interface File { val path: String? val thumbnailPath: String? } - 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 86523c0a..143b643d 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 @@ -141,6 +141,7 @@ class TransferManager internal constructor( * @throws UnexpectedApiErrorFormatException Unparsable api error response. * @throws NetworkException If there is a network issue during the transfer retrieval. * @throws UnknownException Any error not already handled by the above ones. + * @throws RealmException An error has occurred with realm database */ @Throws( CancellationException::class, @@ -172,6 +173,7 @@ class TransferManager internal constructor( * @throws UnexpectedApiErrorFormatException Unparsable api error response. * @throws NetworkException If there is a network issue during the transfer retrieval. * @throws UnknownException Any error not already handled by the above ones. + * @throws RealmException An error has occurred with realm database */ @Throws( CancellationException::class, @@ -187,6 +189,19 @@ class TransferManager internal constructor( return@withContext transferApi.linkUUID } + /** + * Delete a transfer by its UUID. + * + * @param transferUUID The UUID of the transfer to be removed. + * + * @throws CancellationException If the operation is cancelled. + * @throws RealmException An error has occurred with realm database + */ + @Throws(RealmException::class, CancellationException::class) + suspend fun deleteTransfer(transferUUID: String) { + transferController.deleteTransfer(transferUUID) + } + private suspend fun addTransfer(transferApi: TransferApi?, transferDirection: TransferDirection) { runCatching { transferController.upsert(transferApi as Transfer, transferDirection) 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 eb10f120..013d92f1 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 @@ -95,6 +95,14 @@ class TransferController(private val realmProvider: RealmProvider) { //endregion //region Update data + @Throws(RealmException::class, CancellationException::class) + suspend fun deleteTransfer(transferUUID: String) = runThrowingRealm { + realm.write { + val transferToDelete = query("${TransferDB::linkUUID.name} == '$transferUUID'").first() + delete(transferToDelete) + } + } + @Throws(RealmException::class, CancellationException::class) suspend fun removeData() = runThrowingRealm { realm.write { deleteAll() }