Skip to content

Commit

Permalink
Merge pull request #98 from Infomaniak/add-delete-transfer-manager
Browse files Browse the repository at this point in the history
chore: Add method to be able to delete a transfer
  • Loading branch information
tevincent authored Nov 22, 2024
2 parents d42a355 + 252adff commit 77f707b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,3 @@ interface File {
val path: String?
val thumbnailPath: String?
}

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>("${TransferDB::linkUUID.name} == '$transferUUID'").first()
delete(transferToDelete)
}
}

@Throws(RealmException::class, CancellationException::class)
suspend fun removeData() = runThrowingRealm {
realm.write { deleteAll() }
Expand Down

0 comments on commit 77f707b

Please sign in to comment.