Skip to content

Commit

Permalink
getSavingsWithAssociations in SavingsAccountService migrated to ktor (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
PratyushSingh07 authored Sep 4, 2024
1 parent 1fda280 commit 7089ebc
Show file tree
Hide file tree
Showing 29 changed files with 138 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
*/
package org.mifospay.core.data.domain.usecase.account

import android.util.Log
import com.mifospay.core.model.domain.Transaction
import com.mifospay.core.model.entity.accounts.savings.SavingsWithAssociations
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import org.mifospay.core.data.base.UseCase
import org.mifospay.core.data.fineract.entity.mapper.TransactionMapper
import org.mifospay.core.data.fineract.repository.FineractRepository
import org.mifospay.core.data.util.Constants
import rx.Subscriber
import rx.android.schedulers.AndroidSchedulers
import rx.schedulers.Schedulers
import javax.inject.Inject

class FetchAccountTransactions @Inject constructor(
Expand All @@ -26,27 +27,26 @@ class FetchAccountTransactions @Inject constructor(
) : UseCase<FetchAccountTransactions.RequestValues, FetchAccountTransactions.ResponseValue?>() {

override fun executeUseCase(requestValues: RequestValues) {
fineractRepository.getSelfAccountTransactions(requestValues.accountId)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(Schedulers.io())
.subscribe(
object : Subscriber<SavingsWithAssociations>() {
override fun onCompleted() {}
override fun onError(e: Throwable) {
useCaseCallback.onError(
Constants.ERROR_FETCHING_REMOTE_ACCOUNT_TRANSACTIONS,
)
}

override fun onNext(transactions: SavingsWithAssociations) {
useCaseCallback.onSuccess(
ResponseValue(
transactionMapper.transformTransactionList(transactions),
),
)
}
},
)
CoroutineScope(Dispatchers.IO).launch {
try {
val api = fineractRepository.getSelfAccountTransactions(requestValues.accountId)
withContext(Dispatchers.Main) {
Log.d("FetchTransactions@@@@","$api")
useCaseCallback.onSuccess(
ResponseValue(
transactionMapper.transformTransactionList(api),
),
)
}
} catch (e: Exception) {
withContext(Dispatchers.Main) {
Log.d("FetchTransactions@@@@","${e.message}")
useCaseCallback.onError(
Constants.ERROR_FETCHING_REMOTE_ACCOUNT_TRANSACTIONS,
)
}
}
}
}

data class RequestValues(var accountId: Long) : UseCase.RequestValues
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,8 @@ class FineractRepository @Inject constructor(
val selfClientDetails: Observable<Page<Client>>
get() = selfApiManager.clientsApi.clients

fun getSelfAccountTransactions(accountId: Long): Observable<SavingsWithAssociations> {
return selfApiManager.savingAccountsListApi.getSavingsWithAssociations(
suspend fun getSelfAccountTransactions(accountId: Long): SavingsWithAssociations {
return selfApiManager.ktorSavingsAccountApi.getSavingsWithAssociations(
accountId,
Constants.TRANSACTIONS,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
*/
package com.mifospay.core.model.domain

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

@Parcelize
@Serializable
data class Account(
var image: String = "",
var name: String,
var number: String,
var balance: Double = 0.0,
var id: Long = 0L,
var productId: Long = 0L,
var currency: com.mifospay.core.model.domain.Currency,
) : Parcelable
var currency: Currency,
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@
*/
package com.mifospay.core.model.domain

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

@Parcelize
@Serializable
data class Currency(
var code: String,
var displaySymbol: String,
var displayLabel: String,
) : Parcelable {
) {
constructor() : this("", "", "")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,31 @@
*/
package com.mifospay.core.model.domain

import android.os.Parcelable
import com.mifospay.core.model.entity.accounts.savings.TransferDetail
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

@Suppress("MaxLineLength")
@Parcelize
@Serializable
data class Transaction(
var transactionId: String? = null,
var clientId: Long = 0,
var accountId: Long = 0,
var amount: Double = 0.0,
var date: String? = null,
var currency: com.mifospay.core.model.domain.Currency = com.mifospay.core.model.domain.Currency(),
var transactionType: com.mifospay.core.model.domain.TransactionType = com.mifospay.core.model.domain.TransactionType.OTHER,
var currency: Currency = Currency(),
var transactionType: TransactionType = TransactionType.OTHER,
var transferId: Long = 0,
var transferDetail: TransferDetail = TransferDetail(),
var receiptId: String? = null,
) : Parcelable {
) {
constructor() : this(
"",
0,
0,
0.0,
"",
com.mifospay.core.model.domain.Currency(),
com.mifospay.core.model.domain.TransactionType.OTHER,
Currency(),
TransactionType.OTHER,
0,
TransferDetail(),
"",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ package com.mifospay.core.model.domain.client

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

@Parcelize
@Serializable
data class Client(
var name: String? = null,
var image: String,
var externalId: String? = null,
var clientId: Long = 0L,
var displayName: String,
var mobileNo: String,
) : Parcelable {
) {
constructor() : this("", "", "", 0L, "", "")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
*/
package com.mifospay.core.model.entity

import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

@Parcelize
@Serializable
data class Timeline(
var submittedOnDate: List<Int?> = ArrayList(),
var submittedByUsername: String? = null,
Expand All @@ -26,6 +25,6 @@ data class Timeline(
var closedByUsername: String? = null,
var closedByFirstname: String? = null,
var closedByLastname: String? = null,
) : Parcelable {
) {
constructor() : this(ArrayList(), "", "", "", ArrayList(), "", "", "", ArrayList(), "", "", "")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
*/
package com.mifospay.core.model.entity.accounts.savings

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

@Parcelize
@Serializable
data class Currency(

@SerializedName("code")
Expand All @@ -37,6 +36,6 @@ data class Currency(
@SerializedName("displayLabel")
var displayLabel: String = " ",

) : Parcelable {
) {
constructor() : this("", "", 0, 0, "", "", "")
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
*/
package com.mifospay.core.model.entity.accounts.savings

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

@Parcelize
@Serializable
data class PaymentDetailData(
@SerializedName("id")
var id: Int? = null,
Expand All @@ -35,6 +34,6 @@ data class PaymentDetailData(

@SerializedName("bankNumber")
var bankNumber: String? = null,
) : Parcelable {
) {
constructor() : this(null, null, null, null, null, null, null)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,15 @@
*/
package com.mifospay.core.model.entity.accounts.savings

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

@Parcelize
@Serializable
data class PaymentType(
@SerializedName("id")
var id: Int? = null,

@SerializedName("name")
var name: String? = null,

) : Parcelable
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
*/
package com.mifospay.core.model.entity.accounts.savings

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.mifospay.core.model.entity.client.DepositType
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

@Parcelize
@Serializable
data class SavingAccount(

@SerializedName("id")
Expand Down Expand Up @@ -62,7 +61,7 @@ data class SavingAccount(
@SerializedName("depositType")
var depositType: DepositType? = null,

) : Parcelable {
) {
fun isRecurring(): Boolean {
return this.depositType != null && this.depositType!!.isRecurring
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@
*/
package com.mifospay.core.model.entity.accounts.savings

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import com.mifospay.core.model.entity.client.DepositType
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

@Parcelize
@Serializable
data class SavingsWithAssociations(

@SerializedName("id")
Expand Down Expand Up @@ -86,7 +85,7 @@ data class SavingsWithAssociations(
@SerializedName("transactions")
var transactions: List<Transactions> = ArrayList(),

) : Parcelable {
) {
constructor() : this(
0L,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
*/
package com.mifospay.core.model.entity.accounts.savings

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

@Parcelize
@Serializable
data class Status(

@SerializedName("id")
Expand Down Expand Up @@ -54,7 +53,7 @@ data class Status(

@SerializedName("matured")
var matured: Boolean? = null,
) : Parcelable {
) {
constructor() : this(
null,
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
*/
package com.mifospay.core.model.entity.accounts.savings

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

@Parcelize
@Serializable
data class Summary(
@SerializedName("currency")
var currency: Currency? = null,
Expand Down Expand Up @@ -41,4 +40,4 @@ data class Summary(

@SerializedName("lastInterestCalculationDate")
var lastInterestCalculationDate: List<Int?>? = null,
) : Parcelable
)
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
*/
package com.mifospay.core.model.entity.accounts.savings

import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

@Parcelize
@Serializable
data class TimeLine(
@SerializedName("submittedOnDate")
var submittedOnDate: List<Int?> = ArrayList(),
Expand Down Expand Up @@ -50,7 +49,7 @@ data class TimeLine(

@SerializedName("activatedByLastname")
var activatedByLastname: String? = null,
) : Parcelable {
) {
constructor() : this(
ArrayList(),
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ package com.mifospay.core.model.entity.accounts.savings
import android.os.Parcelable
import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable

@Parcelize
@Serializable
data class TransactionType(
@SerializedName("id")
var id: Int? = null,
Expand Down Expand Up @@ -67,4 +68,4 @@ data class TransactionType(

@SerializedName("escheat")
var escheat: Boolean? = null,
) : Parcelable
)
Loading

0 comments on commit 7089ebc

Please sign in to comment.