Skip to content

Commit

Permalink
feat: Add the transfer to the database if upload finish with success
Browse files Browse the repository at this point in the history
  • Loading branch information
sirambd committed Oct 22, 2024
1 parent 5cf20ba commit 2ed95ac
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class SwissTransferInjection {
val accountManager by lazy { AccountManager(appSettingsController, uploadController, transferController, realmProvider) }

/** A manager used to orchestrate Uploads operations. */
val uploadManager by lazy { UploadManager(uploadController, uploadRepository) }
val uploadManager by lazy { UploadManager(uploadController, uploadRepository, transferManager) }

/** An utils to help use shared routes */
val sharedApiUrlCreator by lazy { SharedApiUrlCreator(transferController, uploadController) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ import kotlin.coroutines.cancellation.CancellationException
*
* @property uploadController The controller for managing upload data in the database.
* @property uploadRepository The repository for interacting with the SwissTransfer API for uploads.
* @property transferManager Transfer operations
*/
class UploadManager(
private val uploadController: UploadController,
private val uploadRepository: UploadRepository,
private val transferManager: TransferManager,
) {

/**
Expand Down Expand Up @@ -184,7 +186,7 @@ class UploadManager(
}

/**
* Finishes an upload session.
* Finishes an upload session and add the transfer to the database .
*
* This method retrieves an upload session from the database using the provided `uuid`.
* If the session is found and has a remote container UUID, it creates a `FinishUploadBody` object
Expand Down Expand Up @@ -217,7 +219,12 @@ class UploadManager(
language = uploadSession.language.code,
recipientsEmails = uploadSession.recipientsEmails,
)
uploadRepository.finishUpload(finishUploadBody)
uploadController.removeUploadSession(containerUUID)
val finishUploadResponse = runCatching {
uploadRepository.finishUpload(finishUploadBody).first()
}.getOrElse { throw UnknownException(it) }
uploadController.removeUploadSession(uploadSession.uuid)

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.
}
}

0 comments on commit 2ed95ac

Please sign in to comment.