Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
WIP: Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed Apr 24, 2022
1 parent 5b4343f commit 63837c4
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ExchangeAct @Inject constructor(
)
}

fun exchangeActInput(
fun actInput(
data: ExchangeData,
amount: BigDecimal
): ExchangeAct.Input = ExchangeAct.Input(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ivy.wallet.domain.action.category

import com.ivy.fp.action.FPAction
import com.ivy.fp.action.thenMap
import com.ivy.wallet.domain.data.core.Category
import com.ivy.wallet.io.persistence.dao.CategoryDao
import javax.inject.Inject

class CategoriesAct @Inject constructor(
private val categoryDao: CategoryDao
) : FPAction<Unit, List<Category>>() {
override suspend fun Unit.compose(): suspend () -> List<Category> = suspend {
io {
categoryDao.findAll()
}
} thenMap { it.toDomain() }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.ivy.wallet.domain.action.category

import com.ivy.fp.action.FPAction
import com.ivy.fp.action.thenMap
import com.ivy.wallet.domain.data.core.Transaction
import com.ivy.wallet.domain.pure.data.ClosedTimeRange
import com.ivy.wallet.io.persistence.dao.TransactionDao
import java.util.*
import javax.inject.Inject

class CategoryTrnsBetweenAct @Inject constructor(
private val transactionDao: TransactionDao
) : FPAction<CategoryTrnsBetweenAct.Input, List<Transaction>>() {

override suspend fun Input.compose(): suspend () -> List<Transaction> = suspend {
io {
transactionDao.findAllByCategoryAndBetween(
startDate = between.from,
endDate = between.to,
categoryId = categoryId
)
}
} thenMap { it.toDomain() }

data class Input(
val categoryId: UUID,
val between: ClosedTimeRange
)
}

fun actInput(
categoryId: UUID,
between: ClosedTimeRange
) = CategoryTrnsBetweenAct.Input(
categoryId = categoryId,
between = between
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.ivy.wallet.domain.action.transaction
import com.ivy.fp.action.FPAction
import com.ivy.fp.then
import com.ivy.wallet.domain.action.ExchangeAct
import com.ivy.wallet.domain.action.exchangeActInput
import com.ivy.wallet.domain.action.actInput
import com.ivy.wallet.domain.data.TransactionHistoryItem
import com.ivy.wallet.domain.data.core.Transaction
import com.ivy.wallet.domain.pure.wallet.withDateDividers
Expand All @@ -19,7 +19,7 @@ class AddDateDividersAct @Inject constructor(
transactions.withDateDividers(
baseCurrencyCode = baseCurrency,
getAccount = accountDao::findById then { it?.toDomain() },
exchange = ::exchangeActInput then exchangeAct
exchange = ::actInput then exchangeAct
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,15 @@ import com.ivy.wallet.domain.data.TransactionType
import com.ivy.wallet.domain.data.core.Account
import com.ivy.wallet.domain.data.core.Category
import com.ivy.wallet.domain.data.core.Transaction
import com.ivy.wallet.domain.logic.*
import com.ivy.wallet.domain.logic.currency.ExchangeRatesLogic
import com.ivy.wallet.domain.deprecated.logic.*
import com.ivy.wallet.domain.deprecated.logic.currency.ExchangeRatesLogic
import com.ivy.wallet.domain.deprecated.sync.uploader.AccountUploader
import com.ivy.wallet.domain.deprecated.sync.uploader.CategoryUploader
import com.ivy.wallet.domain.pure.account.calculateAccountBalance
import com.ivy.wallet.domain.pure.account.calculateAccountIncomeExpense
import com.ivy.wallet.domain.pure.data.WalletDAOs
import com.ivy.wallet.domain.pure.exchangeToBaseCurrency
import com.ivy.wallet.domain.pure.wallet.baseCurrencyCode
import com.ivy.wallet.domain.pure.wallet.withDateDividers
import com.ivy.wallet.domain.sync.uploader.AccountUploader
import com.ivy.wallet.domain.sync.uploader.CategoryUploader
import com.ivy.wallet.io.persistence.dao.*
import com.ivy.wallet.stringRes
import com.ivy.wallet.ui.ItemStatistic
Expand Down

0 comments on commit 63837c4

Please sign in to comment.