Skip to content

Commit

Permalink
Merge pull request #118 from Infomaniak/take-enum-for-language
Browse files Browse the repository at this point in the history
feat: Expose verifyEmailCode and resendEmailCode through UploadManager and simplify arguments
  • Loading branch information
sirambd authored Dec 12, 2024
2 parents a281760 + 550d5a8 commit a100628
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ 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
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.flow.flowOn
Expand All @@ -54,6 +55,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)
Expand Down Expand Up @@ -314,6 +316,30 @@ class UploadManager(
uploadController.removeData()
}

@Throws(
CancellationException::class,
EmailValidationException::class,
ApiException::class,
NetworkException::class,
UnexpectedApiErrorFormatException::class,
UnknownException::class,
)
suspend fun verifyEmailCode(code: String, address: String): AuthorEmailToken {
return uploadRepository.verifyEmailCode(VerifyEmailCodeBody(code, address))
}

@Throws(
CancellationException::class,
ApiException::class,
NetworkException::class,
UnexpectedApiErrorFormatException::class,
UnknownException::class,
)
suspend fun resendEmailCode(address: String) {
val language = emailLanguageUtils.getEmailLanguageFromLocal()
uploadRepository.resendEmailCode(ResendEmailCodeBody(address, language.code))
}

private suspend fun addTransferByLinkUUID(
finishUploadResponse: UploadCompleteResponse,
uploadSession: UploadSession,
Expand Down

0 comments on commit a100628

Please sign in to comment.