Skip to content
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

fix #1525: fixed authentication logic #1526

Merged
merged 1 commit into from
Feb 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.mifos.mobilewallet.core.domain.usecase.client

import org.mifos.mobilewallet.core.base.UseCase
import org.mifos.mobilewallet.core.data.fineract.entity.Page
import org.mifos.mobilewallet.core.data.fineract.entity.client.Client
import org.mifos.mobilewallet.core.data.fineract.entity.mapper.ClientDetailsMapper
import org.mifos.mobilewallet.core.data.fineract.repository.FineractRepository
Expand All @@ -19,27 +20,52 @@ class FetchClientData @Inject constructor(private val fineractRepository: Finera
@Inject
lateinit var clientDetailsMapper: ClientDetailsMapper

data class RequestValues(val clientid: Long) : UseCase.RequestValues
data class ResponseValue(val userDetails: org.mifos.mobilewallet.core.domain.model.client.Client) :
UseCase.ResponseValue
override fun executeUseCase(requestValues: RequestValues?) {
if (requestValues != null) {
fineractRepository.getSelfClientDetails(requestValues.clientid)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<Client>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA)
}

override fun executeUseCase(requestValues: RequestValues) {
fineractRepository.getSelfClientDetails(requestValues.clientid)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<Client>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA)
}

override fun onNext(client: Client) {
useCaseCallback.onSuccess(
ResponseValue(
clientDetailsMapper.transform(client)
override fun onNext(client: Client) {
useCaseCallback.onSuccess(
ResponseValue(
clientDetailsMapper.transform(client)
)
)
)
}
})
}
})
} else {
fineractRepository.selfClientDetails
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<Page<Client>>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(Constants.ERROR_FETCHING_CLIENT_DATA)
}

override fun onNext(client: Page<Client>) {
if (client.pageItems != null && client.pageItems.size != 0) {
useCaseCallback.onSuccess(
ResponseValue(
clientDetailsMapper
.transform(client.pageItems[0])
)
)
} else {
useCaseCallback.onError(Constants.NO_CLIENT_FOUND)
}
}
})
}
}

data class RequestValues(val clientid: Long) : UseCase.RequestValues
data class ResponseValue(val userDetails: org.mifos.mobilewallet.core.domain.model.client.Client) :
UseCase.ResponseValue
}
Loading