From e530734a028205e094a6896fab5926f47c6345e1 Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Wed, 11 Dec 2024 14:29:01 +0100 Subject: [PATCH 1/7] feat: Save EmailToken in AppSettings --- .../interfaces/appSettings/EmailToken.kt | 23 +++++++++++++ .../database/RealmProvider.kt | 3 +- .../controllers/AppSettingsController.kt | 19 +++++++++++ .../models/appSettings/EmailTokenDB.kt | 33 +++++++++++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/appSettings/EmailToken.kt create mode 100644 STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/appSettings/EmailTokenDB.kt diff --git a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/appSettings/EmailToken.kt b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/appSettings/EmailToken.kt new file mode 100644 index 00000000..3aed2c25 --- /dev/null +++ b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/appSettings/EmailToken.kt @@ -0,0 +1,23 @@ +/* + * Infomaniak SwissTransfer - Multiplatform + * Copyright (C) 2024 Infomaniak Network SA + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings + +interface EmailToken { + val email: String + val token: String +} \ No newline at end of file diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/RealmProvider.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/RealmProvider.kt index bb48e191..be5d02b0 100644 --- a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/RealmProvider.kt +++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/RealmProvider.kt @@ -18,6 +18,7 @@ package com.infomaniak.multiplatform_swisstransfer.database import com.infomaniak.multiplatform_swisstransfer.database.models.appSettings.AppSettingsDB +import com.infomaniak.multiplatform_swisstransfer.database.models.appSettings.EmailTokenDB import com.infomaniak.multiplatform_swisstransfer.database.models.transfers.ContainerDB import com.infomaniak.multiplatform_swisstransfer.database.models.transfers.FileDB import com.infomaniak.multiplatform_swisstransfer.database.models.transfers.TransferDB @@ -58,7 +59,7 @@ class RealmProvider(private val loadDataInMemory: Boolean = false) { } private val realmAppSettingsConfiguration = RealmConfiguration - .Builder(schema = setOf(AppSettingsDB::class)) + .Builder(schema = setOf(AppSettingsDB::class, EmailTokenDB::class)) .name("AppSettings.realm") .deleteRealmDataIfNeeded() .loadDataInMemoryIfNeeded() diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt index 4fce1a5d..deadc8fa 100644 --- a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt +++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt @@ -19,9 +19,14 @@ package com.infomaniak.multiplatform_swisstransfer.database.controllers import com.infomaniak.multiplatform_swisstransfer.common.exceptions.RealmException import com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings.AppSettings +import com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings.EmailToken +import com.infomaniak.multiplatform_swisstransfer.common.interfaces.transfers.File import com.infomaniak.multiplatform_swisstransfer.common.models.* import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider import com.infomaniak.multiplatform_swisstransfer.database.models.appSettings.AppSettingsDB +import com.infomaniak.multiplatform_swisstransfer.database.models.appSettings.EmailTokenDB +import com.infomaniak.multiplatform_swisstransfer.database.models.transfers.FileDB +import com.infomaniak.multiplatform_swisstransfer.database.models.transfers.TransferDB import com.infomaniak.multiplatform_swisstransfer.database.utils.RealmUtils.runThrowingRealm import io.realm.kotlin.UpdatePolicy import io.realm.kotlin.ext.query @@ -56,6 +61,12 @@ class AppSettingsController(private val realmProvider: RealmProvider) { fun getAppSettings(): AppSettings? = runThrowingRealm { return appSettingsQuery.find() } + + @Throws(RealmException::class) + fun getTokenForEmail(email: String): String? = runThrowingRealm { + val query = "${EmailTokenDB::email} == '$email'" + return realm.query(query).first().find()?.token + } //endregion //region Update data @@ -116,5 +127,13 @@ class AppSettingsController(private val realmProvider: RealmProvider) { suspend fun removeData() = runThrowingRealm { realm.write { deleteAll() } } + + @Throws(RealmException::class, CancellationException::class) + suspend fun setEmailToken(email: String, token: String) = runThrowingRealm { + realm.write { + val emailTokenDB = EmailTokenDB(email, token) + copyToRealm(emailTokenDB, UpdatePolicy.ALL) + } + } //endregion } diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/appSettings/EmailTokenDB.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/appSettings/EmailTokenDB.kt new file mode 100644 index 00000000..4a2a56b1 --- /dev/null +++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/models/appSettings/EmailTokenDB.kt @@ -0,0 +1,33 @@ +/* + * Infomaniak SwissTransfer - Multiplatform + * Copyright (C) 2024 Infomaniak Network SA + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.infomaniak.multiplatform_swisstransfer.database.models.appSettings + +import com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings.EmailToken +import io.realm.kotlin.types.RealmObject +import io.realm.kotlin.types.annotations.PrimaryKey + +class EmailTokenDB() : RealmObject, EmailToken { + @PrimaryKey + override var email: String = "" + override var token: String = "" + + constructor(email: String, token: String) : this() { + this.email = email + this.token = token + } +} From 3cfba579c6448cd05560a1d1678d1f00c6a7ae2d Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Wed, 11 Dec 2024 15:42:20 +0100 Subject: [PATCH 2/7] feat: Expose AppSettings controller in manager --- .../managers/AppSettingsManager.kt | 25 +++++++++++++++++++ .../controllers/AppSettingsController.kt | 6 ++--- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/AppSettingsManager.kt b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/AppSettingsManager.kt index 365fb613..997be267 100644 --- a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/AppSettingsManager.kt +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/AppSettingsManager.kt @@ -123,4 +123,29 @@ class AppSettingsManager internal constructor( suspend fun setLastAuthorEmail(authorEmail: String?): Unit = withContext(Dispatchers.IO) { appSettingsController.setLastAuthorEmail(authorEmail) } + + /** + * Asynchronously sets the email and it's corresponding token. + * + * @param email The validated email. + * @param token 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, token: String): Unit = withContext(Dispatchers.IO) { + appSettingsController.setEmailToken(email, token) + } + + /** + * Get a token for a given email. + * + * @param email The email possibly associated with a token. + * + * @return A token which may be associated with the email. + */ + fun getTokenForEmail(email: String): String? { + return appSettingsController.getEmailTokenForEmail(email)?.token + } } diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt index deadc8fa..ca6cc0a9 100644 --- a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt +++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt @@ -63,9 +63,9 @@ class AppSettingsController(private val realmProvider: RealmProvider) { } @Throws(RealmException::class) - fun getTokenForEmail(email: String): String? = runThrowingRealm { - val query = "${EmailTokenDB::email} == '$email'" - return realm.query(query).first().find()?.token + fun getEmailTokenForEmail(email: String): EmailToken? = runThrowingRealm { + val query = "${EmailTokenDB::email.name} == '$email'" + return realm.query(query).first().find() } //endregion From 65a4e46aff920a8dcff71f5108a7b26ce11a410c Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Thu, 12 Dec 2024 08:32:53 +0100 Subject: [PATCH 3/7] refactor: Move logic to EmailTokensManager --- .../SwissTransferInjection.kt | 10 ++-- .../managers/AppSettingsManager.kt | 25 --------- .../managers/EmailTokensManager.kt | 54 +++++++++++++++++++ .../controllers/AppSettingsController.kt | 13 ----- .../controllers/EmailTokensController.kt | 49 +++++++++++++++++ 5 files changed, 109 insertions(+), 42 deletions(-) create mode 100644 STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/EmailTokensManager.kt create mode 100644 STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/EmailTokensController.kt 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 a68c282c..a4e83305 100644 --- a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/SwissTransferInjection.kt +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/SwissTransferInjection.kt @@ -18,10 +18,7 @@ package com.infomaniak.multiplatform_swisstransfer import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider -import com.infomaniak.multiplatform_swisstransfer.database.controllers.AppSettingsController -import com.infomaniak.multiplatform_swisstransfer.database.controllers.FileController -import com.infomaniak.multiplatform_swisstransfer.database.controllers.TransferController -import com.infomaniak.multiplatform_swisstransfer.database.controllers.UploadController +import com.infomaniak.multiplatform_swisstransfer.database.controllers.* import com.infomaniak.multiplatform_swisstransfer.managers.* import com.infomaniak.multiplatform_swisstransfer.network.ApiClientProvider import com.infomaniak.multiplatform_swisstransfer.network.repositories.TransferRepository @@ -41,6 +38,7 @@ import com.infomaniak.multiplatform_swisstransfer.utils.EmailLanguageUtils * @property appSettingsManager A manager used to orchestrate AppSettings operations. * @property accountManager A manager used to orchestrate Accounts operations. * @property uploadManager A manager used to orchestrate Uploads operations. + * @property emailTokensManager A manager used to orchestrate EmailTokens operations. * @property sharedApiUrlCreator An utils to help use shared routes. */ class SwissTransferInjection( @@ -54,6 +52,7 @@ class SwissTransferInjection( private val transferRepository by lazy { TransferRepository(apiClientProvider) } private val appSettingsController by lazy { AppSettingsController(realmProvider) } + private val emailTokensController by lazy { EmailTokensController(realmProvider) } private val uploadController by lazy { UploadController(realmProvider) } private val transferController by lazy { TransferController(realmProvider) } private val fileController by lazy { FileController(realmProvider) } @@ -69,6 +68,9 @@ class SwissTransferInjection( /** A manager used to orchestrate AppSettings operations. */ val appSettingsManager by lazy { AppSettingsManager(appSettingsController) } + /** A manager used to orchestrate EmailTokens operations. */ + val emailTokensManager by lazy { EmailTokensManager(emailTokensController) } + /** A manager used to orchestrate Accounts operations. */ val accountManager by lazy { AccountManager( diff --git a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/AppSettingsManager.kt b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/AppSettingsManager.kt index 997be267..365fb613 100644 --- a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/AppSettingsManager.kt +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/AppSettingsManager.kt @@ -123,29 +123,4 @@ class AppSettingsManager internal constructor( suspend fun setLastAuthorEmail(authorEmail: String?): Unit = withContext(Dispatchers.IO) { appSettingsController.setLastAuthorEmail(authorEmail) } - - /** - * Asynchronously sets the email and it's corresponding token. - * - * @param email The validated email. - * @param token 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, token: String): Unit = withContext(Dispatchers.IO) { - appSettingsController.setEmailToken(email, token) - } - - /** - * Get a token for a given email. - * - * @param email The email possibly associated with a token. - * - * @return A token which may be associated with the email. - */ - fun getTokenForEmail(email: String): String? { - return appSettingsController.getEmailTokenForEmail(email)?.token - } } diff --git a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/EmailTokensManager.kt b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/EmailTokensManager.kt new file mode 100644 index 00000000..167126ee --- /dev/null +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/EmailTokensManager.kt @@ -0,0 +1,54 @@ +/* + * Infomaniak SwissTransfer - Multiplatform + * Copyright (C) 2024 Infomaniak Network SA + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.infomaniak.multiplatform_swisstransfer.managers + +import com.infomaniak.multiplatform_swisstransfer.common.exceptions.RealmException +import com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings.EmailToken +import com.infomaniak.multiplatform_swisstransfer.database.controllers.EmailTokensController +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.IO +import kotlinx.coroutines.withContext +import kotlin.coroutines.cancellation.CancellationException + +class EmailTokensManager(private val emailTokensController: EmailTokensController) { + + /** + * Get a token for a given email. + * + * @param email The email possibly associated with a token. + * + * @return A token which may be associated with the email. + */ + fun getEmailTokenForEmail(email: String): EmailToken? { + return emailTokensController.getEmailTokenForEmail(email) + } + + /** + * Asynchronously sets the email and it's corresponding token. + * + * @param email The validated email. + * @param token 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, token: String): Unit = withContext(Dispatchers.IO) { + emailTokensController.setEmailToken(email, token) + } +} diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt index ca6cc0a9..d4664121 100644 --- a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt +++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt @@ -62,11 +62,6 @@ class AppSettingsController(private val realmProvider: RealmProvider) { return appSettingsQuery.find() } - @Throws(RealmException::class) - fun getEmailTokenForEmail(email: String): EmailToken? = runThrowingRealm { - val query = "${EmailTokenDB::email.name} == '$email'" - return realm.query(query).first().find() - } //endregion //region Update data @@ -127,13 +122,5 @@ class AppSettingsController(private val realmProvider: RealmProvider) { suspend fun removeData() = runThrowingRealm { realm.write { deleteAll() } } - - @Throws(RealmException::class, CancellationException::class) - suspend fun setEmailToken(email: String, token: String) = runThrowingRealm { - realm.write { - val emailTokenDB = EmailTokenDB(email, token) - copyToRealm(emailTokenDB, UpdatePolicy.ALL) - } - } //endregion } diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/EmailTokensController.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/EmailTokensController.kt new file mode 100644 index 00000000..80c71e42 --- /dev/null +++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/EmailTokensController.kt @@ -0,0 +1,49 @@ +/* + * Infomaniak SwissTransfer - Multiplatform + * Copyright (C) 2024 Infomaniak Network SA + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.infomaniak.multiplatform_swisstransfer.database.controllers + +import com.infomaniak.multiplatform_swisstransfer.common.exceptions.RealmException +import com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings.EmailToken +import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider +import com.infomaniak.multiplatform_swisstransfer.database.models.appSettings.EmailTokenDB +import com.infomaniak.multiplatform_swisstransfer.database.utils.RealmUtils.runThrowingRealm +import io.realm.kotlin.UpdatePolicy +import io.realm.kotlin.ext.query +import kotlin.coroutines.cancellation.CancellationException + +class EmailTokensController(private val realmProvider: RealmProvider) { + private val realm by lazy { realmProvider.realmAppSettings } + + //region Get data + @Throws(RealmException::class) + fun getEmailTokenForEmail(email: String): EmailToken? = runThrowingRealm { + val query = "${EmailTokenDB::email.name} == '$email'" + return realm.query(query).first().find() + } + //endregion + + //region Update data + @Throws(RealmException::class, CancellationException::class) + suspend fun setEmailToken(email: String, token: String) = runThrowingRealm { + realm.write { + val emailTokenDB = EmailTokenDB(email, token) + copyToRealm(emailTokenDB, UpdatePolicy.ALL) + } + } + //endregion +} From cff2e804dcc27e1d54dc6d073202655a3e673448 Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Thu, 12 Dec 2024 09:52:03 +0100 Subject: [PATCH 4/7] style: Add line end of file --- .../common/interfaces/appSettings/EmailToken.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/appSettings/EmailToken.kt b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/appSettings/EmailToken.kt index 3aed2c25..31d51ae8 100644 --- a/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/appSettings/EmailToken.kt +++ b/STCommon/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/common/interfaces/appSettings/EmailToken.kt @@ -20,4 +20,4 @@ package com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings interface EmailToken { val email: String val token: String -} \ No newline at end of file +} From 70054c99143cf8c5b54fb1035d59f925d9e3c5cf Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Thu, 12 Dec 2024 10:29:13 +0100 Subject: [PATCH 5/7] fix: Update getTokenForEmail signature --- .../managers/EmailTokensManager.kt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/EmailTokensManager.kt b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/EmailTokensManager.kt index 167126ee..6f332ccb 100644 --- a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/EmailTokensManager.kt +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/EmailTokensManager.kt @@ -33,9 +33,13 @@ class EmailTokensManager(private val emailTokensController: EmailTokensControlle * @param email The email possibly associated with a token. * * @return A token which may be associated with the email. + * + * @throws RealmException If an error occurs during database access. + * @throws CancellationException If the operation is cancelled. */ - fun getEmailTokenForEmail(email: String): EmailToken? { - return emailTokensController.getEmailTokenForEmail(email) + @Throws(RealmException::class, CancellationException::class) + suspend fun getTokenForEmail(email: String): String? = withContext(Dispatchers.IO) { + return@withContext emailTokensController.getEmailTokenForEmail(email)?.token } /** From 5a10ae24dfb3352b19da83593642f2a93477529f Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Thu, 12 Dec 2024 10:41:41 +0100 Subject: [PATCH 6/7] docs: Update readme --- STCore/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/STCore/README.md b/STCore/README.md index cb6a55fa..8a1ee79a 100644 --- a/STCore/README.md +++ b/STCore/README.md @@ -41,6 +41,7 @@ centralized access point to orchestrate transfer operations. | Property | fileManager | A manager used to orchestrate Files operations. | | Property | accountManager | A manager used to orchestrate Accounts operations. | | Property | uploadManager | A manager used to orchestrate Uploads operations. | +| Property | emailTokensManager | A manager used to orchestrate EmailTokens operations. | | Property | sharedApiUrlCreator | An utils to help use shared routes | ### Details of Properties and Methods @@ -112,6 +113,18 @@ centralized access point to orchestrate transfer operations. // Use the uploadManager to orchestrate Uploads ``` +- **Type**: `EmailTokensManager` +- **Description**: + - `emailTokensManager` is a lazily initialized property that provides a manager to orchestrate all EmailTokens operations. It + uses `EmailTokensController` to do operations. + +- **Usage Example**: + ```kotlin + val core = SwissTransferInjection(userAgent = "user_agent") + val emailTokensManager = core.emailTokensManager + // Use the EmailTokensManager to orchestrate EmailTokens + ``` + #### Property: `sharedApiUrlCreator` - **Type**: `SharedApiUrlCreator` From 6095b2ef96174498416f0a220a98a8bb5be51008 Mon Sep 17 00:00:00 2001 From: Philippe Weidmann Date: Thu, 12 Dec 2024 11:04:19 +0100 Subject: [PATCH 7/7] refactor: Remove leftover imports --- .../managers/EmailTokensManager.kt | 1 - .../database/controllers/AppSettingsController.kt | 6 ------ 2 files changed, 7 deletions(-) diff --git a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/EmailTokensManager.kt b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/EmailTokensManager.kt index 6f332ccb..a40e83f2 100644 --- a/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/EmailTokensManager.kt +++ b/STCore/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/EmailTokensManager.kt @@ -18,7 +18,6 @@ package com.infomaniak.multiplatform_swisstransfer.managers import com.infomaniak.multiplatform_swisstransfer.common.exceptions.RealmException -import com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings.EmailToken import com.infomaniak.multiplatform_swisstransfer.database.controllers.EmailTokensController import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.IO diff --git a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt index d4664121..4fce1a5d 100644 --- a/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt +++ b/STDatabase/src/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/database/controllers/AppSettingsController.kt @@ -19,14 +19,9 @@ package com.infomaniak.multiplatform_swisstransfer.database.controllers import com.infomaniak.multiplatform_swisstransfer.common.exceptions.RealmException import com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings.AppSettings -import com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings.EmailToken -import com.infomaniak.multiplatform_swisstransfer.common.interfaces.transfers.File import com.infomaniak.multiplatform_swisstransfer.common.models.* import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider import com.infomaniak.multiplatform_swisstransfer.database.models.appSettings.AppSettingsDB -import com.infomaniak.multiplatform_swisstransfer.database.models.appSettings.EmailTokenDB -import com.infomaniak.multiplatform_swisstransfer.database.models.transfers.FileDB -import com.infomaniak.multiplatform_swisstransfer.database.models.transfers.TransferDB import com.infomaniak.multiplatform_swisstransfer.database.utils.RealmUtils.runThrowingRealm import io.realm.kotlin.UpdatePolicy import io.realm.kotlin.ext.query @@ -61,7 +56,6 @@ class AppSettingsController(private val realmProvider: RealmProvider) { fun getAppSettings(): AppSettings? = runThrowingRealm { return appSettingsQuery.find() } - //endregion //region Update data