-
Notifications
You must be signed in to change notification settings - Fork 698
feat(loan): implement disburse screen for approved loan account #2659
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
kartikey004
wants to merge
10
commits into
openMF:dev
from
kartikey004:feature/loan-disbursement-screen
Closed
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0a18ad2
feat(loan): implement disburse screen (approved loan account)
kartikey004 b329fe9
requested changes made
kartikey004 3fccad7
requested changes made
kartikey004 7c48b2f
requested changes made
kartikey004 c3f001e
requested changes made
kartikey004 35d6a44
requested changes made
kartikey004 a3761e6
requested changes made
kartikey004 9c4abfa
requested changes made
kartikey004 3ee38b4
moved network monitoring to repository layer
kartikey004 0d53fa8
Merge branch 'development' into feature/loan-disbursement-screen
biplab1 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -12,32 +12,65 @@ package com.mifos.core.data.repositoryImp | |
| import com.mifos.core.common.utils.DataState | ||
| import com.mifos.core.common.utils.asDataStateFlow | ||
| import com.mifos.core.data.repository.LoanAccountDisbursementRepository | ||
| import com.mifos.core.data.util.NetworkMonitor | ||
| import com.mifos.core.model.objects.account.loan.LoanDisbursement | ||
| import com.mifos.core.network.GenericResponse | ||
| import com.mifos.core.network.datamanager.DataManagerLoan | ||
| import com.mifos.room.entities.templates.loans.LoanTransactionTemplate | ||
| import kotlinx.coroutines.CoroutineDispatcher | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.combine | ||
| import kotlinx.coroutines.flow.first | ||
| import kotlinx.coroutines.flow.flowOn | ||
|
|
||
| /** | ||
| * Created by Aditya Gupta on 10/08/23. | ||
| */ | ||
| class LoanAccountDisbursementRepositoryImp( | ||
| private val dataManagerLoan: DataManagerLoan, | ||
| private val ioDispatcher: CoroutineDispatcher, | ||
| private val networkMonitor: NetworkMonitor, | ||
| ) : LoanAccountDisbursementRepository { | ||
|
|
||
| override fun getLoanTransactionTemplate( | ||
| loanId: Int, | ||
| command: String?, | ||
| ): Flow<DataState<LoanTransactionTemplate>> { | ||
| return dataManagerLoan.getLoanTransactionTemplate(loanId, command) | ||
| .asDataStateFlow() | ||
| return combine( | ||
| networkMonitor.isOnline, | ||
| dataManagerLoan.getLoanTransactionTemplate(loanId, command) | ||
| .asDataStateFlow(), | ||
| ) { isOnline, dataState -> | ||
| if (!isOnline && dataState !is DataState.Success) { | ||
| DataState.Error(NetworkUnavailableException()) | ||
| } else { | ||
| dataState | ||
| } | ||
| }.flowOn(ioDispatcher) | ||
| } | ||
|
|
||
| override fun disburseLoan( | ||
| override suspend fun disburseLoan( | ||
| loanId: Int, | ||
| loanDisbursement: LoanDisbursement?, | ||
| ): Flow<DataState<GenericResponse>> { | ||
| return dataManagerLoan.disburseLoan(loanId, loanDisbursement) | ||
| .asDataStateFlow() | ||
| ): DataState<GenericResponse> { | ||
| return try { | ||
| if (!networkMonitor.isOnline.first()) { | ||
| return DataState.Error(NetworkUnavailableException()) | ||
| } | ||
|
|
||
| val response = dataManagerLoan.disburseLoan(loanId, loanDisbursement) | ||
| .asDataStateFlow() | ||
| .first { it !is DataState.Loading } | ||
|
|
||
|
Comment on lines
+61
to
+64
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're converting a one-shot API call into a Flow. If API is one-shot -> keep it simple: return try {
val response = dataManagerLoan.disburseLoan(...)
DataState.Success(response)
} catch (e: Exception) {
DataState.Error(e)
}Or expose suspend -> not Flow |
||
| if (response is DataState.Success) { | ||
| DataState.Success(response.data) | ||
| } else { | ||
| DataState.Error((response as DataState.Error).exception) | ||
| } | ||
| } catch (e: Exception) { | ||
| DataState.Error(e) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| class NetworkUnavailableException : IllegalStateException() | ||
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This follows the approach suggested by @niyajali, but the current
combineusage doesn’t actually prevent upstream calls when offline and may lead to incorrect error mapping.I would suggest that we should align on the exact expected behavior/implementation details on Slack before proceeding, to avoid unintended side effects.