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

feat: Expose verifyEmailCode and resendEmailCode through UploadManager and simplify arguments #118

Merged
merged 3 commits into from
Dec 12, 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 @@ -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
Loading