-
Notifications
You must be signed in to change notification settings - Fork 603
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: refactor group details to compose with multi module
- Loading branch information
1 parent
41bc7ab
commit f9e15a5
Showing
14 changed files
with
1,092 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
core/data/src/main/java/com/mifos/core/data/repository/GroupDetailsRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.mifos.core.data.repository | ||
|
||
import com.mifos.core.objects.accounts.GroupAccounts | ||
import com.mifos.core.objects.group.Group | ||
import com.mifos.core.objects.group.GroupWithAssociations | ||
import rx.Observable | ||
|
||
/** | ||
* Created by Aditya Gupta on 06/08/23. | ||
*/ | ||
interface GroupDetailsRepository { | ||
|
||
fun getGroup(groupId: Int): Observable<Group> | ||
|
||
fun getGroupAccounts(groupId: Int): Observable<GroupAccounts> | ||
|
||
fun getGroupWithAssociations(groupId: Int): Observable<GroupWithAssociations> | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
core/data/src/main/java/com/mifos/core/data/repository_imp/GroupDetailsRepositoryImp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.mifos.core.data.repository_imp | ||
|
||
import com.mifos.core.data.repository.GroupDetailsRepository | ||
import com.mifos.core.network.datamanager.DataManagerGroups | ||
import com.mifos.core.objects.accounts.GroupAccounts | ||
import com.mifos.core.objects.group.Group | ||
import com.mifos.core.objects.group.GroupWithAssociations | ||
import rx.Observable | ||
import javax.inject.Inject | ||
|
||
/** | ||
* Created by Aditya Gupta on 06/08/23. | ||
*/ | ||
class GroupDetailsRepositoryImp @Inject constructor(private val dataManagerGroups: DataManagerGroups) : | ||
GroupDetailsRepository { | ||
|
||
override fun getGroup(groupId: Int): Observable<Group> { | ||
return dataManagerGroups.getGroup(groupId) | ||
} | ||
|
||
override fun getGroupAccounts(groupId: Int): Observable<GroupAccounts> { | ||
return dataManagerGroups.getGroupAccounts(groupId) | ||
} | ||
|
||
override fun getGroupWithAssociations(groupId: Int): Observable<GroupWithAssociations> { | ||
return dataManagerGroups.getGroupWithAssociations(groupId) | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
core/domain/src/main/java/com/mifos/core/domain/use_cases/GetGroupAssociateClientsUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.mifos.core.domain.use_cases | ||
|
||
import com.mifos.core.common.utils.Resource | ||
import com.mifos.core.data.repository.GroupDetailsRepository | ||
import com.mifos.core.objects.client.Client | ||
import com.mifos.core.objects.group.GroupWithAssociations | ||
import kotlinx.coroutines.channels.awaitClose | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.callbackFlow | ||
import rx.Subscriber | ||
import rx.android.schedulers.AndroidSchedulers | ||
import rx.schedulers.Schedulers | ||
import javax.inject.Inject | ||
|
||
class GetGroupAssociateClientsUseCase @Inject constructor(private val groupDetailsRepository: GroupDetailsRepository) { | ||
|
||
suspend operator fun invoke(groupId: Int): Flow<Resource<List<Client>>> = callbackFlow { | ||
try { | ||
trySend(Resource.Loading()) | ||
|
||
groupDetailsRepository.getGroupWithAssociations(groupId) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribeOn(Schedulers.io()) | ||
.subscribe(object : Subscriber<GroupWithAssociations>() { | ||
override fun onCompleted() {} | ||
|
||
override fun onError(exception: Throwable) { | ||
trySend(Resource.Error(exception.message.toString())) | ||
} | ||
|
||
override fun onNext(groupWithAssociations: GroupWithAssociations) { | ||
trySend(Resource.Success(groupWithAssociations.clientMembers)) | ||
} | ||
}) | ||
|
||
awaitClose { channel.close() } | ||
} catch (exception: Exception) { | ||
trySend(Resource.Error(exception.message.toString())) | ||
} | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
core/domain/src/main/java/com/mifos/core/domain/use_cases/GetGroupDetailsUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.mifos.core.domain.use_cases | ||
|
||
import com.mifos.core.common.utils.Resource | ||
import com.mifos.core.data.repository.GroupDetailsRepository | ||
import com.mifos.core.objects.zipmodels.GroupAndGroupAccounts | ||
import kotlinx.coroutines.channels.awaitClose | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.callbackFlow | ||
import rx.Observable | ||
import rx.Subscriber | ||
import rx.android.schedulers.AndroidSchedulers | ||
import rx.schedulers.Schedulers | ||
import javax.inject.Inject | ||
|
||
class GetGroupDetailsUseCase @Inject constructor(private val repository: GroupDetailsRepository) { | ||
|
||
suspend operator fun invoke(groupId: Int): Flow<Resource<GroupAndGroupAccounts>> = | ||
callbackFlow { | ||
try { | ||
trySend(Resource.Loading()) | ||
Observable.combineLatest( | ||
repository.getGroup(groupId), | ||
repository.getGroupAccounts(groupId) | ||
) { group, groupAccounts -> GroupAndGroupAccounts(group, groupAccounts) } | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribeOn(Schedulers.io()) | ||
.subscribe(object : Subscriber<GroupAndGroupAccounts>() { | ||
override fun onCompleted() {} | ||
|
||
override fun onError(e: Throwable) { | ||
trySend(Resource.Error(e.message.toString())) | ||
} | ||
|
||
override fun onNext(groupAndGroupAccounts: GroupAndGroupAccounts) { | ||
trySend(Resource.Success(groupAndGroupAccounts)) | ||
} | ||
}) | ||
|
||
awaitClose { channel.close() } | ||
} catch (exception: Exception) { | ||
trySend(Resource.Error(exception.message.toString())) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.