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
490eef0
commit 985a49f
Showing
26 changed files
with
327 additions
and
143 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
app/src/main/java/com/ivy/wallet/domain/action/account/AccountByIdAct.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,18 @@ | ||
package com.ivy.wallet.domain.action.account | ||
|
||
import com.ivy.fp.action.FPAction | ||
import com.ivy.fp.action.then | ||
import com.ivy.wallet.domain.data.core.Account | ||
import com.ivy.wallet.io.persistence.dao.AccountDao | ||
import java.util.* | ||
import javax.inject.Inject | ||
|
||
class AccountByIdAct @Inject constructor( | ||
private val accountDao: AccountDao | ||
) : FPAction<UUID, Account?>() { | ||
override suspend fun UUID.compose(): suspend () -> Account? = suspend { | ||
this //accountId | ||
} then accountDao::findById then { | ||
it?.toDomain() | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
...m/ivy/wallet/domain/action/ExchangeAct.kt → ...let/domain/action/exchange/ExchangeAct.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
22 changes: 22 additions & 0 deletions
22
app/src/main/java/com/ivy/wallet/domain/action/transaction/DueTrnsAct.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,22 @@ | ||
package com.ivy.wallet.domain.action.transaction | ||
|
||
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 javax.inject.Inject | ||
|
||
class DueTrnsAct @Inject constructor( | ||
private val transactionDao: TransactionDao | ||
) : FPAction<ClosedTimeRange, List<Transaction>>() { | ||
|
||
override suspend fun ClosedTimeRange.compose(): suspend () -> List<Transaction> = suspend { | ||
io { | ||
transactionDao.findAllDueToBetween( | ||
startDate = from, | ||
endDate = to | ||
) | ||
} | ||
} thenMap { it.toDomain() } | ||
} |
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
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
4 changes: 0 additions & 4 deletions
4
app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/CalcHomeDueStatsAct.kt
This file was deleted.
Oops, something went wrong.
73 changes: 73 additions & 0 deletions
73
app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/DueTrnsInfoAct.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,73 @@ | ||
package com.ivy.wallet.domain.action.viewmodel.home | ||
|
||
import com.ivy.fp.action.FPAction | ||
import com.ivy.fp.action.lambda | ||
import com.ivy.fp.action.then | ||
import com.ivy.fp.then | ||
import com.ivy.wallet.domain.action.account.AccountByIdAct | ||
import com.ivy.wallet.domain.action.exchange.ExchangeAct | ||
import com.ivy.wallet.domain.action.exchange.actInput | ||
import com.ivy.wallet.domain.action.transaction.DueTrnsAct | ||
import com.ivy.wallet.domain.data.core.Transaction | ||
import com.ivy.wallet.domain.pure.data.ClosedTimeRange | ||
import com.ivy.wallet.domain.pure.data.IncomeExpensePair | ||
import com.ivy.wallet.domain.pure.exchange.ExchangeTrnArgument | ||
import com.ivy.wallet.domain.pure.exchange.exchangeInCurrency | ||
import com.ivy.wallet.domain.pure.transaction.expenses | ||
import com.ivy.wallet.domain.pure.transaction.incomes | ||
import com.ivy.wallet.domain.pure.transaction.sumTrns | ||
import com.ivy.wallet.utils.timeNowUTC | ||
import java.time.LocalDateTime | ||
import javax.inject.Inject | ||
|
||
class DueTrnsInfoAct @Inject constructor( | ||
private val dueTrnsAct: DueTrnsAct, | ||
private val accountByIdAct: AccountByIdAct, | ||
private val exchangeAct: ExchangeAct | ||
) : FPAction<DueTrnsInfoAct.Input, DueTrnsInfoAct.Output>() { | ||
|
||
override suspend fun Input.compose(): suspend () -> Output = suspend { | ||
range | ||
} then dueTrnsAct then { trns -> | ||
val timeNow = timeNowUTC() | ||
trns.filter { | ||
this.dueFilter(it, timeNow) | ||
} | ||
} then { upcomingTrns -> | ||
//We have due transactions in different currencies | ||
val exchangeArg = ExchangeTrnArgument( | ||
baseCurrency = baseCurrency, | ||
exchange = ::actInput then exchangeAct, | ||
getAccount = accountByIdAct.lambda() | ||
) | ||
|
||
io { | ||
Output( | ||
dueIncomeExpense = IncomeExpensePair( | ||
income = sumTrns( | ||
incomes(upcomingTrns), | ||
::exchangeInCurrency, | ||
exchangeArg | ||
), | ||
expense = sumTrns( | ||
expenses(upcomingTrns), | ||
::exchangeInCurrency, | ||
exchangeArg | ||
) | ||
), | ||
dueTrns = upcomingTrns | ||
) | ||
} | ||
} | ||
|
||
data class Input( | ||
val range: ClosedTimeRange, | ||
val baseCurrency: String, | ||
val dueFilter: (Transaction, LocalDateTime) -> Boolean | ||
) | ||
|
||
data class Output( | ||
val dueIncomeExpense: IncomeExpensePair, | ||
val dueTrns: List<Transaction> | ||
) | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/HasTrnsAct.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.viewmodel.home | ||
|
||
import com.ivy.fp.action.FPAction | ||
import com.ivy.wallet.io.persistence.dao.TransactionDao | ||
import javax.inject.Inject | ||
|
||
class HasTrnsAct @Inject constructor( | ||
private val transactionDao: TransactionDao | ||
) : FPAction<Unit, Boolean>() { | ||
override suspend fun Unit.compose(): suspend () -> Boolean = suspend { | ||
io { | ||
transactionDao.findAll_LIMIT_1().isNotEmpty() | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/OverdueAct.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,37 @@ | ||
package com.ivy.wallet.domain.action.viewmodel.home | ||
|
||
import com.ivy.fp.action.FPAction | ||
import com.ivy.fp.action.then | ||
import com.ivy.wallet.domain.data.core.Transaction | ||
import com.ivy.wallet.domain.pure.data.ClosedTimeRange | ||
import com.ivy.wallet.domain.pure.data.IncomeExpensePair | ||
import com.ivy.wallet.domain.pure.transaction.isOverdue | ||
import javax.inject.Inject | ||
|
||
class OverdueAct @Inject constructor( | ||
private val dueTrnsInfoAct: DueTrnsInfoAct | ||
) : FPAction<OverdueAct.Input, OverdueAct.Output>() { | ||
|
||
override suspend fun Input.compose(): suspend () -> Output = suspend { | ||
DueTrnsInfoAct.Input( | ||
range = range, | ||
baseCurrency = baseCurrency, | ||
dueFilter = ::isOverdue | ||
) | ||
} then dueTrnsInfoAct then { | ||
Output( | ||
overdue = it.dueIncomeExpense, | ||
overdueTrns = it.dueTrns | ||
) | ||
} | ||
|
||
data class Input( | ||
val range: ClosedTimeRange, | ||
val baseCurrency: String | ||
) | ||
|
||
data class Output( | ||
val overdue: IncomeExpensePair, | ||
val overdueTrns: List<Transaction> | ||
) | ||
} |
37 changes: 37 additions & 0 deletions
37
app/src/main/java/com/ivy/wallet/domain/action/viewmodel/home/UpcomingAct.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,37 @@ | ||
package com.ivy.wallet.domain.action.viewmodel.home | ||
|
||
import com.ivy.fp.action.FPAction | ||
import com.ivy.fp.action.then | ||
import com.ivy.wallet.domain.data.core.Transaction | ||
import com.ivy.wallet.domain.pure.data.ClosedTimeRange | ||
import com.ivy.wallet.domain.pure.data.IncomeExpensePair | ||
import com.ivy.wallet.domain.pure.transaction.isUpcoming | ||
import javax.inject.Inject | ||
|
||
class UpcomingAct @Inject constructor( | ||
private val dueTrnsInfoAct: DueTrnsInfoAct | ||
) : FPAction<UpcomingAct.Input, UpcomingAct.Output>() { | ||
|
||
override suspend fun Input.compose(): suspend () -> Output = suspend { | ||
DueTrnsInfoAct.Input( | ||
range = range, | ||
baseCurrency = baseCurrency, | ||
dueFilter = ::isUpcoming | ||
) | ||
} then dueTrnsInfoAct then { | ||
Output( | ||
upcoming = it.dueIncomeExpense, | ||
upcomingTrns = it.dueTrns | ||
) | ||
} | ||
|
||
data class Input( | ||
val range: ClosedTimeRange, | ||
val baseCurrency: String | ||
) | ||
|
||
data class Output( | ||
val upcoming: IncomeExpensePair, | ||
val upcomingTrns: List<Transaction> | ||
) | ||
} |
29 changes: 0 additions & 29 deletions
29
app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcOverdueAct.kt
This file was deleted.
Oops, something went wrong.
29 changes: 0 additions & 29 deletions
29
app/src/main/java/com/ivy/wallet/domain/action/wallet/CalcUpcomingAct.kt
This file was deleted.
Oops, something went wrong.
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
2 changes: 1 addition & 1 deletion
2
...va/com/ivy/wallet/domain/pure/Exchange.kt → ...y/wallet/domain/pure/exchange/Exchange.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
Oops, something went wrong.