Skip to content

Commit

Permalink
chore: Create FileManager and add it to SwissTransferInjection
Browse files Browse the repository at this point in the history
  • Loading branch information
tevincent committed Nov 21, 2024
1 parent f19565d commit 5e943ac
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ 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.managers.AccountManager
import com.infomaniak.multiplatform_swisstransfer.managers.AppSettingsManager
import com.infomaniak.multiplatform_swisstransfer.managers.TransferManager
import com.infomaniak.multiplatform_swisstransfer.managers.UploadManager
import com.infomaniak.multiplatform_swisstransfer.managers.*
import com.infomaniak.multiplatform_swisstransfer.network.ApiClientProvider
import com.infomaniak.multiplatform_swisstransfer.network.repositories.TransferRepository
import com.infomaniak.multiplatform_swisstransfer.network.repositories.UploadRepository
Expand Down Expand Up @@ -58,12 +56,16 @@ class SwissTransferInjection(
private val appSettingsController by lazy { AppSettingsController(realmProvider) }
private val uploadController by lazy { UploadController(realmProvider) }
private val transferController by lazy { TransferController(realmProvider) }
private val fileController by lazy { FileController(realmProvider) }

private val emailLanguageUtils by lazy { EmailLanguageUtils() }

/** A manager used to orchestrate Transfers operations. */
val transferManager by lazy { TransferManager(apiClientProvider, transferController, transferRepository) }

/** A manager used to orchestrate Files operations. */
val fileManager by lazy { FileManager(fileController) }

/** A manager used to orchestrate AppSettings operations. */
val appSettingsManager by lazy { AppSettingsManager(appSettingsController) }

Expand Down
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.managers

import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi
import com.infomaniak.multiplatform_swisstransfer.common.utils.mapToList
import com.infomaniak.multiplatform_swisstransfer.database.controllers.FileController
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

class FileManager(private val fileController: FileController) {

/**
* Retrieves a flow of files contained in a folder with the specified folderUuid.
*
* @param folderUuid The UUID of the folder within the transfer.
* @return A flow of lists of [FileUi] objects representing the files in the transfer.
*/
fun getFilesFromTransfer(folderUuid: String): Flow<List<FileUi>?> {
return fileController.getFilesFromTransfer(folderUuid).map { files -> files.mapToList { FileUi(it) } }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package com.infomaniak.multiplatform_swisstransfer.managers
import com.infomaniak.multiplatform_swisstransfer.common.exceptions.RealmException
import com.infomaniak.multiplatform_swisstransfer.common.exceptions.UnknownException
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.transfers.Transfer
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.FileUi
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.ui.TransferUi
import com.infomaniak.multiplatform_swisstransfer.common.interfaces.upload.UploadSession
import com.infomaniak.multiplatform_swisstransfer.common.models.TransferDirection
Expand Down Expand Up @@ -127,16 +126,6 @@ class TransferManager internal constructor(
return transferController.getTransfer(transferUUID)?.let(::TransferUi)
}

/**
* Retrieves a flow of files contained in a folder with the specified folderUuid.
*
* @param folderUuid The UUID of the folder within the transfer.
* @return A flow of lists of [FileUi] objects representing the files in the transfer.
*/
fun getFilesFromTransfer(folderUuid: String): Flow<List<FileUi>?> {
return transferController.getFilesFromTransfer(folderUuid).map { files -> files.mapToList { FileUi(it) } }
}

/**
* Retrieves a transfer using the provided link UUID and saves it to the database.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import com.infomaniak.multiplatform_swisstransfer.common.models.*
import io.realm.kotlin.types.RealmObject
import io.realm.kotlin.types.annotations.Ignore

class AppSettingsDB(): RealmObject, AppSettings {
class AppSettingsDB() : RealmObject, AppSettings {

@Ignore
private var defaultEmailLanguage = EmailLanguage.ENGLISH

constructor(defaultEmailLanguage: EmailLanguage): this() {
constructor(defaultEmailLanguage: EmailLanguage) : this() {
this.defaultEmailLanguage = defaultEmailLanguage
}

Expand Down

0 comments on commit 5e943ac

Please sign in to comment.