This repository has been archived by the owner on Nov 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 712
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c600b7
commit 490eef0
Showing
23 changed files
with
289 additions
and
121 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -31,4 +31,5 @@ class AccTrnsAct @Inject constructor( | |
val accountId: UUID, | ||
val range: ClosedTimeRange | ||
) | ||
} | ||
} | ||
|
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
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/ivy/wallet/domain/action/settings/CalcBufferDiffAct.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,17 @@ | ||
package com.ivy.wallet.domain.action.settings | ||
|
||
import com.ivy.fp.action.FPAction | ||
import java.math.BigDecimal | ||
import javax.inject.Inject | ||
|
||
class CalcBufferDiffAct @Inject constructor() : FPAction<CalcBufferDiffAct.Input, BigDecimal>() { | ||
|
||
override suspend fun Input.compose(): suspend () -> BigDecimal = { | ||
balance - buffer | ||
} | ||
|
||
data class Input( | ||
val balance: BigDecimal, | ||
val buffer: BigDecimal | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/ivy/wallet/domain/action/settings/SettingsAct.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,15 @@ | ||
package com.ivy.wallet.domain.action.settings | ||
|
||
import com.ivy.fp.action.FPAction | ||
import com.ivy.fp.action.then | ||
import com.ivy.wallet.domain.data.core.Settings | ||
import com.ivy.wallet.io.persistence.dao.SettingsDao | ||
import javax.inject.Inject | ||
|
||
class SettingsAct @Inject constructor( | ||
private val settingsDao: SettingsDao | ||
) : FPAction<Unit, Settings>() { | ||
override suspend fun Unit.compose(): suspend () -> Settings = suspend { | ||
io { settingsDao.findFirst() } | ||
} then { it.toDomain() } | ||
} |
27 changes: 27 additions & 0 deletions
27
app/src/main/java/com/ivy/wallet/domain/action/transaction/HistoryWithDateDivsAct.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,27 @@ | ||
package com.ivy.wallet.domain.action.transaction | ||
|
||
import com.ivy.fp.action.FPAction | ||
import com.ivy.fp.action.then | ||
import com.ivy.wallet.domain.data.TransactionHistoryItem | ||
import com.ivy.wallet.domain.pure.data.ClosedTimeRange | ||
import javax.inject.Inject | ||
|
||
class HistoryWithDateDivsAct @Inject constructor( | ||
private val historyTrnsAct: HistoryTrnsAct, | ||
private val trnsWithDateDivsAct: TrnsWithDateDivsAct | ||
) : FPAction<HistoryWithDateDivsAct.Input, List<TransactionHistoryItem>>() { | ||
|
||
override suspend fun Input.compose(): suspend () -> List<TransactionHistoryItem> = suspend { | ||
HistoryTrnsAct.Input(range) | ||
} then historyTrnsAct then { trns -> | ||
TrnsWithDateDivsAct.Input( | ||
baseCurrency = baseCurrency, | ||
transactions = trns | ||
) | ||
} then trnsWithDateDivsAct | ||
|
||
data class Input( | ||
val range: ClosedTimeRange, | ||
val baseCurrency: String | ||
) | ||
} |
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
83 changes: 83 additions & 0 deletions
83
app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcBalanceIncsExpsAct.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,83 @@ | ||
package com.ivy.wallet.domain.action.viewmodel.home | ||
|
||
import arrow.core.nonEmptyListOf | ||
import arrow.core.toOption | ||
import com.ivy.fp.action.FPAction | ||
import com.ivy.fp.action.then | ||
import com.ivy.fp.action.thenMap | ||
import com.ivy.wallet.domain.action.ExchangeAct | ||
import com.ivy.wallet.domain.action.account.AccTrnsAct | ||
import com.ivy.wallet.domain.data.core.Account | ||
import com.ivy.wallet.domain.pure.ExchangeData | ||
import com.ivy.wallet.domain.pure.account.filterExcluded | ||
import com.ivy.wallet.domain.pure.data.ClosedTimeRange | ||
import com.ivy.wallet.domain.pure.data.IncomeExpensePair | ||
import com.ivy.wallet.domain.pure.transaction.AccountValueFunctions | ||
import com.ivy.wallet.domain.pure.transaction.foldTransactions | ||
import com.ivy.wallet.domain.pure.util.orZero | ||
import java.math.BigDecimal | ||
import javax.inject.Inject | ||
|
||
class CalcBalanceIncsExpsAct @Inject constructor( | ||
private val accTrnsAct: AccTrnsAct, | ||
private val exchangeAct: ExchangeAct | ||
) : FPAction<CalcBalanceIncsExpsAct.Input, CalcBalanceIncsExpsAct.Output>() { | ||
|
||
override suspend fun Input.compose(): suspend () -> Output = suspend { | ||
filterExcluded(accounts) | ||
} thenMap { acc -> | ||
Pair( | ||
acc, | ||
accTrnsAct( | ||
AccTrnsAct.Input( | ||
accountId = acc.id, | ||
range = range | ||
) | ||
) | ||
) | ||
} thenMap { (acc, trns) -> | ||
Pair( | ||
acc, | ||
foldTransactions( | ||
transactions = trns, | ||
valueFunctions = nonEmptyListOf( | ||
AccountValueFunctions::balance, | ||
AccountValueFunctions::income, | ||
AccountValueFunctions::expense | ||
), | ||
arg = acc.id | ||
) | ||
) | ||
} thenMap { (acc, stats) -> | ||
stats.map { | ||
exchangeAct( | ||
ExchangeAct.Input( | ||
data = ExchangeData( | ||
baseCurrency = baseCurrency, | ||
fromCurrency = acc.currency.toOption() | ||
), | ||
amount = it | ||
), | ||
).orZero() | ||
} | ||
} then { statsList -> | ||
Output( | ||
balance = statsList[0].sumOf { it }, | ||
incomeExpense = IncomeExpensePair( | ||
income = statsList[1].sumOf { it }, | ||
expense = statsList[2].sumOf { it } | ||
) | ||
) | ||
} | ||
|
||
data class Input( | ||
val baseCurrency: String, | ||
val accounts: List<Account>, | ||
val range: ClosedTimeRange, | ||
) | ||
|
||
data class Output( | ||
val balance: BigDecimal, | ||
val incomeExpense: IncomeExpensePair, | ||
) | ||
} |
4 changes: 4 additions & 0 deletions
4
app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcHomeDueStatsAct.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,4 @@ | ||
package com.ivy.wallet.domain.action.viewmodel.home | ||
|
||
class CalcHomeDueStatsAct { | ||
} |
5 changes: 3 additions & 2 deletions
5
app/src/main/java/com/ivy/wallet/domain/data/core/Settings.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
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
6 changes: 6 additions & 0 deletions
6
app/src/main/java/com/ivy/wallet/domain/pure/account/AccountFunctions.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,6 @@ | ||
package com.ivy.wallet.domain.pure.account | ||
|
||
import com.ivy.wallet.domain.data.core.Account | ||
|
||
fun filterExcluded(accounts: List<Account>): List<Account> = | ||
accounts.filter { it.includeInBalance } |
29 changes: 0 additions & 29 deletions
29
app/src/main/java/com/ivy/wallet/domain/pure/data/FPAccount.kt
This file was deleted.
Oops, something went wrong.
3 changes: 1 addition & 2 deletions
3
...y/wallet/domain/pure/AccValueFunctions.kt → ...ain/pure/transaction/AccValueFunctions.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
3 changes: 1 addition & 2 deletions
3
...y/wallet/domain/pure/CatValueFunctions.kt → ...ain/pure/transaction/CatValueFunctions.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
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
Oops, something went wrong.