-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from Infomaniak/account-manager
Add AccountManager
- Loading branch information
Showing
11 changed files
with
254 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
...c/commonMain/kotlin/com/infomaniak/multiplatform_swisstransfer/managers/AccountManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.multiplatform_swisstransfer.managers | ||
|
||
import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider | ||
import com.infomaniak.multiplatform_swisstransfer.database.cache.setting.AppSettingsController | ||
import com.infomaniak.multiplatform_swisstransfer.database.cache.setting.TransfersController | ||
import com.infomaniak.multiplatform_swisstransfer.database.cache.setting.UploadController | ||
|
||
/** | ||
* AccountManager is responsible for orchestrating Accounts operations using Realm for local data management. | ||
* | ||
* @property appSettingsController The controller for managing AppSettings operations. | ||
* @property uploadController The controller for managing Upload operations. | ||
* @property transfersController The controller for managing Transfers operation. | ||
* @property realmProvider The provider for managing Realm database operations. | ||
*/ | ||
class AccountManager internal constructor( | ||
private val appSettingsController: AppSettingsController, | ||
private val uploadController: UploadController, | ||
private val transfersController: TransfersController, | ||
private val realmProvider: RealmProvider, | ||
) { | ||
|
||
/** | ||
* Loads the default User account and initializes Realm Transfers for the default UserID defined in Constants. | ||
*/ | ||
@Throws(IllegalArgumentException::class, IllegalStateException::class) | ||
suspend fun loadUser(userId: Int) { | ||
appSettingsController.initAppSettings() | ||
realmProvider.openRealmTransfers(userId) | ||
} | ||
|
||
/** | ||
* Delete specified User data | ||
*/ | ||
@Throws(IllegalArgumentException::class, IllegalStateException::class) | ||
suspend fun removeUser(userId: Int) { | ||
|
||
appSettingsController.removeData() | ||
uploadController.removeData() | ||
transfersController.removeData() | ||
|
||
realmProvider.closeAllRealms() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
.../com/infomaniak/multiplatform_swisstransfer/database/cache/setting/TransfersController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.multiplatform_swisstransfer.database.cache.setting | ||
|
||
import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider | ||
import com.infomaniak.multiplatform_swisstransfer.database.models.transfers.TransferDB | ||
import io.realm.kotlin.ext.query | ||
import io.realm.kotlin.query.RealmResults | ||
import kotlin.coroutines.cancellation.CancellationException | ||
|
||
class TransfersController(private val realmProvider: RealmProvider) { | ||
|
||
private val realm by lazy { realmProvider.realmTransfers } | ||
|
||
//region Get data | ||
@Throws(IllegalArgumentException::class, CancellationException::class) | ||
fun getTransfers(): RealmResults<TransferDB>? = realm?.query<TransferDB>()?.find() | ||
//endregion | ||
|
||
//region Update data | ||
@Throws(IllegalArgumentException::class, CancellationException::class) | ||
suspend fun removeData() { | ||
realm?.write { deleteAll() } | ||
} | ||
//endregion | ||
} |
48 changes: 48 additions & 0 deletions
48
...lin/com/infomaniak/multiplatform_swisstransfer/database/cache/setting/UploadController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.multiplatform_swisstransfer.database.cache.setting | ||
|
||
import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider | ||
import com.infomaniak.multiplatform_swisstransfer.database.models.upload.Upload | ||
import io.realm.kotlin.ext.query | ||
import io.realm.kotlin.query.RealmResults | ||
import kotlin.coroutines.cancellation.CancellationException | ||
|
||
class UploadController(private val realmProvider: RealmProvider) { | ||
|
||
private val realm by lazy { realmProvider.realmUploads } | ||
|
||
//region Queries | ||
private fun getUploadsQuery() = realm.query<Upload>() | ||
//endregion | ||
|
||
//region Get data | ||
@Throws(IllegalArgumentException::class, CancellationException::class) | ||
fun getUploads(): RealmResults<Upload> = getUploadsQuery().find() | ||
|
||
@Throws(IllegalArgumentException::class, CancellationException::class) | ||
fun getUploadsCount(): Long = getUploadsQuery().count().find() | ||
//endregion | ||
|
||
//region Update data | ||
@Throws(IllegalArgumentException::class, CancellationException::class) | ||
suspend fun removeData() { | ||
realm.write { deleteAll() } | ||
} | ||
//endregion | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...in/com/infomaniak/multiplatform_swisstransfer/database/models/upload/UploadContainerDB.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
package com.infomaniak.multiplatform_swisstransfer.database.models.upload | ||
|
||
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadContainer | ||
import io.realm.kotlin.types.EmbeddedRealmObject | ||
|
||
class UploadContainerDB : UploadContainer, EmbeddedRealmObject { | ||
override var uuid: String = "" | ||
override var duration: String = "" | ||
override var downloadLimit: Long = 0 | ||
override var language: String = "" | ||
override var source: String = "" | ||
override var wsUser: String? = null | ||
override var authorIP: String = "" | ||
override var swiftVersion: String = "" | ||
// var createdDate: String // TODO: Why a complex date instead of a simple date ? May be Custom serial this | ||
override var expiredDateTimestamp: Long = 0 | ||
override var needPassword: Boolean = false | ||
override var message: String = "" | ||
override var numberOfFiles: Int = 0 | ||
} |
Oops, something went wrong.