From d3bf76f7f35fc00ff2a3eac39f41f594e401d716 Mon Sep 17 00:00:00 2001 From: Gibran Chevalley Date: Thu, 12 Dec 2024 11:04:11 +0100 Subject: [PATCH 1/3] feat: Add resendEmailCode method in UploadManager and automatically detect language --- .../SwissTransferInjection.kt | 2 +- .../managers/UploadManager.kt | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/SwissTransferInjection.kt b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/SwissTransferInjection.kt index a4e83305..8875e994 100644 --- a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/SwissTransferInjection.kt +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/SwissTransferInjection.kt @@ -83,7 +83,7 @@ class SwissTransferInjection( } /** A manager used to orchestrate Uploads operations. */ - val uploadManager by lazy { UploadManager(uploadController, uploadRepository, transferManager) } + val uploadManager by lazy { UploadManager(uploadController, uploadRepository, transferManager, emailLanguageUtils) } /** An utils to help use shared routes */ val sharedApiUrlCreator by lazy { SharedApiUrlCreator(transferController, uploadController) } 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 1d3a895d..1d7e4859 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 @@ -32,8 +32,10 @@ import com.infomaniak.multiplatform_swisstransfer.network.exceptions.NetworkExce import com.infomaniak.multiplatform_swisstransfer.network.exceptions.UnexpectedApiErrorFormatException import com.infomaniak.multiplatform_swisstransfer.network.models.upload.request.FinishUploadBody import com.infomaniak.multiplatform_swisstransfer.network.models.upload.request.InitUploadBody +import com.infomaniak.multiplatform_swisstransfer.network.models.upload.request.ResendEmailCodeBody import com.infomaniak.multiplatform_swisstransfer.network.models.upload.response.UploadCompleteResponse import com.infomaniak.multiplatform_swisstransfer.network.repositories.UploadRepository +import com.infomaniak.multiplatform_swisstransfer.utils.EmailLanguageUtils import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.IO import kotlinx.coroutines.flow.flowOn @@ -54,6 +56,7 @@ class UploadManager( private val uploadController: UploadController, private val uploadRepository: UploadRepository, private val transferManager: TransferManager, + private val emailLanguageUtils: EmailLanguageUtils, ) { val lastUploadFlow get() = uploadController.getLastUploadFlow().flowOn(Dispatchers.IO) @@ -314,6 +317,18 @@ class UploadManager( uploadController.removeData() } + @Throws( + CancellationException::class, + ApiException::class, + NetworkException::class, + UnexpectedApiErrorFormatException::class, + UnknownException::class, + ) + suspend fun resendEmailCode(emailAddress: String) { + val language = emailLanguageUtils.getEmailLanguageFromLocal() + uploadRepository.resendEmailCode(ResendEmailCodeBody(emailAddress, language.code)) + } + private suspend fun addTransferByLinkUUID( finishUploadResponse: UploadCompleteResponse, uploadSession: UploadSession, From e267d0ab27cece89cd9ba4d4097ae49ca58dc404 Mon Sep 17 00:00:00 2001 From: Gibran Chevalley Date: Thu, 12 Dec 2024 11:08:24 +0100 Subject: [PATCH 2/3] feat: Expose verifyEmailCode through the UploadManager like other methods --- .../managers/UploadManager.kt | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) 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 1d7e4859..b57fd396 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 @@ -26,13 +26,12 @@ import com.infomaniak.multiplatform_swisstransfer.data.NewUploadSession import com.infomaniak.multiplatform_swisstransfer.database.controllers.UploadController import com.infomaniak.multiplatform_swisstransfer.exceptions.NotFoundException import com.infomaniak.multiplatform_swisstransfer.exceptions.NullPropertyException -import com.infomaniak.multiplatform_swisstransfer.network.exceptions.ApiException -import com.infomaniak.multiplatform_swisstransfer.network.exceptions.ContainerErrorsException -import com.infomaniak.multiplatform_swisstransfer.network.exceptions.NetworkException -import com.infomaniak.multiplatform_swisstransfer.network.exceptions.UnexpectedApiErrorFormatException +import com.infomaniak.multiplatform_swisstransfer.network.exceptions.* import com.infomaniak.multiplatform_swisstransfer.network.models.upload.request.FinishUploadBody import com.infomaniak.multiplatform_swisstransfer.network.models.upload.request.InitUploadBody import com.infomaniak.multiplatform_swisstransfer.network.models.upload.request.ResendEmailCodeBody +import com.infomaniak.multiplatform_swisstransfer.network.models.upload.request.VerifyEmailCodeBody +import com.infomaniak.multiplatform_swisstransfer.network.models.upload.response.AuthorEmailToken import com.infomaniak.multiplatform_swisstransfer.network.models.upload.response.UploadCompleteResponse import com.infomaniak.multiplatform_swisstransfer.network.repositories.UploadRepository import com.infomaniak.multiplatform_swisstransfer.utils.EmailLanguageUtils @@ -317,6 +316,18 @@ class UploadManager( uploadController.removeData() } + @Throws( + CancellationException::class, + EmailValidationException::class, + ApiException::class, + NetworkException::class, + UnexpectedApiErrorFormatException::class, + UnknownException::class, + ) + suspend fun verifyEmailCode(code: String, email: String): AuthorEmailToken { + return uploadRepository.verifyEmailCode(VerifyEmailCodeBody(code, email)) + } + @Throws( CancellationException::class, ApiException::class, From 550d5a89cdf904b63e31f020468b665b26add211 Mon Sep 17 00:00:00 2001 From: Gibran Chevalley Date: Thu, 12 Dec 2024 11:22:12 +0100 Subject: [PATCH 3/3] refactor: Make "address" argument names coherent between the two methods --- .../multiplatform_swisstransfer/managers/UploadManager.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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 b57fd396..56e0c41a 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 @@ -324,8 +324,8 @@ class UploadManager( UnexpectedApiErrorFormatException::class, UnknownException::class, ) - suspend fun verifyEmailCode(code: String, email: String): AuthorEmailToken { - return uploadRepository.verifyEmailCode(VerifyEmailCodeBody(code, email)) + suspend fun verifyEmailCode(code: String, address: String): AuthorEmailToken { + return uploadRepository.verifyEmailCode(VerifyEmailCodeBody(code, address)) } @Throws( @@ -335,9 +335,9 @@ class UploadManager( UnexpectedApiErrorFormatException::class, UnknownException::class, ) - suspend fun resendEmailCode(emailAddress: String) { + suspend fun resendEmailCode(address: String) { val language = emailLanguageUtils.getEmailLanguageFromLocal() - uploadRepository.resendEmailCode(ResendEmailCodeBody(emailAddress, language.code)) + uploadRepository.resendEmailCode(ResendEmailCodeBody(address, language.code)) } private suspend fun addTransferByLinkUUID(