From 7a53fb9ea3dbf0f9e3d288dd193e7ffa0f402e99 Mon Sep 17 00:00:00 2001 From: Abdourahamane Boinaidi Date: Thu, 24 Oct 2024 14:35:40 +0200 Subject: [PATCH] feat: Retrieve the last uploaded transfer --- .../managers/TransferManager.kt | 11 +++++++++++ .../managers/UploadManager.kt | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) 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 ed6f65ab..1b33d920 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 @@ -72,6 +72,17 @@ class TransferManager internal constructor( .flowOn(Dispatchers.IO) } + /** + * Retrieves a transfer by linkUUID. + * + * @param transferUUID The UUID of an existing transfer in the database. + * + * @return A transfer matching the specified linkUUID or null. + */ + fun getTransferByLinkUUID(transferUUID: String): Transfer? { + return transferController.getTransfer(transferUUID) + } + /** * Retrieves a transfer using the provided link UUID and saves it to the database. * diff --git a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/UploadManager.kt b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/UploadManager.kt index 58d02cfe..92b997d8 100644 --- a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/UploadManager.kt +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/UploadManager.kt @@ -201,6 +201,8 @@ class UploadManager( * * @param uuid The UUID of the upload session. * + * @return The transfer UUID of the uploaded transfer. + * * @throws CancellationException If the operation is cancelled. * @throws ApiException If there is a general API error. * @throws UnexpectedApiErrorFormatException If the API error format is unexpected. @@ -220,7 +222,7 @@ class UploadManager( NotFoundException::class, NullPropertyException::class, ) - suspend fun finishUploadSession(uuid: String): Unit = withContext(Dispatchers.IO) { + suspend fun finishUploadSession(uuid: String): String = withContext(Dispatchers.IO) { val uploadSession = uploadController.getUploadByUUID(uuid) ?: throw NotFoundException("Unknown upload session with uuid = $uuid") val containerUUID = uploadSession.remoteContainer?.uuid @@ -238,5 +240,7 @@ class UploadManager( transferManager.addTransferByLinkUUID(finishUploadResponse.linkUUID) // TODO: If we can't retrieve the transfer cause of the Internet, we should put it in Realm and try again later. + + return@withContext finishUploadResponse.linkUUID } }