Skip to content

Commit 24d62ef

Browse files
committed
fix: repositoryImpl
1 parent 1eb3ec5 commit 24d62ef

File tree

11 files changed

+212
-242
lines changed

11 files changed

+212
-242
lines changed

core/data/src/commonMain/kotlin/org/mifos/mobile/core/data/di/RepositoryModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ val RepositoryModule = module {
5757
single<UserDataRepository> { AuthenticationUserRepository(get(), get(ioDispatcher)) }
5858
single<BeneficiaryRepository> { BeneficiaryRepositoryImp(get(), get(ioDispatcher)) }
5959
single<ClientChargeRepository> { ClientChargeRepositoryImp(get(), get(ioDispatcher)) } // TODO
60-
single<ClientRepository> { ClientRepositoryImp(get(), get(), get(ioDispatcher)) }
60+
single<ClientRepository> { ClientRepositoryImp(get(), get(ioDispatcher)) }
6161
single<GuarantorRepository> { GuarantorRepositoryImp(get(), get(ioDispatcher)) }
6262
single<HomeRepository> { HomeRepositoryImp(get(), get(), get(ioDispatcher)) }
6363
single<LoanRepository> { LoanRepositoryImp(get(), get(ioDispatcher)) }
64-
single<NotificationRepository> { NotificationRepositoryImp(get(), get(ioDispatcher)) } // TODO
64+
single<NotificationRepository> { NotificationRepositoryImp(get(ioDispatcher)) } // TODO
6565
single<RecentTransactionRepository> { RecentTransactionRepositoryImp(get(), get(ioDispatcher)) }
6666
single<ReviewLoanApplicationRepository> { ReviewLoanApplicationRepositoryImpl(get(), get(ioDispatcher)) }
6767
single<SavingsAccountRepository> { SavingsAccountRepositoryImp(get(), get(ioDispatcher)) }
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* Copyright 2025 Mifos Initiative
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public
5+
* License, v. 2.0. If a copy of the MPL was not distributed with this
6+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
9+
*/
10+
package org.mifos.mobile.core.data.mapper
11+
12+
import org.mifos.mobile.core.model.entity.Charge
13+
import org.mifos.mobile.core.model.entity.ChargeCalculationType
14+
import org.mifos.mobile.core.model.entity.ChargeTimeType
15+
import org.mifos.mobile.core.model.entity.Currency
16+
17+
// fun ChargeEntity.toCharge(): Charge {
18+
// return Charge(
19+
// clientId = clientId,
20+
// chargeId = chargeId,
21+
// name = name,
22+
// dueDate = dueDate,
23+
// chargeTimeType = ChargeTimeType(
24+
// id = chargeTimeType?.id ?: 0,
25+
// code = chargeTimeType?.code,
26+
// value = chargeTimeType?.value,
27+
// ),
28+
// chargeCalculationType = ChargeCalculationType(
29+
// id = chargeCalculationType?.id ?: 0,
30+
// code = chargeCalculationType?.code,
31+
// value = chargeCalculationType?.value,
32+
// ),
33+
// currency = Currency(
34+
// code = currency?.code,
35+
// name = currency?.name,
36+
// decimalPlaces = currency?.decimalPlaces ?: 0,
37+
// displaySymbol = currency?.displaySymbol,
38+
// nameCode = currency?.nameCode,
39+
// displayLabel = currency?.displayLabel,
40+
// ),
41+
// amount = amount,
42+
// amountPaid = amountPaid,
43+
// amountWaived = amountWaived,
44+
// amountWrittenOff = amountWrittenOff,
45+
// amountOutstanding = amountOutstanding,
46+
// penalty = penalty,
47+
// isActive = isActive,
48+
// isChargePaid = isChargePaid,
49+
// isChargeWaived = isChargeWaived,
50+
// paid = paid,
51+
// waived = waived,
52+
// )
53+
// }
54+
//
55+
// fun Charge.toChargeEntity(): ChargeEntity {
56+
// return ChargeEntity(
57+
// clientId = clientId,
58+
// chargeId = chargeId,
59+
// name = name,
60+
// dueDate = dueDate,
61+
// chargeTimeType = ChargeTimeTypeEntity(
62+
// id = chargeTimeType?.id ?: 0,
63+
// code = chargeTimeType?.code,
64+
// value = chargeTimeType?.value,
65+
// ),
66+
// chargeCalculationType = ChargeCalculationTypeEntity(
67+
// id = chargeCalculationType?.id ?: 0,
68+
// code = chargeCalculationType?.code,
69+
// value = chargeCalculationType?.value,
70+
// ),
71+
// currency = CurrencyEntity(
72+
// code = currency?.code,
73+
// name = currency?.name,
74+
// decimalPlaces = currency?.decimalPlaces ?: 0,
75+
// displaySymbol = currency?.displaySymbol,
76+
// nameCode = currency?.nameCode,
77+
// displayLabel = currency?.displayLabel,
78+
// ),
79+
// amount = amount,
80+
// amountPaid = amountPaid,
81+
// amountWaived = amountWaived,
82+
// amountWrittenOff = amountWrittenOff,
83+
// amountOutstanding = amountOutstanding,
84+
// penalty = penalty,
85+
// isActive = isActive,
86+
// isChargePaid = isChargePaid,
87+
// isChargeWaived = isChargeWaived,
88+
// paid = paid,
89+
// waived = waived,
90+
// )
91+
// }
92+
93+
fun Charge.toModel(): Charge {
94+
return Charge(
95+
clientId = clientId,
96+
chargeId = chargeId,
97+
name = name,
98+
dueDate = dueDate,
99+
chargeTimeType = chargeTimeType?.let {
100+
ChargeTimeType(
101+
id = it.id,
102+
code = it.code,
103+
value = it.value,
104+
)
105+
},
106+
chargeCalculationType = chargeCalculationType?.let {
107+
ChargeCalculationType(
108+
id = it.id,
109+
code = it.code,
110+
value = it.value,
111+
)
112+
},
113+
currency = currency?.let {
114+
Currency(
115+
code = it.code,
116+
name = it.name,
117+
decimalPlaces = it.decimalPlaces,
118+
displaySymbol = it.displaySymbol,
119+
nameCode = it.nameCode,
120+
displayLabel = it.displayLabel,
121+
)
122+
},
123+
amount = amount,
124+
amountPaid = amountPaid,
125+
amountWaived = amountWaived,
126+
amountWrittenOff = amountWrittenOff,
127+
amountOutstanding = amountOutstanding,
128+
penalty = penalty,
129+
isActive = isActive,
130+
isChargePaid = isChargePaid,
131+
isChargeWaived = isChargeWaived,
132+
paid = paid,
133+
waived = waived,
134+
)
135+
}

core/data/src/commonMain/kotlin/org/mifos/mobile/core/data/model/MifosNotification.kt renamed to core/data/src/commonMain/kotlin/org/mifos/mobile/core/data/mapper/MifosNotification.kt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,19 @@
77
*
88
* See https://github.com/openMF/mobile-mobile/blob/master/LICENSE.md
99
*/
10-
package org.mifos.mobile.core.data.model
10+
package org.mifos.mobile.core.data.mapper
1111

12-
import org.mifos.mobile.core.database.entity.MifosNotificationEntity
1312
import org.mifos.mobile.core.model.entity.MifosNotification
1413

15-
fun MifosNotification.toEntity(): MifosNotificationEntity {
16-
return MifosNotificationEntity(
17-
timeStamp = timeStamp,
18-
msg = msg,
19-
read = read,
20-
)
21-
}
14+
// fun MifosNotification.toEntity(): MifosNotificationEntity {
15+
// return MifosNotificationEntity(
16+
// timeStamp = timeStamp,
17+
// msg = msg,
18+
// read = read,
19+
// )
20+
// }
2221

23-
fun MifosNotificationEntity.toModel(): MifosNotification {
22+
fun MifosNotification.toModel(): MifosNotification {
2423
return MifosNotification(
2524
timeStamp = timeStamp,
2625
msg = msg,

core/data/src/commonMain/kotlin/org/mifos/mobile/core/data/model/Charge.kt

Lines changed: 0 additions & 95 deletions
This file was deleted.

core/data/src/commonMain/kotlin/org/mifos/mobile/core/data/repository/ClientRepository.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,10 @@ package org.mifos.mobile.core.data.repository
1111

1212
import kotlinx.coroutines.flow.Flow
1313
import org.mifos.mobile.core.model.entity.Page
14-
import org.mifos.mobile.core.model.entity.User
1514
import org.mifos.mobile.core.model.entity.client.Client
1615
import org.mifospay.core.common.DataState
1716

1817
interface ClientRepository {
1918

2019
fun loadClient(): Flow<DataState<Page<Client>>>
21-
22-
suspend fun saveAuthenticationTokenForSession(user: User): DataState<Unit>
23-
24-
suspend fun setClientId(clientId: Long?): DataState<Unit>
25-
26-
fun reInitializeService()
27-
28-
suspend fun updateAuthenticationToken(password: String): DataState<Unit>
2920
}

core/data/src/commonMain/kotlin/org/mifos/mobile/core/data/repositoryImpl/ClientChargeRepositoryImp.kt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,12 @@ package org.mifos.mobile.core.data.repositoryImpl
1111

1212
import kotlinx.coroutines.CoroutineDispatcher
1313
import kotlinx.coroutines.flow.Flow
14+
import kotlinx.coroutines.flow.flowOf
1415
import kotlinx.coroutines.flow.flowOn
15-
import kotlinx.coroutines.flow.map
1616
import kotlinx.coroutines.withContext
1717
import org.mifos.mobile.core.common.Dispatcher
1818
import org.mifos.mobile.core.common.MifosDispatchers
19-
import org.mifos.mobile.core.data.model.toCharge
20-
import org.mifos.mobile.core.data.model.toChargeEntity
2119
import org.mifos.mobile.core.data.repository.ClientChargeRepository
22-
import org.mifos.mobile.core.database.dao.ChargeDao
2320
import org.mifos.mobile.core.model.entity.Charge
2421
import org.mifos.mobile.core.model.entity.Page
2522
import org.mifos.mobile.core.network.DataManager
@@ -28,7 +25,7 @@ import org.mifospay.core.common.asDataStateFlow
2825

2926
class ClientChargeRepositoryImp(
3027
private val dataManager: DataManager,
31-
private val chargeDao: ChargeDao,
28+
// private val chargeDao: ChargeDao,
3229
@Dispatcher(MifosDispatchers.IO)
3330
private val ioDispatcher: CoroutineDispatcher,
3431
) : ClientChargeRepository {
@@ -48,19 +45,23 @@ class ClientChargeRepositoryImp(
4845
.asDataStateFlow().flowOn(ioDispatcher)
4946
}
5047

51-
override fun clientLocalCharges(): Flow<Page<Charge>> {
52-
return chargeDao.getAllLocalCharges().map { chargeList ->
53-
Page(chargeList.size, chargeList.map { it.toCharge() })
54-
}.flowOn(ioDispatcher)
48+
override fun clientLocalCharges(): Flow<DataState<Page<Charge>>> {
49+
// return chargeDao.getAllLocalCharges().map { chargeList ->
50+
// Page(chargeList.size, chargeList.map { it.toCharge() })
51+
// }.flowOn(ioDispatcher)
52+
return flowOf(DataState.Success(Page(0, emptyList<Charge>())))
53+
.flowOn(ioDispatcher)
5554
}
5655

57-
override suspend fun syncCharges(charges: Page<Charge>?): Page<Charge>? {
56+
override suspend fun syncCharges(charges: Page<Charge>?): DataState<Page<Charge>?> {
5857
return withContext(ioDispatcher) {
59-
charges?.pageItems?.let {
60-
chargeDao.syncCharges(it.map { it.toChargeEntity() })
61-
}
62-
63-
charges?.copy(pageItems = charges.pageItems)
58+
// charges?.pageItems?.let {
59+
// chargeDao.syncCharges(it.map { it.toChargeEntity() })
60+
// }
61+
//
62+
// charges?.copy(pageItems = charges.pageItems)
63+
val result = charges?.copy(pageItems = charges.pageItems) ?: Page(0, emptyList())
64+
DataState.Success(result)
6465
}
6566
}
6667
}

0 commit comments

Comments
 (0)