Skip to content

Commit

Permalink
refactor #1497: migrated savedcards usecase to kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
PratyushSingh07 authored and therajanmaurya committed Feb 3, 2024
1 parent 640b2e8 commit 3775e1f
Show file tree
Hide file tree
Showing 7 changed files with 98 additions and 104 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,24 @@ import javax.inject.Inject
* Created by ankur on 21/May/2018
*/
class AddCard @Inject constructor(private val mFineractRepository: FineractRepository) :
UseCase<AddCard.RequestValues?, AddCard.ResponseValue?>() {
UseCase<AddCard.RequestValues, AddCard.ResponseValue>() {
class RequestValues(val clientId: Long, val card: Card) : UseCase.RequestValues
class ResponseValue : UseCase.ResponseValue

override fun executeUseCase(requestValues: RequestValues?) {
if (requestValues != null) {
mFineractRepository.addSavedCards(requestValues.clientId, requestValues.card)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<GenericResponse?>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(e.toString())
}
override fun executeUseCase(requestValues: RequestValues) {
mFineractRepository.addSavedCards(requestValues.clientId, requestValues.card)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<GenericResponse?>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(e.toString())
}

override fun onNext(t: GenericResponse?) {
useCaseCallback.onSuccess(ResponseValue())
}
})

override fun onNext(t: GenericResponse?) {
useCaseCallback.onSuccess(ResponseValue())
}
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@ import javax.inject.Inject
* Created by ankur on 22/May/2018
*/
class DeleteCard @Inject constructor(private val mFineractRepository: FineractRepository) :
UseCase<DeleteCard.RequestValues?, DeleteCard.ResponseValue?>() {
UseCase<DeleteCard.RequestValues, DeleteCard.ResponseValue>() {

class RequestValues(val clientId: Int, val cardId: Int) : UseCase.RequestValues
class ResponseValue : UseCase.ResponseValue

override fun executeUseCase(requestValues: RequestValues?) {
if (requestValues != null) {
mFineractRepository.deleteSavedCard(requestValues.clientId, requestValues.cardId)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<GenericResponse?>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(e.toString())
}
override fun executeUseCase(requestValues: RequestValues) {
mFineractRepository.deleteSavedCard(requestValues.clientId, requestValues.cardId)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<GenericResponse?>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(e.toString())
}

override fun onNext(t: GenericResponse?) {
useCaseCallback.onSuccess(ResponseValue())
}
})

override fun onNext(t: GenericResponse?) {
useCaseCallback.onSuccess(ResponseValue())
}
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,25 @@ import javax.inject.Inject
* Created by ankur on 22/May/2018
*/
class EditCard @Inject constructor(private val mFineractRepository: FineractRepository) :
UseCase<EditCard.RequestValues?, EditCard.ResponseValue?>() {
UseCase<EditCard.RequestValues, EditCard.ResponseValue>() {

class RequestValues(val clientId: Int, val card: Card) : UseCase.RequestValues
class ResponseValue : UseCase.ResponseValue

override fun executeUseCase(requestValues: RequestValues?) {
if (requestValues != null) {
mFineractRepository.editSavedCard(requestValues.clientId, requestValues.card)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<GenericResponse?>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(e.toString())
}
override fun executeUseCase(requestValues: RequestValues) {
mFineractRepository.editSavedCard(requestValues.clientId, requestValues.card)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<GenericResponse?>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(e.toString())
}

override fun onNext(t: GenericResponse?) {
useCaseCallback.onSuccess(ResponseValue())
}
})

override fun onNext(t: GenericResponse?) {
useCaseCallback.onSuccess(ResponseValue())
}
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,29 @@ import javax.inject.Inject
* Created by ankur on 21/May/2018
*/
class FetchSavedCards @Inject constructor(private val mFineractRepository: FineractRepository) :
UseCase<FetchSavedCards.RequestValues?, FetchSavedCards.ResponseValue?>() {
UseCase<FetchSavedCards.RequestValues, FetchSavedCards.ResponseValue>() {

class RequestValues(val clientId: Long) : UseCase.RequestValues
class ResponseValue(val cardList: List<Card?>) : UseCase.ResponseValue

override fun executeUseCase(requestValues: RequestValues?) {
if (requestValues != null) {
mFineractRepository.fetchSavedCards(requestValues.clientId)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<List<Card?>?>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(e.toString())
}
override fun executeUseCase(requestValues: RequestValues) {
mFineractRepository.fetchSavedCards(requestValues.clientId)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<List<Card?>?>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(e.toString())
}

override fun onNext(cards: List<Card?>?) {
if (cards != null) {
useCaseCallback.onSuccess(ResponseValue(cards))
} else {
useCaseCallback.onError(Constants.NO_SAVED_CARDS)
}
override fun onNext(cards: List<Card?>?) {
if (cards != null) {
useCaseCallback.onSuccess(ResponseValue(cards))
} else {
useCaseCallback.onError(Constants.NO_SAVED_CARDS)
}
})
}
}
})

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,25 @@ import javax.inject.Inject
* Created by ankur on 01/June/2018
*/
class FetchDeliveryMethods @Inject constructor(private val mFineractRepository: FineractRepository) :
UseCase<FetchDeliveryMethods.RequestValues?, FetchDeliveryMethods.ResponseValue?>() {
UseCase<FetchDeliveryMethods.RequestValues, FetchDeliveryMethods.ResponseValue>() {

class RequestValues : UseCase.RequestValues
class ResponseValue(
val deliveryMethodList: List<DeliveryMethod?>
) : UseCase.ResponseValue

override fun executeUseCase(requestValues: RequestValues?) {
override fun executeUseCase(requestValues: RequestValues) {
mFineractRepository.deliveryMethods
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<List<DeliveryMethod?>?>() {
.subscribe(object : Subscriber<List<DeliveryMethod?>>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(e.toString())
}

override fun onNext(deliveryMethods: List<DeliveryMethod?>?) {
useCaseCallback.onSuccess(deliveryMethods?.let { ResponseValue(it) })
override fun onNext(deliveryMethods: List<DeliveryMethod?>) {
useCaseCallback.onSuccess(ResponseValue(deliveryMethods))
}

})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,25 @@ import javax.inject.Inject
* Created by ankur on 01/June/2018
*/
class RequestOTP @Inject constructor(private val mFineractRepository: FineractRepository) :
UseCase<RequestOTP.RequestValues?, RequestOTP.ResponseValue?>() {
UseCase<RequestOTP.RequestValues, RequestOTP.ResponseValue>() {

class RequestValues(val deliveryMethod: String) : UseCase.RequestValues
class ResponseValue(val response: String) : UseCase.ResponseValue

override fun executeUseCase(requestValues: RequestValues?) {
requestValues?.let {
mFineractRepository.requestOTP(it.deliveryMethod)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<String?>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(e.toString())
}
override fun executeUseCase(requestValues: RequestValues) {
mFineractRepository.requestOTP(requestValues.deliveryMethod)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<String>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(e.toString())
}

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

override fun onNext(t: String?) {
useCaseCallback.onSuccess(t?.let { response -> ResponseValue(response) })
}
})
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@ import javax.inject.Inject
* Created by ankur on 01/June/2018
*/
class ValidateOTP @Inject constructor(private val mFineractRepository: FineractRepository) :
UseCase<ValidateOTP.RequestValues?, ValidateOTP.ResponseValue?>() {
UseCase<ValidateOTP.RequestValues, ValidateOTP.ResponseValue>() {

class RequestValues(val token: String) : UseCase.RequestValues
class ResponseValue(val accessToken: AccessToken) : UseCase.ResponseValue

override fun executeUseCase(requestValues: RequestValues?) {
if (requestValues != null) {
mFineractRepository.validateToken(requestValues.token)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<AccessToken?>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(e.toString())
}
override fun executeUseCase(requestValues: RequestValues) {
mFineractRepository.validateToken(requestValues.token)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<AccessToken>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(e.toString())
}

override fun onNext(accessToken: AccessToken?) {
useCaseCallback.onSuccess(accessToken?.let { ResponseValue(it) })
}
})

override fun onNext(accessToken: AccessToken?) {
useCaseCallback.onSuccess(accessToken?.let { ResponseValue(it) })
}
})
}
}
}

0 comments on commit 3775e1f

Please sign in to comment.