-
Notifications
You must be signed in to change notification settings - Fork 435
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor #1505: migrated client usecase to kotlin
- Loading branch information
1 parent
ddc29f8
commit fed2835
Showing
18 changed files
with
281 additions
and
525 deletions.
There are no files selected for viewing
80 changes: 0 additions & 80 deletions
80
core/data/src/main/java/org/mifos/mobilewallet/core/domain/usecase/client/CreateClient.java
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
core/data/src/main/java/org/mifos/mobilewallet/core/domain/usecase/client/CreateClient.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,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) | ||
} | ||
}) | ||
} | ||
} |
110 changes: 0 additions & 110 deletions
110
...data/src/main/java/org/mifos/mobilewallet/core/domain/usecase/client/FetchClientData.java
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
core/data/src/main/java/org/mifos/mobilewallet/core/domain/usecase/client/FetchClientData.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 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) | ||
) | ||
) | ||
} | ||
}) | ||
} | ||
} |
72 changes: 0 additions & 72 deletions
72
...a/src/main/java/org/mifos/mobilewallet/core/domain/usecase/client/FetchClientDetails.java
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
...ata/src/main/java/org/mifos/mobilewallet/core/domain/usecase/client/FetchClientDetails.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,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)) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.