Skip to content

Commit a72352c

Browse files
Client add charge (#2533)
Co-authored-by: Shreyash16b <shreyashborde@gmail.com>
1 parent 9df7ef4 commit a72352c

File tree

41 files changed

+1748
-1126
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1748
-1126
lines changed

core/data/src/commonMain/kotlin/com/mifos/core/data/di/RepositoryModule.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ import com.mifos.core.common.network.MifosDispatchers
1313
import com.mifos.core.data.repository.ActivateRepository
1414
import com.mifos.core.data.repository.CenterDetailsRepository
1515
import com.mifos.core.data.repository.CenterListRepository
16-
import com.mifos.core.data.repository.ChargeDialogRepository
16+
import com.mifos.core.data.repository.ChargeRepository
1717
import com.mifos.core.data.repository.CheckerInboxRepository
1818
import com.mifos.core.data.repository.CheckerInboxTasksRepository
19-
import com.mifos.core.data.repository.ClientChargeRepository
2019
import com.mifos.core.data.repository.ClientDetailsEditRepository
2120
import com.mifos.core.data.repository.ClientDetailsRepository
2221
import com.mifos.core.data.repository.ClientIdentifiersRepository
@@ -76,10 +75,9 @@ import com.mifos.core.data.repository.SyncSavingsAccountTransactionRepository
7675
import com.mifos.core.data.repositoryImp.ActivateRepositoryImp
7776
import com.mifos.core.data.repositoryImp.CenterDetailsRepositoryImp
7877
import com.mifos.core.data.repositoryImp.CenterListRepositoryImp
79-
import com.mifos.core.data.repositoryImp.ChargeDialogRepositoryImp
78+
import com.mifos.core.data.repositoryImp.ChargeRepositoryImp
8079
import com.mifos.core.data.repositoryImp.CheckerInboxRepositoryImp
8180
import com.mifos.core.data.repositoryImp.CheckerInboxTasksRepositoryImp
82-
import com.mifos.core.data.repositoryImp.ClientChargeRepositoryImp
8381
import com.mifos.core.data.repositoryImp.ClientDetailsEditRepositoryImpl
8482
import com.mifos.core.data.repositoryImp.ClientDetailsRepositoryImp
8583
import com.mifos.core.data.repositoryImp.ClientIdentifiersRepositoryImp
@@ -152,7 +150,7 @@ val RepositoryModule = module {
152150
// Client
153151
singleOf(::ClientDetailsRepositoryImp) bind ClientDetailsRepository::class
154152
singleOf(::ClientListRepositoryImp) bind ClientListRepository::class
155-
singleOf(::ClientChargeRepositoryImp) bind ClientChargeRepository::class
153+
singleOf(::ChargeRepositoryImp) bind ChargeRepository::class
156154
singleOf(::ClientIdentifiersRepositoryImp) bind ClientIdentifiersRepository::class
157155
singleOf(::CreateNewClientRepositoryImp) bind CreateNewClientRepository::class
158156
singleOf(::ClientDetailsEditRepositoryImpl) bind ClientDetailsEditRepository::class
@@ -201,7 +199,6 @@ val RepositoryModule = module {
201199

202200
// Others
203201
singleOf(::ActivateRepositoryImp) bind ActivateRepository::class
204-
singleOf(::ChargeDialogRepositoryImp) bind ChargeDialogRepository::class
205202
singleOf(::CheckerInboxRepositoryImp) bind CheckerInboxRepository::class
206203
singleOf(::CheckerInboxTasksRepositoryImp) bind CheckerInboxTasksRepository::class
207204
singleOf(::DataTableDataRepositoryImp) bind DataTableDataRepository::class

core/data/src/commonMain/kotlin/com/mifos/core/data/pagingSource/ClientChargesPagingSource.kt

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import com.mifos.room.entities.client.ChargesEntity
1616
import kotlinx.coroutines.flow.first
1717

1818
class ClientChargesPagingSource(
19-
private val clientId: Int,
19+
private val resourceType: String,
20+
private val resourceId: Int,
2021
private val dataManagerCharge: DataManagerCharge,
2122
) :
2223
PagingSource<Int, ChargesEntity>() {
@@ -33,7 +34,7 @@ class ClientChargesPagingSource(
3334
override suspend fun load(params: LoadParams<Int>): LoadResult<Int, ChargesEntity> {
3435
val position = params.key ?: 0
3536
return try {
36-
val (clientChargesList, totalCharges) = getClientChargeList(clientId, position)
37+
val (clientChargesList, totalCharges) = getListOfPagingCharges(resourceType, resourceId, position)
3738

3839
LoadResult.Page(
3940
data = clientChargesList,
@@ -45,12 +46,14 @@ class ClientChargesPagingSource(
4546
}
4647
}
4748

48-
private suspend fun getClientChargeList(
49-
clientId: Int,
49+
private suspend fun getListOfPagingCharges(
50+
resourceType: String,
51+
resourceId: Int,
5052
position: Int,
5153
): Pair<List<ChargesEntity>, Int> {
52-
val page = dataManagerCharge.getClientCharges(
53-
clientId = clientId,
54+
val page = dataManagerCharge.getListOfPagingCharges(
55+
resourceType = resourceType,
56+
resourceId = resourceId,
5457
offset = position,
5558
limit = 10,
5659
).first()

core/data/src/commonMain/kotlin/com/mifos/core/data/repository/ChargeDialogRepository.kt

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2024 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/android-client/blob/master/LICENSE.md
9+
*/
10+
package com.mifos.core.data.repository
11+
12+
import androidx.paging.PagingData
13+
import com.mifos.core.common.utils.DataState
14+
import com.mifos.core.model.objects.clients.ChargeCreationResponse
15+
import com.mifos.core.model.objects.clients.Page
16+
import com.mifos.core.model.objects.payloads.ChargesPayload
17+
import com.mifos.core.model.objects.template.client.ChargeTemplate
18+
import com.mifos.room.entities.client.ChargesEntity
19+
import kotlinx.coroutines.flow.Flow
20+
21+
/**
22+
* Created by Aditya Gupta on 08/08/23.
23+
*/
24+
interface ChargeRepository {
25+
26+
fun getListOfPagingCharges(
27+
resourceType: String,
28+
resourceId: Int,
29+
): Flow<PagingData<ChargesEntity>>
30+
31+
suspend fun getChargeTemplate(resourceType: String, resourceId: Int): ChargeTemplate
32+
33+
suspend fun createCharges(
34+
resourceType: String,
35+
resourceId: Int,
36+
payload: ChargesPayload,
37+
): ChargeCreationResponse
38+
39+
suspend fun deleteCharge(
40+
resourceId: Int,
41+
resourceType: String,
42+
chargeId: Int,
43+
): Flow<DataState<Unit>>
44+
45+
suspend fun updateCharge(
46+
resourceId: Int,
47+
resourceType: String,
48+
chargeId: Int,
49+
payload: ChargesPayload,
50+
): Flow<DataState<Unit>>
51+
52+
fun getListOfClientCharges(
53+
resourceType: String,
54+
resourceId: Int,
55+
): Flow<DataState<Page<ChargesEntity>>>
56+
57+
fun getListOfOtherAccountCharge(
58+
resourceType: String,
59+
resourceId: Int,
60+
): Flow<DataState<List<ChargesEntity>>>
61+
62+
fun getCharge(
63+
resourceType: String,
64+
resourceId: Int,
65+
chargeId: Int,
66+
): Flow<DataState<ChargesEntity>>
67+
}

core/data/src/commonMain/kotlin/com/mifos/core/data/repositoryImp/ChargeDialogRepositoryImp.kt

Lines changed: 0 additions & 35 deletions
This file was deleted.
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright 2024 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/android-client/blob/master/LICENSE.md
9+
*/
10+
package com.mifos.core.data.repositoryImp
11+
12+
import androidx.paging.Pager
13+
import androidx.paging.PagingConfig
14+
import androidx.paging.PagingData
15+
import com.mifos.core.common.utils.DataState
16+
import com.mifos.core.common.utils.asDataStateFlow
17+
import com.mifos.core.data.pagingSource.ClientChargesPagingSource
18+
import com.mifos.core.data.repository.ChargeRepository
19+
import com.mifos.core.model.objects.clients.ChargeCreationResponse
20+
import com.mifos.core.model.objects.clients.Page
21+
import com.mifos.core.model.objects.payloads.ChargesPayload
22+
import com.mifos.core.model.objects.template.client.ChargeTemplate
23+
import com.mifos.core.network.datamanager.DataManagerCharge
24+
import com.mifos.room.entities.client.ChargesEntity
25+
import kotlinx.coroutines.flow.Flow
26+
import kotlinx.coroutines.flow.flow
27+
28+
class ChargeRepositoryImp(
29+
private val dataManagerCharge: DataManagerCharge,
30+
) : ChargeRepository {
31+
32+
override fun getListOfPagingCharges(
33+
resourceType: String,
34+
resourceId: Int,
35+
): Flow<PagingData<ChargesEntity>> {
36+
return Pager(
37+
config = PagingConfig(
38+
pageSize = 10,
39+
),
40+
pagingSourceFactory = {
41+
ClientChargesPagingSource(resourceType, resourceId, dataManagerCharge)
42+
},
43+
).flow
44+
}
45+
46+
override suspend fun getChargeTemplate(resourceType: String, resourceId: Int): ChargeTemplate {
47+
return dataManagerCharge.getChargeTemplate(resourceType, resourceId)
48+
}
49+
50+
override suspend fun createCharges(
51+
resourceType: String,
52+
resourceId: Int,
53+
payload: ChargesPayload,
54+
): ChargeCreationResponse {
55+
return dataManagerCharge.createCharges(
56+
resourceId = resourceId,
57+
resourceType = resourceType,
58+
payload = payload,
59+
)
60+
}
61+
62+
override suspend fun deleteCharge(
63+
resourceId: Int,
64+
resourceType: String,
65+
chargeId: Int,
66+
): Flow<DataState<Unit>> {
67+
return flow {
68+
emit(
69+
dataManagerCharge.deleteCharge(
70+
resourceId = resourceId,
71+
resourceType = resourceType,
72+
chargeId = chargeId,
73+
),
74+
)
75+
}.asDataStateFlow()
76+
}
77+
78+
override suspend fun updateCharge(
79+
resourceId: Int,
80+
resourceType: String,
81+
chargeId: Int,
82+
payload: ChargesPayload,
83+
): Flow<DataState<Unit>> {
84+
return flow {
85+
emit(
86+
dataManagerCharge.updateCharge(
87+
resourceId = resourceId,
88+
resourceType = resourceType,
89+
chargeId = chargeId,
90+
payload = payload,
91+
),
92+
)
93+
}.asDataStateFlow()
94+
}
95+
96+
override fun getListOfClientCharges(
97+
resourceType: String,
98+
resourceId: Int,
99+
): Flow<DataState<Page<ChargesEntity>>> {
100+
return dataManagerCharge.getListOfClientCharges(resourceType, resourceId).asDataStateFlow()
101+
}
102+
103+
override fun getListOfOtherAccountCharge(
104+
resourceType: String,
105+
resourceId: Int,
106+
): Flow<DataState<List<ChargesEntity>>> {
107+
return dataManagerCharge.getListOfOtherAccountCharge(resourceType, resourceId)
108+
.asDataStateFlow()
109+
}
110+
111+
override fun getCharge(
112+
resourceType: String,
113+
resourceId: Int,
114+
chargeId: Int,
115+
): Flow<DataState<ChargesEntity>> {
116+
return dataManagerCharge.getCharge(
117+
resourceId = resourceId,
118+
resourceType = resourceType,
119+
chargeId = chargeId,
120+
).asDataStateFlow()
121+
}
122+
}

core/data/src/commonMain/kotlin/com/mifos/core/data/repositoryImp/ClientChargeRepositoryImp.kt

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

0 commit comments

Comments
 (0)