Skip to content

Commit

Permalink
Renamed UploadTasks into Upload + Some code/packages cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinBoulongne committed Sep 6, 2024
1 parent 50910b5 commit 09a50b4
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.common.interfaces
package com.infomaniak.multiplatform_swisstransfer.common.interfaces.transfers

interface Container<F : List<File>> {
var uuid: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.common.interfaces
package com.infomaniak.multiplatform_swisstransfer.common.interfaces.transfers

interface File {
var containerUUID: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.common.interfaces
package com.infomaniak.multiplatform_swisstransfer.common.interfaces.transfers

interface Transfer<ContainerType> {
var linkUUID: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ package com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload
interface InitUploadResponse<C : UploadContainer> {
var container: C
var uploadHost: String
var filesUUID: List<String>
var filesUuid: List<String>
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ interface UploadContainer {
val authorIP: String
val swiftVersion: String

// val createdDate: Object TODO: (Date) Waiting or deserialize this complex date object to timestamp
// val createdDate: Object // TODO: (Date) Waiting or deserialize this complex date object to timestamp
val expiredDateTimestamp: Long
val needPassword: Boolean
val message: String
val numberOfFile: Long
val numberOfFiles: Long
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
*/
package com.infomaniak.multiplatform_swisstransfer.database

import com.infomaniak.multiplatform_swisstransfer.database.models.ContainerDB
import com.infomaniak.multiplatform_swisstransfer.database.models.FileDB
import com.infomaniak.multiplatform_swisstransfer.database.models.TransferDB
import com.infomaniak.multiplatform_swisstransfer.database.models.setting.AppSettingsDB
import com.infomaniak.multiplatform_swisstransfer.database.models.upload.UploadTasks
import com.infomaniak.multiplatform_swisstransfer.database.models.appSettings.AppSettingsDB
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
import com.infomaniak.multiplatform_swisstransfer.database.models.upload.Upload
import io.realm.kotlin.Realm
import io.realm.kotlin.RealmConfiguration

class RealmProvider {

val realmAppSettings by lazy { Realm.open(realmAppSettingsConfiguration) }

val realmUploadTasks by lazy { Realm.open(realmUploadTasksConfiguration) }
val realmUploads by lazy { Realm.open(realmUploadConfiguration) }

var realmTransfers: Realm? = null
private set
Expand All @@ -42,11 +42,11 @@ class RealmProvider {
realmAppSettings.close()
}

fun closeRealmUploadTasks() {
realmUploadTasks.close()
fun closeRealmUploads() {
realmUploads.close()
}

fun closeCurrentRealmTransfers() {
fun closeRealmTransfers() {
realmTransfers?.close()
}

Expand All @@ -56,18 +56,18 @@ class RealmProvider {

fun closeAllRealms() {
closeRealmAppSettings()
closeRealmUploadTasks()
closeCurrentRealmTransfers()
closeRealmUploads()
closeRealmTransfers()
}

private val realmAppSettingsConfiguration = RealmConfiguration
.Builder(schema = setOf(AppSettingsDB::class))
.name("AppSettings")
.build()

private val realmUploadTasksConfiguration = RealmConfiguration
.Builder(schema = setOf(UploadTasks::class))
.name("UploadTasks")
private val realmUploadConfiguration = RealmConfiguration
.Builder(schema = setOf(Upload::class))
.name("Uploads")
.build()

private fun realmTransfersConfiguration(userId: Int) = RealmConfiguration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage
import com.infomaniak.multiplatform_swisstransfer.common.models.Theme
import com.infomaniak.multiplatform_swisstransfer.common.models.ValidityPeriod
import com.infomaniak.multiplatform_swisstransfer.database.RealmProvider
import com.infomaniak.multiplatform_swisstransfer.database.models.setting.AppSettingsDB
import com.infomaniak.multiplatform_swisstransfer.database.models.appSettings.AppSettingsDB
import io.realm.kotlin.UpdatePolicy
import io.realm.kotlin.ext.query
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand All @@ -46,15 +46,12 @@ class AppSettingsController(private val realmProvider: RealmProvider) {
}

//region Get data

fun getAppSettingsFlow(): Flow<AppSettingsDB?> {
return appSettingsQuery.asFlow().mapLatest { it.obj }
}

//endregion

//region Update data

@Throws(IllegalArgumentException::class, CancellationException::class)
private suspend fun updateAppSettings(onUpdate: (AppSettingsDB) -> Unit) {
val appSettings = appSettingsQuery.find() ?: return
Expand Down Expand Up @@ -93,6 +90,5 @@ class AppSettingsController(private val realmProvider: RealmProvider) {
mutableAppSettings.emailLanguage = emailLanguage
}
}

//endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.setting
package com.infomaniak.multiplatform_swisstransfer.database.models.appSettings

import com.infomaniak.multiplatform_swisstransfer.common.interfaces.appSettings.AppSettings
import com.infomaniak.multiplatform_swisstransfer.common.models.DownloadLimit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* 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
package com.infomaniak.multiplatform_swisstransfer.database.models.transfers

import com.infomaniak.multiplatform_swisstransfer.common.interfaces.Container
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.transfers.Container
import io.realm.kotlin.ext.realmListOf
import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* 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
package com.infomaniak.multiplatform_swisstransfer.database.models.transfers

import com.infomaniak.multiplatform_swisstransfer.common.interfaces.File
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.transfers.File
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.PrimaryKey

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
* 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
package com.infomaniak.multiplatform_swisstransfer.database.models.transfers

import com.infomaniak.multiplatform_swisstransfer.common.interfaces.Transfer
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.transfers.Transfer
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.PrimaryKey

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import io.realm.kotlin.types.RealmObject
/**
* Class representing files to be uploaded
*/
class UploadTasks : RealmObject {
class Upload : RealmObject {
var userId: Long = 0
//TODO: implement
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package com.infomaniak.multiplatform_swisstransfer.network.models.transfer

import com.infomaniak.multiplatform_swisstransfer.common.interfaces.Container
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.transfers.Container
import com.infomaniak.multiplatform_swisstransfer.network.serializers.DateToTimestampSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package com.infomaniak.multiplatform_swisstransfer.network.models.transfer

import com.infomaniak.multiplatform_swisstransfer.common.interfaces.File
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.transfers.File
import com.infomaniak.multiplatform_swisstransfer.network.serializers.DateToTimestampSerializer
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package com.infomaniak.multiplatform_swisstransfer.network.models.transfer

import com.infomaniak.multiplatform_swisstransfer.common.interfaces.Transfer
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.transfers.Transfer
import com.infomaniak.multiplatform_swisstransfer.network.serializers.DateToTimestampSerializer
import com.infomaniak.multiplatform_swisstransfer.network.serializers.IntToBooleanSerializer
import kotlinx.serialization.SerialName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.network.models.upload
package com.infomaniak.multiplatform_swisstransfer.network.models.upload.response

import kotlinx.serialization.Serializable

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
* 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.network.models.upload
package com.infomaniak.multiplatform_swisstransfer.network.models.upload.response

import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.InitUploadResponse

class InitUploadResponseApi : InitUploadResponse<UploadContainerApi> {
override var container: UploadContainerApi = UploadContainerApi()
override var uploadHost: String = ""
override var filesUUID: List<String> = emptyList()
override var filesUuid: List<String> = emptyList()
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.network.models.upload
package com.infomaniak.multiplatform_swisstransfer.network.models.upload.response

import com.infomaniak.multiplatform_swisstransfer.network.serializers.DateToTimestampSerializer
import com.infomaniak.multiplatform_swisstransfer.network.serializers.IntToBooleanSerializer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* 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.network.models.upload
package com.infomaniak.multiplatform_swisstransfer.network.models.upload.response

import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadContainer
import com.infomaniak.multiplatform_swisstransfer.network.serializers.DateToTimestampSerializer
Expand All @@ -38,11 +38,12 @@ class UploadContainerApi : UploadContainer {
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
// var createdDate: String // TODO: Why a complex date instead of a simple date ? May be Custom serial this
@SerialName("expiredDate")
@Serializable(DateToTimestampSerializer::class)
override var expiredDateTimestamp: Long = 0
override var needPassword: Boolean = false
override var message: String = ""
override var numberOfFile: Long = 0
@SerialName("numberOfFile")
override var numberOfFiles: Long = 0
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ import com.infomaniak.multiplatform_swisstransfer.network.ApiClientProvider
import com.infomaniak.multiplatform_swisstransfer.network.exceptions.*
import com.infomaniak.multiplatform_swisstransfer.network.exceptions.ContainerErrorsException.Companion.toContainerErrorsException
import com.infomaniak.multiplatform_swisstransfer.network.exceptions.EmailValidationException.Companion.toEmailValidationException
import com.infomaniak.multiplatform_swisstransfer.network.models.upload.AuthorEmailToken
import com.infomaniak.multiplatform_swisstransfer.network.models.upload.InitUploadResponseApi
import com.infomaniak.multiplatform_swisstransfer.network.models.upload.UploadCompleteResponse
import com.infomaniak.multiplatform_swisstransfer.network.models.upload.response.AuthorEmailToken
import com.infomaniak.multiplatform_swisstransfer.network.models.upload.response.InitUploadResponseApi
import com.infomaniak.multiplatform_swisstransfer.network.models.upload.response.UploadCompleteResponse
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
package com.infomaniak.multiplatform_swisstransfer.network.requests

import com.infomaniak.multiplatform_swisstransfer.network.models.upload.AuthorEmailToken
import com.infomaniak.multiplatform_swisstransfer.network.models.upload.InitUploadResponseApi
import com.infomaniak.multiplatform_swisstransfer.network.models.upload.UploadCompleteResponse
import com.infomaniak.multiplatform_swisstransfer.network.models.upload.response.AuthorEmailToken
import com.infomaniak.multiplatform_swisstransfer.network.models.upload.response.InitUploadResponseApi
import com.infomaniak.multiplatform_swisstransfer.network.models.upload.response.UploadCompleteResponse
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
Expand Down

0 comments on commit 09a50b4

Please sign in to comment.