Skip to content

Commit

Permalink
Use enumerate for language
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Oct 22, 2024
1 parent c8c7ad7 commit e536f46
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@
*/
package com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload

import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage

interface UploadSession {
val uuid: String
val duration: String
val authorEmail: String
val password: String
val message: String
val numberOfDownload: Int
val language: String
val language: EmailLanguage
val recipientsEmails: List<String>
val files: List<UploadFileSession>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ package com.infomaniak.multiplatform_swisstransfer.data
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadContainer
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadFileSession
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadSession
import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage

data class NewUploadSession(
override val duration: String,
override val authorEmail: String,
override val password: String,
override val message: String,
override val numberOfDownload: Int,
override val language: String,
override val language: EmailLanguage,
override val recipientsEmails: List<String>,
override val files: List<UploadFileSession>,
) : UploadSession {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.infomaniak.multiplatform_swisstransfer.database.models.upload

import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadSession
import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage
import io.realm.kotlin.ext.realmListOf
import io.realm.kotlin.types.RealmList
import io.realm.kotlin.types.RealmObject
Expand All @@ -32,13 +33,20 @@ class UploadSessionDB() : UploadSession, RealmObject {
override var password: String = ""
override var message: String = ""
override var numberOfDownload: Int = 0
override var language: String = ""
override var recipientsEmails: RealmList<String> = realmListOf()
override var files: RealmList<UploadFileSessionDB> = realmListOf()
private var _language: String = ""

// Remote
override var remoteContainer: UploadContainerDB? = null
override var remoteUploadHost: String? = null

override var language: EmailLanguage
get() = EmailLanguage.entries.first { it.code == _language }
set(value) {
_language = value.code
}

constructor(uploadSession: UploadSession) : this() {
if (uploadSession.uuid.isNotEmpty()) this.uuid = uploadSession.uuid
this.duration = uploadSession.duration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package com.infomaniak.multiplatform_swisstransfer.database

import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage
import com.infomaniak.multiplatform_swisstransfer.database.controllers.UploadController
import com.infomaniak.multiplatform_swisstransfer.database.dataset.DummyUpload
import kotlinx.coroutines.test.runTest
Expand Down Expand Up @@ -45,6 +46,7 @@ class UploadControllerTest {
uploadController.insert(dummyUpload)
val realmUpload = uploadController.getUploadByUuid(dummyUpload.uuid)
assertNotNull(realmUpload)
assertEquals(realmUpload.language, EmailLanguage.ITALIAN)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.infomaniak.multiplatform_swisstransfer.database.dataset
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadContainer
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadFileSession
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadSession
import com.infomaniak.multiplatform_swisstransfer.common.models.EmailLanguage

object DummyUpload {
val container = object : UploadContainer {
Expand All @@ -44,7 +45,7 @@ object DummyUpload {
override val password: String = ""
override val message: String = ""
override val numberOfDownload: Int = 0
override val language: String = ""
override val language: EmailLanguage = EmailLanguage.ITALIAN
override val recipientsEmails: List<String> = emptyList()
override val files: List<UploadFileSession> = emptyList()
override val remoteContainer: UploadContainer? = null
Expand Down

0 comments on commit e536f46

Please sign in to comment.