This commit is contained in:
xds
2025-04-07 18:26:23 +03:00
parent a38d5068e0
commit af7577c65b
13 changed files with 229 additions and 62 deletions

View File

@@ -47,7 +47,7 @@ class FinancialService(
private val categoryRepo: CategoryRepo,
val transactionsMapper: TransactionsMapper,
val budgetMapper: BudgetMapper,
private val subscriptionService: SubscriptionService
private val subscriptionService: SubscriptionService,
) {
private val logger = LoggerFactory.getLogger(FinancialService::class.java)
@@ -57,8 +57,14 @@ class FinancialService(
transaction.space!!.id!!, budgetId = null, transaction.date, transaction.date
)
if (transaction.category.type.code == "EXPENSE") {
val budgetCategory = budget.categories.firstOrNull { it.category.id == transaction.category.id }
?: throw NotFoundException("Budget category not found in the budget")
var budgetCategory = budget.categories.firstOrNull { it.category.id == transaction.category.id }
if (budgetCategory == null) {
budgetCategory = BudgetCategory(0.0, 0.0, 0.0, transaction.category)
budget.categories.add(budgetCategory)
budgetRepo.save(budget).awaitSingle()
}
if (transaction.category.type.code == "INCOME") {
budgetRepo.save(budget).awaitSingle()
}
@@ -845,6 +851,7 @@ class FinancialService(
}
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
suspend fun createTransaction(space: Space, transaction: Transaction, user: User? = null): Transaction {
@@ -930,12 +937,15 @@ class FinancialService(
"main" -> {
"Пользователь ${author.username} изменил $transactionType транзакцию:\n$sb"
}
"done_true" -> {
"Пользователь ${author.username} выполнил ${transaction.comment} с суммой ${transaction.amount.toInt()}"
}
"done_false" -> {
"Пользователь ${author.username} отменил выполнение ${transaction.comment} с суммой ${transaction.amount.toInt()}"
}
else -> "Изменения не обнаружены, но что то точно изменилось"
}