forked from openMF/android-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
40 changed files
with
3,060 additions
and
1,076 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
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
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
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
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
41 changes: 41 additions & 0 deletions
41
core/domain/src/main/java/com/mifos/core/domain/use_cases/CreateLoanAccountUseCase.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.LoansPayload | ||
import com.mifos.core.data.repository.LoanAccountRepository | ||
import com.mifos.core.objects.accounts.loan.Loans | ||
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 CreateLoanAccountUseCase @Inject constructor(private val loanAccountRepository: LoanAccountRepository) { | ||
|
||
suspend operator fun invoke(loansPayload: LoansPayload): Flow<Resource<Loans>> = callbackFlow { | ||
try { | ||
trySend(Resource.Loading()) | ||
loanAccountRepository.createLoansAccount(loansPayload) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribeOn(Schedulers.io()) | ||
.subscribe(object : Subscriber<Loans>() { | ||
override fun onCompleted() {} | ||
|
||
override fun onError(exception: Throwable) { | ||
trySend(Resource.Error(exception.message.toString())) | ||
} | ||
|
||
override fun onNext(loans: Loans) { | ||
trySend(Resource.Success(loans)) | ||
} | ||
}) | ||
|
||
awaitClose { channel.close() } | ||
|
||
} catch (exception: Exception) { | ||
trySend(Resource.Error(exception.message.toString())) | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
core/domain/src/main/java/com/mifos/core/domain/use_cases/GetAllLoanUseCase.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,38 @@ | ||
package com.mifos.core.domain.use_cases | ||
|
||
import com.mifos.core.common.utils.Resource | ||
import com.mifos.core.data.repository.LoanAccountRepository | ||
import com.mifos.core.objects.organisation.LoanProducts | ||
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 GetAllLoanUseCase @Inject constructor(private val loanAccountRepository: LoanAccountRepository) { | ||
|
||
suspend operator fun invoke(): Flow<Resource<List<LoanProducts>>> = callbackFlow { | ||
try { | ||
trySend(Resource.Loading()) | ||
loanAccountRepository.allLoans() | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribeOn(Schedulers.io()) | ||
.subscribe(object : Subscriber<List<LoanProducts>>() { | ||
override fun onCompleted() {} | ||
|
||
override fun onError(exception: Throwable) { | ||
trySend(Resource.Error(exception.message.toString())) | ||
} | ||
|
||
override fun onNext(products: List<LoanProducts>) { | ||
trySend(Resource.Success(products)) | ||
} | ||
}) | ||
awaitClose { channel.close() } | ||
} catch (exception: Exception) { | ||
trySend(Resource.Error(exception.message.toString())) | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
core/domain/src/main/java/com/mifos/core/domain/use_cases/GetLoansAccountTemplateUseCase.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.LoanAccountRepository | ||
import com.mifos.core.objects.templates.loans.LoanTemplate | ||
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 GetLoansAccountTemplateUseCase @Inject constructor(private val loanAccountRepository: LoanAccountRepository) { | ||
|
||
suspend operator fun invoke(clientId: Int, productId: Int): Flow<Resource<LoanTemplate>> = | ||
callbackFlow { | ||
try { | ||
trySend(Resource.Loading()) | ||
loanAccountRepository.getLoansAccountTemplate(clientId, productId) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.subscribeOn(Schedulers.io()) | ||
.subscribe(object : Subscriber<LoanTemplate>() { | ||
override fun onCompleted() {} | ||
|
||
override fun onError(exception: Throwable) { | ||
trySend(Resource.Error(exception.message.toString())) | ||
} | ||
|
||
override fun onNext(loanTemplate: LoanTemplate?) { | ||
trySend(Resource.Success(loanTemplate)) | ||
} | ||
}) | ||
|
||
awaitClose { channel.close() } | ||
|
||
} catch (exception: Exception) { | ||
trySend(Resource.Error(exception.message.toString())) | ||
} | ||
} | ||
} |
Oops, something went wrong.