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

refactor : converted core model java class to kotilin data class #1545

Merged
merged 8 commits into from
Feb 29, 2024

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.mifos.mobilewallet.core.data.fineract.entity.mapper

import com.mifos.mobilewallet.model.entity.accounts.savings.SavingAccount
import com.mifos.mobilewallet.model.entity.client.ClientAccounts
import com.mifos.mobilewallet.model.domain.Account
import javax.inject.Inject

class AccountMapper @Inject constructor(private val currencyMapper: CurrencyMapper) {

fun transform(clientAccounts: ClientAccounts?): List<Account> {
val accountList = mutableListOf<Account>()

if (clientAccounts != null
&& !clientAccounts.savingsAccounts.isNullOrEmpty()) {

for (savingAccount in clientAccounts.savingsAccounts) {
val account = Account().apply {
name = savingAccount.productName
number = savingAccount.accountNo
id = savingAccount.id
balance = savingAccount.accountBalance
currency = currencyMapper.transform(savingAccount.currency)
productId = savingAccount.productId.toLong()
}

accountList.add(account)
}
}
return accountList
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.mifos.mobilewallet.core.data.fineract.entity.mapper

import com.mifos.mobilewallet.model.entity.client.Client
import javax.inject.Inject
import com.mifos.mobilewallet.model.domain.client.Client as DomainClient
/**
* Created by naman on 10/7/17.
*/
class ClientDetailsMapper @Inject constructor() {
fun transformList(clients: List<Client?>?): List<DomainClient> {
val clientList: MutableList<DomainClient> = ArrayList()
if (clients != null && clients.size != 0) {
for (client in clients) {
clientList.add(transform(client))
}
}
return clientList
}

fun transform(client: Client?): DomainClient {
val clientDetails = DomainClient()
if (client != null) {
clientDetails.name = client.displayName
clientDetails.clientId = client.id.toLong()
clientDetails.externalId = client.externalId
clientDetails.mobileNo = client.mobileNo
}
return clientDetails
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.mifos.mobilewallet.core.data.fineract.entity.mapper

import com.mifos.mobilewallet.model.entity.accounts.savings.Currency
import javax.inject.Inject

/**
* Created by naman on 17/8/17.
*/
class CurrencyMapper @Inject internal constructor() {
fun transform(savingsCurrency: Currency): com.mifos.mobilewallet.model.domain.Currency {
val currency: com.mifos.mobilewallet.model.domain.Currency =
com.mifos.mobilewallet.model.domain.Currency()
currency.code = savingsCurrency.code
currency.displayLabel = savingsCurrency.displayLabel
currency.displaySymbol = savingsCurrency.displaySymbol
return currency
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package org.mifos.mobilewallet.core.data.fineract.entity.mapper

import org.mifos.mobilewallet.core.base.UseCase
import org.mifos.mobilewallet.core.data.fineract.entity.mapper.AccountMapper
import org.mifos.mobilewallet.core.data.fineract.repository.FineractRepository
import org.mifos.mobilewallet.core.utils.Constants
import com.mifos.mobilewallet.model.domain.Account
import com.mifos.mobilewallet.model.entity.client.ClientAccounts
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers

import javax.inject.Inject

class FetchAccount @Inject constructor(
private val fineractRepository: FineractRepository,
private val accountMapper: AccountMapper
) : UseCase<FetchAccount.RequestValues, FetchAccount.ResponseValue>() {

override fun executeUseCase(requestValues: RequestValues) {
fineractRepository.getSelfAccounts(requestValues.clientId)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(object : Subscriber<ClientAccounts>() {
override fun onCompleted() {}

override fun onError(e: Throwable) {
useCaseCallback.onError(Constants.ERROR_FETCHING_ACCOUNTS)
}

override fun onNext(clientAccounts: ClientAccounts) {
val accounts: List<Account> = accountMapper.transform(clientAccounts)
if (accounts.isNotEmpty()) {
var walletAccount: Account? = null
for (account in accounts) {
if (account.productId.toInt() == Constants.WALLET_ACCOUNT_SAVINGS_PRODUCT_ID) {
walletAccount = account
break
}
}
if (walletAccount != null) {
useCaseCallback.onSuccess(ResponseValue(walletAccount))
} else {
useCaseCallback.onError(Constants.NO_ACCOUNT_FOUND)
}
} else {
useCaseCallback.onError(Constants.NO_ACCOUNTS_FOUND)
}
}
})
}

data class RequestValues(val clientId: Long) : UseCase.RequestValues

data class ResponseValue(val account: Account) : UseCase.ResponseValue
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.mifos.mobilewallet.core.data.fineract.entity.mapper

import com.mifos.mobilewallet.model.domain.SearchResult
import com.mifos.mobilewallet.model.entity.SearchedEntity
import javax.inject.Inject

/**
* Created by naman on 19/8/17.
*/
class SearchedEntitiesMapper @Inject internal constructor() {
fun transformList(searchedEntities: List<SearchedEntity>?): List<SearchResult> {
val searchResults: MutableList<SearchResult> = ArrayList()
if (!searchedEntities.isNullOrEmpty()) {
for (entity in searchedEntities) {
searchResults.add(transform(entity))
}
}
return searchResults
}

fun transform(searchedEntity: SearchedEntity): SearchResult {
val searchResult = SearchResult()
searchResult.resultId = searchedEntity.entityId
searchResult.resultName = searchedEntity.entityName
searchResult.resultType = searchedEntity.entityType
return searchResult
}
}
Loading
Loading