Skip to content

Commit

Permalink
refactor #1505: migrated client usecase to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
PratyushSingh07 authored and therajanmaurya committed Feb 14, 2024
1 parent ddc29f8 commit fed2835
Show file tree
Hide file tree
Showing 18 changed files with 281 additions and 525 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.mifos.mobilewallet.core.domain.usecase.client

import org.mifos.mobilewallet.core.base.UseCase
import org.mifos.mobilewallet.core.data.fineract.repository.FineractRepository
import org.mifos.mobilewallet.core.domain.model.client.NewClient
import org.mifos.mobilewallet.core.utils.ErrorJsonMessageHelper.getUserMessage
import retrofit2.HttpException
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import javax.inject.Inject

/**
* Created by naman on 20/8/17.
*/
class CreateClient @Inject constructor(private val apiRepository: FineractRepository) :
UseCase<CreateClient.RequestValues, CreateClient.ResponseValue>() {

data class RequestValues(val client: NewClient) : UseCase.RequestValues
data class ResponseValue(val clientId: Int) : UseCase.ResponseValue

override fun executeUseCase(requestValues: RequestValues) {
apiRepository.createClient(requestValues.client)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<ResponseValue>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
var message: String
try {
message = (e as HttpException).response().errorBody().string()
message = getUserMessage(message)
} catch (e1: Exception) {
message = "Error"
}
useCaseCallback.onError(message)
}

override fun onNext(genericResponse: ResponseValue) {
useCaseCallback.onSuccess(genericResponse)
}
})
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.mifos.mobilewallet.core.domain.usecase.client

import org.mifos.mobilewallet.core.base.UseCase
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
import org.mifos.mobilewallet.core.utils.Constants
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import javax.inject.Inject

/**
* Created by naman on 17/6/17.
*/
class FetchClientData @Inject constructor(private val fineractRepository: FineractRepository) :
UseCase<FetchClientData.RequestValues, FetchClientData.ResponseValue>() {

@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) {
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)
)
)
}
})
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package org.mifos.mobilewallet.core.domain.usecase.client

import org.mifos.mobilewallet.core.base.UseCase
import org.mifos.mobilewallet.core.data.fineract.entity.client.Client
import org.mifos.mobilewallet.core.data.fineract.repository.FineractRepository
import org.mifos.mobilewallet.core.utils.Constants
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import javax.inject.Inject

/**
* Created by ankur on 24/July/2018
*/
class FetchClientDetails @Inject constructor(private val mFineractRepository: FineractRepository) :
UseCase<FetchClientDetails.RequestValues, FetchClientDetails.ResponseValue>() {

data class RequestValues(val clientId: Long) : UseCase.RequestValues
data class ResponseValue(val client: Client) : UseCase.ResponseValue

override fun executeUseCase(requestValues: RequestValues) {
mFineractRepository.getClientDetails(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(client))
}
})
}
}
Loading

0 comments on commit fed2835

Please sign in to comment.