Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Add method to be able to delete a transfer #98

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading