diff --git a/core/common/src/main/java/com/mifos/core/common/utils/DatabaseFetchException.kt b/core/common/src/main/java/com/mifos/core/common/utils/DatabaseFetchException.kt new file mode 100644 index 0000000000..bfb17b8dbf --- /dev/null +++ b/core/common/src/main/java/com/mifos/core/common/utils/DatabaseFetchException.kt @@ -0,0 +1,15 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.core.common.utils + +class DatabaseFetchException( + message: String, + cause: Throwable? = null, +) : Exception(message, cause) diff --git a/core/common/src/main/java/com/mifos/core/common/utils/FlowCallAdapterFactory.kt b/core/common/src/main/java/com/mifos/core/common/utils/FlowCallAdapterFactory.kt new file mode 100644 index 0000000000..11f8361ca4 --- /dev/null +++ b/core/common/src/main/java/com/mifos/core/common/utils/FlowCallAdapterFactory.kt @@ -0,0 +1,48 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.core.common.utils + +import kotlinx.coroutines.flow.Flow +import retrofit2.CallAdapter +import retrofit2.Response +import retrofit2.Retrofit +import java.lang.reflect.ParameterizedType +import java.lang.reflect.Type + +class FlowCallAdapterFactory private constructor() : CallAdapter.Factory() { + override fun get( + returnType: Type, + annotations: Array, + retrofit: Retrofit, + ): CallAdapter<*, *>? { + if (getRawType(returnType) != Flow::class.java) { + return null + } + check(returnType is ParameterizedType) { "Flow return type must be parameterized as Flow or Flow" } + val responseType = getParameterUpperBound(0, returnType) + val rawFlowType = getRawType(responseType) + return if (rawFlowType == Response::class.java) { + check(responseType is ParameterizedType) { "Response must be parameterized as Response or Response" } + ResponseCallAdapter( + getParameterUpperBound( + 0, + responseType, + ), + ) + } else { + BodyCallAdapter(responseType) + } + } + + companion object { + @JvmStatic + fun create() = FlowCallAdapterFactory() + } +} diff --git a/core/common/src/main/java/com/mifos/core/common/utils/ResponseCallAdapter.kt b/core/common/src/main/java/com/mifos/core/common/utils/ResponseCallAdapter.kt new file mode 100644 index 0000000000..a68aa2eedd --- /dev/null +++ b/core/common/src/main/java/com/mifos/core/common/utils/ResponseCallAdapter.kt @@ -0,0 +1,72 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.core.common.utils // FlowCallAdapter.kt +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.suspendCancellableCoroutine +import retrofit2.Call +import retrofit2.CallAdapter +import retrofit2.Callback +import retrofit2.Response +import java.lang.reflect.Type +import kotlin.coroutines.resume +import kotlin.coroutines.resumeWithException + +class ResponseCallAdapter( + private val responseType: Type, +) : CallAdapter>> { + override fun adapt(call: Call): Flow> { + return flow { + emit( + suspendCancellableCoroutine { continuation -> + call.enqueue(object : Callback { + override fun onFailure(call: Call, t: Throwable) { + continuation.resumeWithException(t) + } + + override fun onResponse(call: Call, response: Response) { + continuation.resume(response) + } + }) + continuation.invokeOnCancellation { call.cancel() } + }, + ) + } + } + + override fun responseType() = responseType +} + +class BodyCallAdapter(private val responseType: Type) : CallAdapter> { + override fun adapt(call: Call): Flow { + return flow { + emit( + suspendCancellableCoroutine { continuation -> + call.enqueue(object : Callback { + override fun onFailure(call: Call, t: Throwable) { + continuation.resumeWithException(t) + } + + override fun onResponse(call: Call, response: Response) { + try { + continuation.resume(response.body()!!) + } catch (e: Exception) { + continuation.resumeWithException(e) + } + } + }) + continuation.invokeOnCancellation { call.cancel() } + }, + ) + } + } + + override fun responseType() = responseType +} diff --git a/core/data/src/main/java/com/mifos/core/data/pagingSource/ClientChargesPagingSource.kt b/core/data/src/main/java/com/mifos/core/data/pagingSource/ClientChargesPagingSource.kt index 12a15b8b5f..f615f0b584 100644 --- a/core/data/src/main/java/com/mifos/core/data/pagingSource/ClientChargesPagingSource.kt +++ b/core/data/src/main/java/com/mifos/core/data/pagingSource/ClientChargesPagingSource.kt @@ -11,15 +11,12 @@ package com.mifos.core.data.pagingSource import androidx.paging.PagingSource import androidx.paging.PagingState -import com.mifos.core.entity.client.Charges +import com.mifos.core.common.utils.DatabaseFetchException +import com.mifos.core.model.objects.clients.Page import com.mifos.core.network.datamanager.DataManagerCharge -import com.mifos.core.objects.clients.Page -import kotlinx.coroutines.suspendCancellableCoroutine -import rx.Subscriber -import rx.android.schedulers.AndroidSchedulers -import rx.schedulers.Schedulers -import kotlin.coroutines.resume -import kotlin.coroutines.resumeWithException +import com.mifos.room.entities.client.Charges +import kotlinx.coroutines.flow.catch +import kotlinx.coroutines.flow.first class ClientChargesPagingSource( private val clientId: Int, @@ -48,6 +45,8 @@ class ClientChargesPagingSource( ) } catch (exception: Exception) { LoadResult.Error(exception) + } catch (exception: DatabaseFetchException) { + LoadResult.Error(exception) } } @@ -55,22 +54,20 @@ class ClientChargesPagingSource( clientId: Int, position: Int, ): Pair, Int> { - return suspendCancellableCoroutine { continuation -> - dataManagerCharge.getClientCharges(clientId = clientId, offset = position, 10) - .observeOn(AndroidSchedulers.mainThread()) - .subscribeOn(Schedulers.io()) - .subscribe(object : Subscriber>() { - override fun onCompleted() { - } - - override fun onError(exception: Throwable) { - continuation.resumeWithException(exception) - } + var page: Page? = null - override fun onNext(page: Page) { - continuation.resume(Pair(page.pageItems, page.totalFilteredRecords)) - } - }) + dataManagerCharge.getClientCharges( + clientId = clientId, + offset = position, + limit = 10, + ).catch { + throw DatabaseFetchException("Failed to fetch client charges") + }.collect { + page = it } + + return page?.let { + Pair(it.pageItems, it.totalFilteredRecords) + } ?: throw DatabaseFetchException("Failed to fetch client charges") } } diff --git a/core/database/src/main/java/com/mifos/room/dao/ChargeDao.kt b/core/database/src/main/java/com/mifos/room/dao/ChargeDao.kt new file mode 100644 index 0000000000..e1fda9629e --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/dao/ChargeDao.kt @@ -0,0 +1,29 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.dao + +import androidx.room.Dao +import androidx.room.Insert +import androidx.room.Query +import com.mifos.room.entities.client.Charges +import kotlinx.coroutines.flow.Flow + +/** + * Created by Pronay Sarker on 14/02/2025 (3:32 PM) + */ +@Dao +interface ChargeDao { + + @Query("SELECT * FROM Charges where clientId = :clientId") + fun getClientCharges(clientId: Int): Flow> + + @Insert + suspend fun insertAllCharges(vararg charges: List) +} diff --git a/core/database/src/main/java/com/mifos/room/db/MifosDatabase.kt b/core/database/src/main/java/com/mifos/room/db/MifosDatabase.kt index c73ea4a9c9..45828573a9 100644 --- a/core/database/src/main/java/com/mifos/room/db/MifosDatabase.kt +++ b/core/database/src/main/java/com/mifos/room/db/MifosDatabase.kt @@ -12,9 +12,11 @@ package com.mifos.room.db import androidx.room.Database import androidx.room.RoomDatabase import androidx.room.TypeConverters +import com.mifos.room.dao.ChargeDao import com.mifos.room.dao.ColumnValueDao import com.mifos.room.dao.GroupsDao import com.mifos.room.dao.LoanDao +import com.mifos.room.dao.OfficeDao import com.mifos.room.dao.StaffDao import com.mifos.room.dao.SurveyDao import com.mifos.room.entities.PaymentTypeOption @@ -46,7 +48,6 @@ import com.mifos.room.utils.typeconverters.SurveyTypeConverters // [TODO -> add other entities ] entities = [ ColumnValue::class, - // loan LoanWithAssociations::class, LoanRepaymentRequest::class, LoanRepaymentTemplate::class, @@ -55,7 +56,6 @@ import com.mifos.room.utils.typeconverters.SurveyTypeConverters Timeline::class, Status::class, Summary::class, - // survey Survey::class, QuestionDatas::class, ResponseDatas::class, @@ -85,7 +85,9 @@ abstract class MifosDatabase : RoomDatabase() { abstract fun loanDao(): LoanDao abstract fun surveyDao(): SurveyDao abstract fun staffDao(): StaffDao + abstract fun officeDao(): OfficeDao abstract fun groupsDao(): GroupsDao + abstract fun chargeDao(): ChargeDao companion object { const val VERSION = 1 diff --git a/core/database/src/main/java/com/mifos/room/di/DaoModule.kt b/core/database/src/main/java/com/mifos/room/di/DaoModule.kt index 0ff4532102..2f04253f87 100644 --- a/core/database/src/main/java/com/mifos/room/di/DaoModule.kt +++ b/core/database/src/main/java/com/mifos/room/di/DaoModule.kt @@ -9,6 +9,7 @@ */ package com.mifos.room.di +import com.mifos.room.dao.ChargeDao import com.mifos.room.dao.ColumnValueDao import com.mifos.room.dao.GroupsDao import com.mifos.room.dao.LoanDao @@ -20,37 +21,50 @@ import dagger.Module import dagger.Provides import dagger.hilt.InstallIn import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) object DaoModule { @Provides + @Singleton fun providesColumnValueDao(database: MifosDatabase): ColumnValueDao { return database.columnValueDao() } @Provides + @Singleton fun providesLoanDao(database: MifosDatabase): LoanDao { return database.loanDao() } @Provides + @Singleton fun providesSurveyDao(database: MifosDatabase): SurveyDao { return database.surveyDao() } @Provides + @Singleton fun providesStaffDao(database: MifosDatabase): StaffDao { return database.staffDao() } @Provides + @Singleton fun providesGroupDao(database: MifosDatabase): GroupsDao { return database.groupsDao() } @Provides + @Singleton fun providesOfficeDao(database: MifosDatabase): OfficeDao { return database.officeDao() } + + @Provides + @Singleton + fun providesClientDao(database: MifosDatabase): ChargeDao { + return database.chargeDao() + } } diff --git a/core/database/src/main/java/com/mifos/room/entities/client/Charges.kt b/core/database/src/main/java/com/mifos/room/entities/client/Charges.kt index bfd576f8eb..383e7de430 100644 --- a/core/database/src/main/java/com/mifos/room/entities/client/Charges.kt +++ b/core/database/src/main/java/com/mifos/room/entities/client/Charges.kt @@ -10,7 +10,6 @@ package com.mifos.room.entities.client import android.os.Parcelable -import androidx.room.ColumnInfo import androidx.room.Entity import androidx.room.ForeignKey import androidx.room.PrimaryKey @@ -56,62 +55,43 @@ import kotlinx.serialization.json.Json ) data class Charges( @PrimaryKey - @ColumnInfo(name = "id") - var id: Int? = null, + val id: Int? = null, - @ColumnInfo(name = "clientId") - var clientId: Int? = null, + val clientId: Int? = null, - @ColumnInfo(name = "loanId") - var loanId: Int? = null, + val loanId: Int? = null, - @ColumnInfo(name = "chargeId") - var chargeId: Int? = null, + val chargeId: Int? = null, - @ColumnInfo(name = "name") - var name: String? = null, + val name: String? = null, - @ColumnInfo(name = "chargeTimeType") - var chargeTimeType: ChargeTimeType? = null, + val chargeTimeType: ChargeTimeType? = null, - @ColumnInfo(name = "chargeDueDateId") - var chargeDueDate: ClientDate? = null, + val chargeDueDate: ClientDate? = null, - @ColumnInfo(name = "dueDate") - var dueDate: String? = null, + val dueDate: String? = null, - @ColumnInfo(name = "chargeCalculationType") - var chargeCalculationType: ChargeCalculationType? = null, + val chargeCalculationType: ChargeCalculationType? = null, - @ColumnInfo(name = "currency") - var currency: Currency? = null, + val currency: Currency? = null, - @ColumnInfo(name = "amount") - var amount: Double? = null, + val amount: Double? = null, - @ColumnInfo(name = "amountPaid") - var amountPaid: Double? = null, + val amountPaid: Double? = null, - @ColumnInfo(name = "amountWaived") - var amountWaived: Double? = null, + val amountWaived: Double? = null, - @ColumnInfo(name = "amountWrittenOff") - var amountWrittenOff: Double? = null, + val amountWrittenOff: Double? = null, - @ColumnInfo(name = "amountOutstanding") - var amountOutstanding: Double? = null, + val amountOutstanding: Double? = null, - @ColumnInfo(name = "penalty") - var penalty: Boolean? = null, + val penalty: Boolean? = null, - @ColumnInfo(name = "active") - var active: Boolean? = null, + val active: Boolean? = null, - @ColumnInfo(name = "paid") - var paid: Boolean? = null, + val paid: Boolean? = null, - @ColumnInfo(name = "waived") - var waived: Boolean? = null, + val waived: Boolean? = null, ) : Parcelable { val formattedDueDate: String diff --git a/core/database/src/main/java/com/mifos/room/helper/ChargeDaoHelper.kt b/core/database/src/main/java/com/mifos/room/helper/ChargeDaoHelper.kt new file mode 100644 index 0000000000..211c76e525 --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/helper/ChargeDaoHelper.kt @@ -0,0 +1,85 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.helper + +import com.mifos.core.common.network.Dispatcher +import com.mifos.core.common.network.MifosDispatchers +import com.mifos.core.model.objects.clients.Page +import com.mifos.room.dao.ChargeDao +import com.mifos.room.entities.client.Charges +import com.mifos.room.entities.client.ClientDate +import kotlinx.coroutines.CoroutineDispatcher +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flowOn +import kotlinx.coroutines.flow.map +import javax.inject.Inject + +/** + * Created by Pronay Sarker on 14/02/2025 (3:36 PM) + */ +class ChargeDaoHelper @Inject constructor( + private val chargeDao: ChargeDao, + @Dispatcher(MifosDispatchers.IO) + private val ioDispatcher: CoroutineDispatcher, +) { + /** + * This Method save the All Client Charges in Database and save the Charge Due date in the + * ClientDate as reference with Charge Id. + * + * @param chargesPage + * @param clientId + * @return null + */ + suspend fun saveClientCharges( + chargesPage: Page, + clientId: Int, + ) { + val updatedCharges = chargesPage.pageItems.map { charges -> + val dateParts = charges.dueDate.orEmpty().split("-").mapNotNull { it.toIntOrNull() } + + val clientDate = if (dateParts.size == 3) { + charges.id?.toLong()?.let { chargeId -> + ClientDate( + 0, + chargeId, + dateParts[2], + dateParts[1], + dateParts[0], + ) + } + } else { + null + } + + charges.copy(clientId = clientId, chargeDueDate = clientDate) + } + + chargeDao.insertAllCharges(updatedCharges) + } + + /** + * This method Retrieve the Charges from Charges_Table and set the Charges Due date after + * loading the Charge due date from the ChargeDate_table as reference with charge Id. + * + * @param clientId Client ID + * @return Page of Charges + */ + fun readClientCharges(clientId: Int): Flow> { + return chargeDao.getClientCharges(clientId) + .map { chargesList -> + Page().apply { + pageItems = chargesList.map { charge -> + charge.copy(dueDate = charge.chargeDueDate?.run { "$year-$month-$day" }) + } + } + } + .flowOn(ioDispatcher) + } +} diff --git a/core/database/src/main/java/com/mifos/room/utils/typeconverters/ChargeTypeConverter.kt b/core/database/src/main/java/com/mifos/room/utils/typeconverters/ChargeTypeConverter.kt new file mode 100644 index 0000000000..73137f95fa --- /dev/null +++ b/core/database/src/main/java/com/mifos/room/utils/typeconverters/ChargeTypeConverter.kt @@ -0,0 +1,54 @@ +/* + * Copyright 2025 Mifos Initiative + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at https://mozilla.org/MPL/2.0/. + * + * See https://github.com/openMF/android-client/blob/master/LICENSE.md + */ +package com.mifos.room.utils.typeconverters + +import androidx.room.TypeConverter +import com.mifos.room.entities.client.ChargeCalculationType +import com.mifos.room.entities.client.ChargeTimeType +import com.mifos.room.entities.client.ClientDate +import kotlinx.serialization.encodeToString +import kotlinx.serialization.json.Json + +/** + * Created by Pronay Sarker on 14/02/2025 (9:18 PM) + */ + +class ChargeTypeConverter { + + @TypeConverter + fun fromChargeTimeType(type: ChargeTimeType?): String? { + return type?.let { Json.encodeToString(it) } + } + + @TypeConverter + fun toChargeTimeType(json: String?): ChargeTimeType? { + return json?.let { Json.decodeFromString(it) } + } + + @TypeConverter + fun fromClientDate(date: ClientDate?): String? { + return date?.let { Json.encodeToString(it) } + } + + @TypeConverter + fun toClientDate(json: String?): ClientDate? { + return json?.let { Json.decodeFromString(it) } + } + + @TypeConverter + fun fromChargeCalculationType(type: ChargeCalculationType?): String? { + return type?.let { Json.encodeToString(it) } + } + + @TypeConverter + fun toChargeCalculationType(json: String?): ChargeCalculationType? { + return json?.let { Json.decodeFromString(it) } + } +} diff --git a/core/network/src/main/java/com/mifos/core/network/BaseApiManager.kt b/core/network/src/main/java/com/mifos/core/network/BaseApiManager.kt index c47310f2a2..b49edb07d8 100644 --- a/core/network/src/main/java/com/mifos/core/network/BaseApiManager.kt +++ b/core/network/src/main/java/com/mifos/core/network/BaseApiManager.kt @@ -10,6 +10,7 @@ package com.mifos.core.network import com.google.gson.GsonBuilder +import com.mifos.core.common.utils.FlowCallAdapterFactory import com.mifos.core.model.getInstanceUrl import com.mifos.core.network.services.CenterService import com.mifos.core.network.services.ChargeService @@ -30,7 +31,6 @@ import com.mifos.core.network.services.StaffService import com.mifos.core.network.services.SurveyService import org.mifos.core.utils.JsonDateSerializer import retrofit2.Retrofit -import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory import retrofit2.converter.gson.GsonConverterFactory import retrofit2.converter.scalars.ScalarsConverterFactory import java.util.Date @@ -165,7 +165,7 @@ class BaseApiManager @Inject constructor(private val prefManager: com.mifos.core .baseUrl(prefManager.getServerConfig.getInstanceUrl()) .addConverterFactory(ScalarsConverterFactory.create()) .addConverterFactory(GsonConverterFactory.create(gson)) - .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) + .addCallAdapterFactory(FlowCallAdapterFactory.create()) .client(MifosOkHttpClient(prefManager).okHttpClient) .build() init() diff --git a/core/network/src/main/java/com/mifos/core/network/DataManager.kt b/core/network/src/main/java/com/mifos/core/network/DataManager.kt index d3de3ba014..651e48e15f 100644 --- a/core/network/src/main/java/com/mifos/core/network/DataManager.kt +++ b/core/network/src/main/java/com/mifos/core/network/DataManager.kt @@ -11,12 +11,12 @@ package com.mifos.core.network import com.mifos.core.entity.accounts.loan.LoanWithAssociations import com.mifos.core.entity.accounts.loan.Loans -import com.mifos.core.entity.client.Charges import com.mifos.core.entity.group.Center import com.mifos.core.entity.group.CenterWithAssociations import com.mifos.core.entity.group.Group import com.mifos.core.entity.group.GroupWithAssociations import com.mifos.core.entity.organisation.Staff +import com.mifos.core.model.objects.clients.Page import com.mifos.core.model.objects.payloads.GroupLoanPayload import com.mifos.core.network.datamanager.DataManagerClient import com.mifos.core.network.model.CollectionSheetPayload @@ -29,6 +29,7 @@ import com.mifos.core.objects.responses.SaveResponse import com.mifos.core.objects.template.client.ChargeTemplate import com.mifos.core.objects.template.loan.GroupLoanTemplate import com.mifos.core.payloads.ChargesPayload +import com.mifos.room.entities.client.Charges import com.mifos.room.entities.organisation.OfficeEntity import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.flow @@ -111,7 +112,7 @@ class DataManager { * Charges API */ // TODO Remove this Method After fixing the Charge Test - fun getClientCharges(clientId: Int, offset: Int, limit: Int): Observable> { + fun getClientCharges(clientId: Int, offset: Int, limit: Int): Flow> { return mBaseApiManager.chargeApi.getListOfCharges(clientId, offset, limit) } diff --git a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerCharge.kt b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerCharge.kt index 8954a4173a..ac87448a74 100644 --- a/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerCharge.kt +++ b/core/network/src/main/java/com/mifos/core/network/datamanager/DataManagerCharge.kt @@ -9,11 +9,13 @@ */ package com.mifos.core.network.datamanager -import com.mifos.core.databasehelper.DatabaseHelperCharge -import com.mifos.core.entity.client.Charges +import com.mifos.core.model.objects.clients.Page import com.mifos.core.network.BaseApiManager -import com.mifos.core.objects.clients.Page -import rx.Observable +import com.mifos.room.entities.client.Charges +import com.mifos.room.helper.ChargeDaoHelper +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.flow +import kotlinx.coroutines.flow.map import javax.inject.Inject import javax.inject.Singleton @@ -28,7 +30,8 @@ import javax.inject.Singleton @Singleton class DataManagerCharge @Inject constructor( val mBaseApiManager: BaseApiManager, - val mDatabaseHelperCharge: DatabaseHelperCharge, +// val mDatabaseHelperCharge: DatabaseHelperCharge, + val chargeDatabase: ChargeDaoHelper, private val prefManager: com.mifos.core.datastore.PrefManager, ) { /** @@ -42,24 +45,27 @@ class DataManagerCharge @Inject constructor( * @return Page Page of Charge in Which List Size is according to Limit and from * where position is Starting according to offset> */ - fun getClientCharges(clientId: Int, offset: Int, limit: Int): Observable> { + suspend fun getClientCharges( + clientId: Int, + offset: Int, + limit: Int, + ): Flow> { return when (prefManager.userStatus) { - false -> mBaseApiManager.chargeApi.getListOfCharges(clientId, offset, limit) - .concatMap { chargesPage -> - mDatabaseHelperCharge.saveClientCharges(chargesPage, clientId) - Observable.just(chargesPage) - } + false -> mBaseApiManager.chargeApi.getListOfCharges(clientId, offset, limit).map { + chargeDatabase.saveClientCharges(it, clientId) + it + } true -> { /** * Return Client Charges from DatabaseHelperClient only one time. */ if (offset == 0) { - mDatabaseHelperCharge.readClientCharges(clientId) + chargeDatabase.readClientCharges(clientId) } else { - Observable.just( - Page(), - ) + flow { + emit(Page()) + } } } } diff --git a/core/network/src/main/java/com/mifos/core/network/services/ChargeService.kt b/core/network/src/main/java/com/mifos/core/network/services/ChargeService.kt index 2e29d4878d..44d153c8f7 100644 --- a/core/network/src/main/java/com/mifos/core/network/services/ChargeService.kt +++ b/core/network/src/main/java/com/mifos/core/network/services/ChargeService.kt @@ -9,12 +9,15 @@ */ package com.mifos.core.network.services -import com.mifos.core.entity.client.Charges +import com.mifos.core.model.objects.clients.Page +import com.mifos.core.model.objects.template.client.ChargeTemplate import com.mifos.core.objects.clients.ChargeCreationResponse import com.mifos.core.objects.clients.Page import com.mifos.core.objects.template.client.ChargeTemplate import com.mifos.core.payloads.ChargesPayload import com.mifos.room.basemodel.APIEndPoint +import com.mifos.room.entities.client.Charges +import kotlinx.coroutines.flow.Flow import okhttp3.ResponseBody import retrofit2.http.Body import retrofit2.http.GET @@ -41,7 +44,7 @@ interface ChargeService { @Path("clientId") clientId: Int, @Query("offset") offset: Int, @Query("limit") limit: Int, - ): Observable> + ): Flow> @POST(APIEndPoint.CLIENTS + "/{clientId}/charges") suspend fun createCharges( diff --git a/version.txt b/version.txt index d6fcc0b357..e57b670bf6 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -2025.2.3-beta.0.4 \ No newline at end of file +2025.2.4-beta.0.0 \ No newline at end of file