Skip to content

Commit

Permalink
chore: Use directly the token instead of object
Browse files Browse the repository at this point in the history
There's really no point in sending a whole object when all you need is the token.
  • Loading branch information
sirambd committed Dec 23, 2024
1 parent 1cd1885 commit 6119b99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package com.infomaniak.multiplatform_swisstransfer.managers

import com.infomaniak.multiplatform_swisstransfer.common.exceptions.RealmException
import com.infomaniak.multiplatform_swisstransfer.database.controllers.EmailTokensController
import com.infomaniak.multiplatform_swisstransfer.network.models.upload.response.AuthorEmailToken
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.IO
import kotlinx.coroutines.withContext
Expand All @@ -46,13 +45,13 @@ class EmailTokensManager(private val emailTokensController: EmailTokensControlle
* Asynchronously sets the email and it's corresponding token.
*
* @param email The validated email.
* @param authorEmailToken The valid token associated to the email.
* @param emailToken The valid token associated to the email.
*
* @throws RealmException If an error occurs during database access.
* @throws CancellationException If the operation is cancelled.
*/
@Throws(RealmException::class, CancellationException::class)
suspend fun setEmailToken(email: String, authorEmailToken: AuthorEmailToken): Unit = withContext(Dispatchers.IO) {
emailTokensController.setEmailToken(email, authorEmailToken.token)
suspend fun setEmailToken(email: String, emailToken: String): Unit = withContext(Dispatchers.IO) {
emailTokensController.setEmailToken(email, emailToken)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ class UploadManager(
* Stores the email address token in DB for future uses and updates the
* current uploadSession stored in DB with this new email address token.
*
* @param authorEmail The email to which the [authorEmailToken] is associated with.
* @param authorEmailToken The token returned by the API that proves the user owns [authorEmail].
* @param authorEmail The email to which the [emailToken] is associated with.
* @param emailToken The token returned by the API that proves the user owns [authorEmail].
*
* @throws RealmException If an error occurs during database access.
* @throws CancellationException If the operation is cancelled.
* @throws NotFoundException If we can't find any upload to update.
*/
@Throws(RealmException::class, CancellationException::class, NotFoundException::class)
suspend fun updateAuthorEmailToken(authorEmail: String, authorEmailToken: AuthorEmailToken) {
emailTokensManager.setEmailToken(authorEmail, authorEmailToken)
suspend fun updateAuthorEmailToken(authorEmail: String, emailToken: String) {
emailTokensManager.setEmailToken(authorEmail, emailToken)

runCatching {
uploadController.updateLastUploadSessionAuthorEmailToken(authorEmailToken.token)
uploadController.updateLastUploadSessionAuthorEmailToken(emailToken)
}.onFailure {
when (it) {
is NoSuchElementException -> throw NotFoundException(it.message ?: "")
Expand Down

0 comments on commit 6119b99

Please sign in to comment.