Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
itsPronay committed Jan 28, 2025
1 parent d5e5e19 commit 44e70c7
Show file tree
Hide file tree
Showing 37 changed files with 447 additions and 393 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import kotlin.annotation.AnnotationRetention.RUNTIME

@Qualifier
@Retention(RUNTIME)
annotation class Dispatcher(val mifosDispatcher: MifosDispatchers)
annotation class Dispatcher(val dispatcher: MifosDispatchers)

enum class MifosDispatchers {
Default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ interface LoanRepaymentRepository {
suspend fun submitPayment(
loanId: Int,
request: LoanRepaymentRequest,
): Flow<LoanRepaymentResponse?>
): LoanRepaymentResponse

fun getDatabaseLoanRepaymentByLoanId(loanId: Int): Flow<LoanRepaymentRequest?>
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ interface SyncCentersDialogRepository {

fun syncCenterAccounts(centerId: Int): Observable<CenterAccounts>

suspend fun syncLoanById(loanId: Int): Flow<LoanWithAssociations>
fun syncLoanById(loanId: Int): Flow<LoanWithAssociations>

suspend fun syncLoanRepaymentTemplate(loanId: Int): Flow<LoanRepaymentTemplate>
fun syncLoanRepaymentTemplate(loanId: Int): Flow<LoanRepaymentTemplate>

fun getCenterWithAssociations(centerId: Int): Observable<CenterWithAssociations>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface SyncClientsDialogRepository {

suspend fun syncClientAccounts(clientId: Int): ClientAccounts

suspend fun syncLoanById(loanId: Int): Flow<LoanWithAssociations>
fun syncLoanById(loanId: Int): Flow<LoanWithAssociations>

fun syncLoanRepaymentTemplate(loanId: Int): Flow<LoanRepaymentTemplate>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface SyncLoanRepaymentTransactionRepository {
request: LoanRepaymentRequest,
): LoanRepaymentResponse

suspend fun deleteAndUpdateLoanRepayments(loanId: Int): Flow<List<LoanRepaymentRequest>>
fun deleteAndUpdateLoanRepayments(loanId: Int): Flow<List<LoanRepaymentRequest>>

fun updateLoanRepaymentTransaction(
loanRepaymentRequest: LoanRepaymentRequest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@
*/
package com.mifos.core.data.repositoryImp

import com.mifos.core.common.network.Dispatcher
import com.mifos.core.common.network.MifosDispatchers
import com.mifos.core.data.repository.LoanAccountSummaryRepository
import com.mifos.core.network.datamanager.DataManagerLoan
import com.mifos.room.entities.accounts.loans.LoanWithAssociations
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject

/**
* Created by Aditya Gupta on 08/08/23.
*/
class LoanAccountSummaryRepositoryImp @Inject constructor(private val dataManagerLoan: DataManagerLoan) :
LoanAccountSummaryRepository {
class LoanAccountSummaryRepositoryImp @Inject constructor(
private val dataManagerLoan: DataManagerLoan,
@Dispatcher(MifosDispatchers.IO)
private val ioDispatcher: CoroutineDispatcher,
) : LoanAccountSummaryRepository {

override fun getLoanById(loanId: Int): Flow<LoanWithAssociations?> {
return dataManagerLoan.getLoanById(loanId)
.flowOn(ioDispatcher)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,35 +9,43 @@
*/
package com.mifos.core.data.repositoryImp

import com.mifos.core.common.network.Dispatcher
import com.mifos.core.common.network.MifosDispatchers
import com.mifos.core.data.repository.LoanRepaymentRepository
import com.mifos.core.network.datamanager.DataManagerLoan
import com.mifos.room.entities.accounts.loans.LoanRepaymentRequest
import com.mifos.room.entities.accounts.loans.LoanRepaymentResponse
import com.mifos.room.entities.templates.loans.LoanRepaymentTemplate
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject

/**
* Created by Aditya Gupta on 10/08/23.
*/
class LoanRepaymentRepositoryImp @Inject constructor(private val dataManagerLoan: DataManagerLoan) :
LoanRepaymentRepository {
class LoanRepaymentRepositoryImp @Inject constructor(
private val dataManagerLoan: DataManagerLoan,
@Dispatcher(MifosDispatchers.IO)
private val ioDispatcher: CoroutineDispatcher,
) : LoanRepaymentRepository {

override fun getLoanRepayTemplate(loanId: Int): Flow<LoanRepaymentTemplate?> {
return dataManagerLoan.getLoanRepayTemplate(loanId)
.flowOn(ioDispatcher)
}

override suspend fun submitPayment(
loanId: Int,
request: LoanRepaymentRequest,
): Flow<LoanRepaymentResponse> {
return submitPayment(loanId, request)
): LoanRepaymentResponse {
return dataManagerLoan.submitPayment(loanId, request)
}

override fun getDatabaseLoanRepaymentByLoanId(loanId: Int): Flow<LoanRepaymentRequest?> {
return flow {
emit(dataManagerLoan.getDatabaseLoanRepaymentByLoanId(loanId))
}
}.flowOn(ioDispatcher)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import com.mifos.core.network.datamanager.DataManagerGroups
import com.mifos.core.network.datamanager.DataManagerLoan
import com.mifos.core.network.datamanager.DataManagerSavings
import com.mifos.room.entities.accounts.loans.LoanRepaymentRequest
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import rx.Observable
import javax.inject.Inject

Expand All @@ -33,6 +35,7 @@ class OfflineDashboardRepositoryImp @Inject constructor(
private val dataManagerCenter: DataManagerCenter,
private val dataManagerLoan: DataManagerLoan,
private val dataManagerSavings: DataManagerSavings,
private val ioDispatcher: CoroutineDispatcher,
) : OfflineDashboardRepository {

override fun allDatabaseClientPayload(): Observable<List<ClientPayload>> {
Expand All @@ -49,6 +52,7 @@ class OfflineDashboardRepositoryImp @Inject constructor(

override fun databaseLoanRepayments(): Flow<List<LoanRepaymentRequest>> {
return dataManagerLoan.databaseLoanRepayments
.flowOn(ioDispatcher)
}

override fun allSavingsAccountTransactions(): Observable<List<SavingsAccountTransactionRequest>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import com.mifos.room.entities.accounts.loans.LoanWithAssociations
import com.mifos.room.entities.group.CenterWithAssociations
import com.mifos.room.entities.group.GroupWithAssociations
import com.mifos.room.entities.templates.loans.LoanRepaymentTemplate
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import rx.Observable
Expand All @@ -42,19 +42,21 @@ class SyncCentersDialogRepositoryImp @Inject constructor(
private val dataManagerSavings: DataManagerSavings,
private val dataManagerGroups: DataManagerGroups,
private val dataManagerClient: DataManagerClient,
private val ioDispatcher: CoroutineDispatcher,
) : SyncCentersDialogRepository {

override fun syncCenterAccounts(centerId: Int): Observable<CenterAccounts> {
return dataManagerCenter.syncCenterAccounts(centerId)
}

override suspend fun syncLoanById(loanId: Int): Flow<LoanWithAssociations> {
override fun syncLoanById(loanId: Int): Flow<LoanWithAssociations> {
return dataManagerLoan.syncLoanById(loanId)
.flowOn(Dispatchers.IO)
.flowOn(ioDispatcher)
}

override suspend fun syncLoanRepaymentTemplate(loanId: Int): Flow<LoanRepaymentTemplate> {
override fun syncLoanRepaymentTemplate(loanId: Int): Flow<LoanRepaymentTemplate> {
return dataManagerLoan.syncLoanRepaymentTemplate(loanId)
.flowOn(ioDispatcher)
}

override fun getCenterWithAssociations(centerId: Int): Observable<CenterWithAssociations> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import com.mifos.core.network.datamanager.DataManagerSavings
import com.mifos.room.entities.accounts.ClientAccounts
import com.mifos.room.entities.accounts.loans.LoanWithAssociations
import com.mifos.room.entities.templates.loans.LoanRepaymentTemplate
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import rx.Observable
Expand All @@ -32,19 +32,21 @@ class SyncClientsDialogRepositoryImp @Inject constructor(
private val dataManagerClient: DataManagerClient,
private val dataManagerLoan: DataManagerLoan,
private val dataManagerSavings: DataManagerSavings,
private val ioDispatcher: CoroutineDispatcher,
) : SyncClientsDialogRepository {

override suspend fun syncClientAccounts(clientId: Int): ClientAccounts {
return dataManagerClient.getClientAccounts(clientId)
}

override suspend fun syncLoanById(loanId: Int): Flow<LoanWithAssociations> {
override fun syncLoanById(loanId: Int): Flow<LoanWithAssociations> {
return dataManagerLoan.syncLoanById(loanId)
.flowOn(Dispatchers.IO)
.flowOn(ioDispatcher)
}

override fun syncLoanRepaymentTemplate(loanId: Int): Flow<LoanRepaymentTemplate> {
return dataManagerLoan.syncLoanRepaymentTemplate(loanId)
.flowOn(ioDispatcher)
}

override fun syncSavingsAccount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import com.mifos.room.entities.accounts.GroupAccounts
import com.mifos.room.entities.accounts.loans.LoanWithAssociations
import com.mifos.room.entities.group.GroupWithAssociations
import com.mifos.room.entities.templates.loans.LoanRepaymentTemplate
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import rx.Observable
Expand All @@ -37,6 +37,7 @@ class SyncGroupsDialogRepositoryImp @Inject constructor(
private val dataManagerLoan: DataManagerLoan,
private val dataManagerSavings: DataManagerSavings,
private val dataManagerClient: DataManagerClient,
private val ioDispatcher: CoroutineDispatcher,
) : SyncGroupsDialogRepository {

override fun syncGroupAccounts(groupId: Int): Observable<GroupAccounts> {
Expand All @@ -45,11 +46,12 @@ class SyncGroupsDialogRepositoryImp @Inject constructor(

override fun syncLoanById(loanId: Int): Flow<LoanWithAssociations> {
return dataManagerLoan.syncLoanById(loanId)
.flowOn(Dispatchers.IO)
.flowOn(ioDispatcher)
}

override fun syncLoanRepaymentTemplate(loanId: Int): Flow<LoanRepaymentTemplate> {
return dataManagerLoan.syncLoanRepaymentTemplate(loanId)
.flowOn(ioDispatcher)
}

override fun syncSavingsAccount(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,24 @@ import com.mifos.core.network.datamanager.DataManagerLoan
import com.mifos.room.entities.PaymentTypeOption
import com.mifos.room.entities.accounts.loans.LoanRepaymentRequest
import com.mifos.room.entities.accounts.loans.LoanRepaymentResponse
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import javax.inject.Inject

class SyncLoanRepaymentTransactionRepositoryImp @Inject constructor(private val dataManagerLoan: DataManagerLoan) :
SyncLoanRepaymentTransactionRepository {
class SyncLoanRepaymentTransactionRepositoryImp @Inject constructor(
private val dataManagerLoan: DataManagerLoan,
private val ioDispatcher: CoroutineDispatcher,
) : SyncLoanRepaymentTransactionRepository {

override fun databaseLoanRepayments(): Flow<List<LoanRepaymentRequest>> {
return dataManagerLoan.databaseLoanRepayments
.flowOn(ioDispatcher)
}

override fun paymentTypeOption(): Flow<List<PaymentTypeOption>> {
return dataManagerLoan.paymentTypeOption
.flowOn(ioDispatcher)
}

override suspend fun submitPayment(
Expand All @@ -37,13 +41,13 @@ class SyncLoanRepaymentTransactionRepositoryImp @Inject constructor(private val
return dataManagerLoan.submitPayment(loanId, request)
}

override suspend fun deleteAndUpdateLoanRepayments(loanId: Int): Flow<List<LoanRepaymentRequest>> {
override fun deleteAndUpdateLoanRepayments(loanId: Int): Flow<List<LoanRepaymentRequest>> {
return dataManagerLoan.deleteAndUpdateLoanRepayments(loanId)
.flowOn(Dispatchers.IO)
.flowOn(ioDispatcher)
}

override fun updateLoanRepaymentTransaction(loanRepaymentRequest: LoanRepaymentRequest): Flow<LoanRepaymentRequest> {
return dataManagerLoan.updateLoanRepaymentTransaction(loanRepaymentRequest)
.flowOn(Dispatchers.IO)
.flowOn(ioDispatcher)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ import com.mifos.core.network.datamanager.DataManagerLoan
import com.mifos.core.network.datamanager.DataManagerSavings
import com.mifos.core.objects.account.saving.SavingsAccountTransactionResponse
import com.mifos.room.entities.PaymentTypeOption
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import rx.Observable
import javax.inject.Inject

Expand All @@ -25,6 +27,7 @@ import javax.inject.Inject
class SyncSavingsAccountTransactionRepositoryImp @Inject constructor(
private val dataManagerSavings: DataManagerSavings,
private val dataManagerLoan: DataManagerLoan,
private val ioDispatcher: CoroutineDispatcher,
) : SyncSavingsAccountTransactionRepository {

override fun allSavingsAccountTransactions(): Observable<List<SavingsAccountTransactionRequest>> {
Expand All @@ -33,6 +36,7 @@ class SyncSavingsAccountTransactionRepositoryImp @Inject constructor(

override fun paymentTypeOption(): Flow<List<PaymentTypeOption>> {
return dataManagerLoan.paymentTypeOption
.flowOn(ioDispatcher)
}

override fun processTransaction(
Expand Down
4 changes: 2 additions & 2 deletions core/database/src/main/java/com/mifos/room/dao/LoanDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ interface LoanDao {
@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertLoanRepaymentTemplate(template: LoanRepaymentTemplate)

@Query("SELECT * FROM LoanRepaymentTemplate WHERE loanId = :loanId")
fun getLoanRepaymentTemplate(loanId: Int): Flow<List<LoanRepaymentTemplate?>>
@Query("SELECT * FROM LoanRepaymentTemplate WHERE loanId = :loanId LIMIT 1")
fun getLoanRepaymentTemplate(loanId: Int): LoanRepaymentTemplate?

@Query("DELETE FROM LoanRepaymentTemplate WHERE loanId = :loanId")
suspend fun deleteLoanRepaymentByLoanId(loanId: Int)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,23 @@ data class PaymentTypeOption(
@SerializedName("id")
@PrimaryKey
@ColumnInfo(name = "id")
var id: Int = 0,
val id: Int = 0,

@SerializedName("name")
@ColumnInfo(name = "name")
var name: String = "",
val name: String = "",

@SerializedName("description")
@ColumnInfo(name = "description")
var description: String? = null,
val description: String? = null,

@SerializedName("isCashPayment")
@ColumnInfo(name = "is_cash_payment")
var isCashPayment: Boolean? = null,
val isCashPayment: Boolean? = null,

@SerializedName("position")
@ColumnInfo(name = "position")
var position: Int? = null,
val position: Int? = null,
) : MifosBaseModel(), Comparable<PaymentTypeOption>, Parcelable {

override fun compareTo(another: PaymentTypeOption): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import kotlinx.parcelize.Parcelize
@Parcelize
data class ActualDisbursementDate(
@PrimaryKey
var loanId: Int? = null,
val loanId: Int? = null,

@ColumnInfo(name = "year")
var year: Int? = null,
val year: Int? = null,

@ColumnInfo(name = "month")
var month: Int? = null,
val month: Int? = null,

@ColumnInfo(name = "date")
var date: Int? = null,
val date: Int? = null,
) : Parcelable
Loading

0 comments on commit 44e70c7

Please sign in to comment.