diff --git a/server/src/main/java/io/myfinbox/account/application/CreateAccountService.java b/server/src/main/java/io/myfinbox/account/application/CreateAccountService.java index 8fb1bed..0f7628c 100644 --- a/server/src/main/java/io/myfinbox/account/application/CreateAccountService.java +++ b/server/src/main/java/io/myfinbox/account/application/CreateAccountService.java @@ -8,6 +8,7 @@ import io.vavr.control.Either; import io.vavr.control.Validation; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -18,6 +19,7 @@ import static io.vavr.API.Invalid; import static io.vavr.API.Valid; +@Slf4j @Service @Transactional @RequiredArgsConstructor @@ -46,6 +48,7 @@ public Either create(CreateAccountCommand cmd) { .build(); accounts.save(account); + log.debug("Account {} was created", account.getId()); return Either.right(account); } diff --git a/server/src/main/java/io/myfinbox/expense/adapter/messaging/AccountEventsListener.java b/server/src/main/java/io/myfinbox/expense/adapter/messaging/AccountEventsListener.java index e35d18c..8c4de79 100644 --- a/server/src/main/java/io/myfinbox/expense/adapter/messaging/AccountEventsListener.java +++ b/server/src/main/java/io/myfinbox/expense/adapter/messaging/AccountEventsListener.java @@ -25,11 +25,11 @@ class AccountEventsListener { */ @ApplicationModuleListener public void on(AccountCreated event) { - log.debug("Handle account create event {}", event); + log.debug("[Expense] Handle account create event {}", event); var either = categoryService.createDefault(new AccountIdentifier(event.accountId())); if (either.isLeft()) { - log.error("Failed to create default categories for account: {}, failure: {}", event, either.getLeft()); + log.error("[Expense] Failed to create default categories for account: {}, failure: {}", event, either.getLeft()); } } } diff --git a/server/src/main/java/io/myfinbox/expense/application/CreateExpenseService.java b/server/src/main/java/io/myfinbox/expense/application/CreateExpenseService.java index 4b1f8fd..4cd6380 100644 --- a/server/src/main/java/io/myfinbox/expense/application/CreateExpenseService.java +++ b/server/src/main/java/io/myfinbox/expense/application/CreateExpenseService.java @@ -9,10 +9,12 @@ import io.myfinbox.shared.PaymentType; import io.vavr.control.Either; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.javamoney.moneta.Money; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +@Slf4j @Service @RequiredArgsConstructor @Transactional @@ -33,8 +35,8 @@ public Either create(ExpenseCommand command) { return Either.left(Failure.ofValidation(VALIDATION_FAILURE_MESSAGE, validation.getError().toJavaList())); } - var category = categories.findByIdAndAccount(new CategoryIdentifier(command.categoryId()), new AccountIdentifier(command.accountId())); - if (category.isEmpty()) { + var possibleCategory = categories.findByIdAndAccount(new CategoryIdentifier(command.categoryId()), new AccountIdentifier(command.accountId())); + if (possibleCategory.isEmpty()) { return Either.left(Failure.ofNotFound(CATEGORY_NOT_FOUND_MESSAGE)); } @@ -44,11 +46,13 @@ public Either create(ExpenseCommand command) { .expenseDate(command.expenseDate()) .paymentType(PaymentType.fromValue(command.paymentType())) .description(command.description()) - .category(category.get()) + .category(possibleCategory.get()) .build(); expenses.save(expense); + log.debug("Expense {} was created", expense.getId()); + return Either.right(expense); } } diff --git a/server/src/main/java/io/myfinbox/expense/application/DefaultCategoryService.java b/server/src/main/java/io/myfinbox/expense/application/DefaultCategoryService.java index ac729e8..40b08a1 100644 --- a/server/src/main/java/io/myfinbox/expense/application/DefaultCategoryService.java +++ b/server/src/main/java/io/myfinbox/expense/application/DefaultCategoryService.java @@ -8,6 +8,7 @@ import io.vavr.control.Either; import io.vavr.control.Validation; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -23,6 +24,7 @@ import static java.util.Objects.nonNull; import static org.apache.commons.lang3.StringUtils.isBlank; +@Slf4j @Service @RequiredArgsConstructor class DefaultCategoryService implements CategoryService { @@ -51,6 +53,8 @@ public Either> createDefault(AccountIdentifier account) categories.saveAll(values); + log.debug("Default expense categories {} were created", values); + return Either.right(values); } @@ -69,6 +73,8 @@ public Either create(CategoryCommand command) { var category = new Category(command.name(), new AccountIdentifier(command.accountId())); categories.save(category); + log.debug("Expense category {} was created", category.getId()); + return Either.right(category); } @@ -84,23 +90,25 @@ public Either update(UUID categoryId, CategoryCommand command return Either.left(Failure.ofNotFound(CATEGORY_NOT_FOUND_MESSAGE)); } - var category = categories.findByIdAndAccount(new CategoryIdentifier(categoryId), new AccountIdentifier(command.accountId())); - if (category.isEmpty()) { + var possibleCategory = categories.findByIdAndAccount(new CategoryIdentifier(categoryId), new AccountIdentifier(command.accountId())); + if (possibleCategory.isEmpty()) { return Either.left(Failure.ofNotFound(CATEGORY_NOT_FOUND_MESSAGE)); } - if (category.get().sameName(command.name())) { - return Either.right(category.get()); + if (possibleCategory.get().sameName(command.name())) { + return Either.right(possibleCategory.get()); } if (categories.existsByNameAndAccount(command.name(), new AccountIdentifier(command.accountId()))) { return Either.left(Failure.ofConflict(CATEGORY_NAME_DUPLICATE_MESSAGE)); } - category.get().setName(command.name()); - categories.save(category.get()); // FIXME: fix the save anti-pattern + possibleCategory.get().setName(command.name()); + categories.save(possibleCategory.get()); // FIXME: fix the save anti-pattern - return Either.right(category.get()); + log.debug("Expense category {} wes updated", possibleCategory.get().getId()); + + return Either.right(possibleCategory.get()); } @Override @@ -110,16 +118,18 @@ public Either delete(UUID categoryId) { return Either.left(Failure.ofNotFound(CATEGORY_NOT_FOUND_MESSAGE)); } - var category = categories.findById(new CategoryIdentifier(categoryId)); - if (category.isEmpty()) { + var possibleCategory = categories.findById(new CategoryIdentifier(categoryId)); + if (possibleCategory.isEmpty()) { return Either.left(Failure.ofNotFound(CATEGORY_NOT_FOUND_MESSAGE)); } - if (expenses.existsByCategory(category.get())) { + if (expenses.existsByCategory(possibleCategory.get())) { return Either.left(Failure.ofConflict(CATEGORY_IN_USE_FAILURE_MESSAGE)); } - categories.delete(category.get()); + categories.delete(possibleCategory.get()); + + log.debug("Expense category {} wes deleted", possibleCategory.get().getId()); return Either.right(null); } diff --git a/server/src/main/java/io/myfinbox/expense/application/DeleteExpenseService.java b/server/src/main/java/io/myfinbox/expense/application/DeleteExpenseService.java index 9d146ac..3a9018f 100644 --- a/server/src/main/java/io/myfinbox/expense/application/DeleteExpenseService.java +++ b/server/src/main/java/io/myfinbox/expense/application/DeleteExpenseService.java @@ -4,6 +4,7 @@ import io.myfinbox.shared.Failure; import io.vavr.control.Either; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -12,6 +13,7 @@ import static io.myfinbox.expense.domain.Expense.ExpenseIdentifier; import static java.util.Objects.isNull; +@Slf4j @Service @Transactional @RequiredArgsConstructor @@ -27,14 +29,16 @@ public Either delete(UUID expenseId) { return Either.left(Failure.ofNotFound(EXPENSE_NOT_FOUND_MESSAGE)); } - var expense = expenses.findById(new ExpenseIdentifier(expenseId)); - if (expense.isEmpty()) { + var possibleExpense = expenses.findById(new ExpenseIdentifier(expenseId)); + if (possibleExpense.isEmpty()) { return Either.left(Failure.ofNotFound(EXPENSE_NOT_FOUND_MESSAGE)); } - expense.get().delete(); + possibleExpense.get().delete(); - expenses.delete(expense.get()); + expenses.delete(possibleExpense.get()); + + log.debug("Expense {} was deleted", possibleExpense.get().getId()); return Either.right(null); } diff --git a/server/src/main/java/io/myfinbox/expense/application/UpdateExpenseService.java b/server/src/main/java/io/myfinbox/expense/application/UpdateExpenseService.java index 6915ea0..72e8cf4 100644 --- a/server/src/main/java/io/myfinbox/expense/application/UpdateExpenseService.java +++ b/server/src/main/java/io/myfinbox/expense/application/UpdateExpenseService.java @@ -7,6 +7,7 @@ import io.myfinbox.shared.PaymentType; import io.vavr.control.Either; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.javamoney.moneta.Money; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -15,6 +16,7 @@ import static java.util.Objects.isNull; +@Slf4j @Service @RequiredArgsConstructor @Transactional @@ -40,17 +42,17 @@ public Either update(UUID expenseId, ExpenseCommand command) { return Either.left(Failure.ofNotFound(EXPENSE_NOT_FOUND_MESSAGE)); } - var expense = expenses.findByIdAndAccount(new ExpenseIdentifier(expenseId), new AccountIdentifier(command.accountId())); - if (expense.isEmpty()) { + var possibleExpense = expenses.findByIdAndAccount(new ExpenseIdentifier(expenseId), new AccountIdentifier(command.accountId())); + if (possibleExpense.isEmpty()) { return Either.left(Failure.ofNotFound(EXPENSE_NOT_FOUND_MESSAGE)); } - var possibleCategory = fetchCategoryOrFailure(expense.get().getCategory(), command.categoryId(), command.accountId()); + var possibleCategory = fetchCategoryOrFailure(possibleExpense.get().getCategory(), command.categoryId(), command.accountId()); if (possibleCategory.isLeft()) { return Either.left(possibleCategory.getLeft()); } - expense.get().update( + possibleExpense.get().update( Expense.builder() .account(new AccountIdentifier(command.accountId())) .amount(Money.of(command.amount(), command.currencyCode())) @@ -60,9 +62,11 @@ public Either update(UUID expenseId, ExpenseCommand command) { .category(possibleCategory.get()) ); - expenses.save(expense.get()); + expenses.save(possibleExpense.get()); //FIXME: fix save anti-pattern - return Either.right(expense.get()); + log.debug("Expense {} was updated", possibleExpense.get().getId()); + + return Either.right(possibleExpense.get()); } private Either fetchCategoryOrFailure(Category category, UUID categoryId, UUID accountId) { diff --git a/server/src/main/java/io/myfinbox/income/adapter/messaging/AccountEventsListener.java b/server/src/main/java/io/myfinbox/income/adapter/messaging/AccountEventsListener.java index 18e3e5d..7b7bd4a 100644 --- a/server/src/main/java/io/myfinbox/income/adapter/messaging/AccountEventsListener.java +++ b/server/src/main/java/io/myfinbox/income/adapter/messaging/AccountEventsListener.java @@ -29,11 +29,11 @@ class AccountEventsListener { @ApplicationModuleListener @Transactional(propagation = REQUIRES_NEW) public void on(AccountCreated event) { - log.debug("Handle account create event {}", event); + log.debug("[Income] Handle account create event {}", event); var either = incomeSourceService.createDefault(new AccountIdentifier(event.accountId())); if (either.isLeft()) { - log.error("Failed to create default income sources for account: {}, failure: {}", event, either.getLeft()); + log.error("[Income] Failed to create default income sources for account: {}, failure: {}", event, either.getLeft()); } } } diff --git a/server/src/main/java/io/myfinbox/income/application/CreateIncomeService.java b/server/src/main/java/io/myfinbox/income/application/CreateIncomeService.java index 453cbc0..8105809 100644 --- a/server/src/main/java/io/myfinbox/income/application/CreateIncomeService.java +++ b/server/src/main/java/io/myfinbox/income/application/CreateIncomeService.java @@ -1,5 +1,6 @@ package io.myfinbox.income.application; +import io.myfinbox.expense.domain.Expense; import io.myfinbox.income.domain.AccountIdentifier; import io.myfinbox.income.domain.Income; import io.myfinbox.income.domain.IncomeSource.IncomeSourceIdentifier; @@ -9,10 +10,12 @@ import io.myfinbox.shared.PaymentType; import io.vavr.control.Either; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.javamoney.moneta.Money; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +@Slf4j @Service @Transactional @RequiredArgsConstructor @@ -34,9 +37,8 @@ public Either create(IncomeCommand command) { return Either.left(Failure.ofValidation(VALIDATION_FAILURE_MESSAGE, validation.getError().toJavaList())); } - var incomeSource = incomeSources.findByIdAndAccount(new IncomeSourceIdentifier(command.incomeSourceId()), new AccountIdentifier(command.accountId())); - - if (incomeSource.isEmpty()) { + var possibleIncomeSource = incomeSources.findByIdAndAccount(new IncomeSourceIdentifier(command.incomeSourceId()), new AccountIdentifier(command.accountId())); + if (possibleIncomeSource.isEmpty()) { return Either.left(Failure.ofNotFound(INCOME_SOURCE_NOT_FOUND_MESSAGE)); } @@ -46,11 +48,13 @@ public Either create(IncomeCommand command) { .paymentType(PaymentType.fromValue(command.paymentType())) .incomeDate(command.incomeDate()) .description(command.description()) - .incomeSource(incomeSource.get()) + .incomeSource(possibleIncomeSource.get()) .build(); incomes.save(income); + log.debug("Income {} was created", income.getId()); + return Either.right(income); } } diff --git a/server/src/main/java/io/myfinbox/income/application/DefaultIncomeSourceService.java b/server/src/main/java/io/myfinbox/income/application/DefaultIncomeSourceService.java index 15dc1e5..470019f 100644 --- a/server/src/main/java/io/myfinbox/income/application/DefaultIncomeSourceService.java +++ b/server/src/main/java/io/myfinbox/income/application/DefaultIncomeSourceService.java @@ -8,6 +8,7 @@ import io.vavr.control.Either; import io.vavr.control.Validation; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -23,6 +24,7 @@ import static java.util.Objects.nonNull; import static org.apache.commons.lang3.StringUtils.isBlank; +@Slf4j @Service @RequiredArgsConstructor class DefaultIncomeSourceService implements IncomeSourceService { @@ -50,6 +52,7 @@ public Either> createDefault(AccountIdentifier accou .toList(); incomeSources.saveAll(values); + log.debug("Default Income Sources {} were created", values); return Either.right(values); } @@ -69,6 +72,8 @@ public Either create(IncomeSourceCommand command) { var incomeSource = new IncomeSource(command.name(), new AccountIdentifier(command.accountId())); incomeSources.save(incomeSource); + log.debug("Income Source {} was created", incomeSource.getId()); + return Either.right(incomeSource); } @@ -84,23 +89,24 @@ public Either update(UUID incomeSourceId, IncomeSourceCom return Either.left(Failure.ofNotFound(SOURCE_NOT_FOUND_MESSAGE)); } - var incomeSource = incomeSources.findByIdAndAccount(new IncomeSourceIdentifier(incomeSourceId), new AccountIdentifier(command.accountId())); - if (incomeSource.isEmpty()) { + var possibleIncomeSource = incomeSources.findByIdAndAccount(new IncomeSourceIdentifier(incomeSourceId), new AccountIdentifier(command.accountId())); + if (possibleIncomeSource.isEmpty()) { return Either.left(Failure.ofNotFound(SOURCE_NOT_FOUND_MESSAGE)); } - if (incomeSource.get().sameName(command.name())) { - return Either.right(incomeSource.get()); + if (possibleIncomeSource.get().sameName(command.name())) { + return Either.right(possibleIncomeSource.get()); } if (incomeSources.existsByNameAndAccount(command.name(), new AccountIdentifier(command.accountId()))) { return Either.left(Failure.ofConflict(SOURCE_NAME_DUPLICATE_MESSAGE)); } - incomeSource.get().setName(command.name()); - incomeSources.save(incomeSource.get()); // FIXME: fix the save anti-pattern + possibleIncomeSource.get().setName(command.name()); + incomeSources.save(possibleIncomeSource.get()); // FIXME: fix the save anti-pattern + log.debug("Income Source {} was updated", possibleIncomeSource.get().getId()); - return Either.right(incomeSource.get()); + return Either.right(possibleIncomeSource.get()); } @Override @@ -110,16 +116,17 @@ public Either delete(UUID incomeSourceId) { return Either.left(Failure.ofNotFound(SOURCE_NOT_FOUND_MESSAGE)); } - var incomeSource = incomeSources.findById(new IncomeSourceIdentifier(incomeSourceId)); - if (incomeSource.isEmpty()) { + var possibleIncomeSource = incomeSources.findById(new IncomeSourceIdentifier(incomeSourceId)); + if (possibleIncomeSource.isEmpty()) { return Either.left(Failure.ofNotFound(SOURCE_NOT_FOUND_MESSAGE)); } - if (incomes.existsByIncomeSource(incomeSource.get())) { + if (incomes.existsByIncomeSource(possibleIncomeSource.get())) { return Either.left(Failure.ofConflict(SOURCE_IN_USE_FAILURE_MESSAGE)); } - incomeSources.delete(incomeSource.get()); + incomeSources.delete(possibleIncomeSource.get()); + log.debug("Income Source {} was deleted", possibleIncomeSource.get().getId()); return Either.right(null); } diff --git a/server/src/main/java/io/myfinbox/income/application/DeleteIncomeService.java b/server/src/main/java/io/myfinbox/income/application/DeleteIncomeService.java index e9ff0c9..3d25903 100644 --- a/server/src/main/java/io/myfinbox/income/application/DeleteIncomeService.java +++ b/server/src/main/java/io/myfinbox/income/application/DeleteIncomeService.java @@ -5,6 +5,7 @@ import io.myfinbox.shared.Failure; import io.vavr.control.Either; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -12,6 +13,7 @@ import static java.util.Objects.isNull; +@Slf4j @Service @Transactional @RequiredArgsConstructor @@ -27,14 +29,15 @@ public Either delete(UUID incomeId) { return Either.left(Failure.ofNotFound(INCOME_NOT_FOUND_MESSAGE)); } - var income = incomes.findById(new IncomeIdentifier(incomeId)); - if (income.isEmpty()) { + var possibleIncome = incomes.findById(new IncomeIdentifier(incomeId)); + if (possibleIncome.isEmpty()) { return Either.left(Failure.ofNotFound(INCOME_NOT_FOUND_MESSAGE)); } - income.get().delete(); + possibleIncome.get().delete(); - incomes.delete(income.get()); + incomes.delete(possibleIncome.get()); + log.debug("Income {} was deleted", possibleIncome.get().getId()); return Either.right(null); } diff --git a/server/src/main/java/io/myfinbox/income/application/UpdateIncomeService.java b/server/src/main/java/io/myfinbox/income/application/UpdateIncomeService.java index bf0a786..dd56c02 100644 --- a/server/src/main/java/io/myfinbox/income/application/UpdateIncomeService.java +++ b/server/src/main/java/io/myfinbox/income/application/UpdateIncomeService.java @@ -6,6 +6,7 @@ import io.myfinbox.shared.PaymentType; import io.vavr.control.Either; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.javamoney.moneta.Money; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -15,6 +16,7 @@ import static io.myfinbox.income.domain.IncomeSource.IncomeSourceIdentifier; import static java.util.Objects.isNull; +@Slf4j @Service @RequiredArgsConstructor @Transactional @@ -40,17 +42,17 @@ public Either update(UUID incomeId, IncomeCommand command) { return Either.left(Failure.ofNotFound(INCOME_NOT_FOUND_MESSAGE)); } - var income = incomes.findByIdAndAccount(new IncomeIdentifier(incomeId), new AccountIdentifier(command.accountId())); - if (income.isEmpty()) { + var possibleIncome = incomes.findByIdAndAccount(new IncomeIdentifier(incomeId), new AccountIdentifier(command.accountId())); + if (possibleIncome.isEmpty()) { return Either.left(Failure.ofNotFound(INCOME_NOT_FOUND_MESSAGE)); } - var possibleIncomeSource = fetchIncomeSourceOrFailure(income.get().getIncomeSource(), command.incomeSourceId(), command.accountId()); + var possibleIncomeSource = fetchIncomeSourceOrFailure(possibleIncome.get().getIncomeSource(), command.incomeSourceId(), command.accountId()); if (possibleIncomeSource.isLeft()) { return Either.left(possibleIncomeSource.getLeft()); } - income.get().update( + possibleIncome.get().update( Income.builder() .account(new AccountIdentifier(command.accountId())) .amount(Money.of(command.amount(), command.currencyCode())) @@ -60,9 +62,10 @@ public Either update(UUID incomeId, IncomeCommand command) { .incomeSource(possibleIncomeSource.get()) ); - incomes.save(income.get()); + incomes.save(possibleIncome.get()); + log.debug("Income {} was updated", possibleIncome.get().getId()); - return Either.right(income.get()); + return Either.right(possibleIncome.get()); } private Either fetchIncomeSourceOrFailure(IncomeSource incomeSource, UUID incomeSourceId, UUID accountId) { diff --git a/server/src/main/java/io/myfinbox/spendingplan/adapter/messaging/ExpenseEventsListener.java b/server/src/main/java/io/myfinbox/spendingplan/adapter/messaging/ExpenseEventsListener.java index 23ad1be..e639f32 100644 --- a/server/src/main/java/io/myfinbox/spendingplan/adapter/messaging/ExpenseEventsListener.java +++ b/server/src/main/java/io/myfinbox/spendingplan/adapter/messaging/ExpenseEventsListener.java @@ -25,7 +25,7 @@ class ExpenseEventsListener { */ @ApplicationModuleListener public void on(ExpenseCreated event) { - log.debug("Received ExpenseCreated event: {}", event); + log.debug("[Plan] Received ExpenseCreated event: {}", event); // Record the created expense var expenseRecord = expenseRecordTrackerUseCase.recordCreated(ExpenseCreatedRecord.builder() @@ -38,7 +38,7 @@ public void on(ExpenseCreated event) { .build()); if (expenseRecord.isEmpty()) { - log.debug("ExpenseCreated event: {} skipped", event); + log.debug("[Plan] ExpenseCreated event: {} skipped", event); } } } diff --git a/server/src/main/java/io/myfinbox/spendingplan/application/AddOrRemoveJarCategoryService.java b/server/src/main/java/io/myfinbox/spendingplan/application/AddOrRemoveJarCategoryService.java index 35e4691..cf96856 100644 --- a/server/src/main/java/io/myfinbox/spendingplan/application/AddOrRemoveJarCategoryService.java +++ b/server/src/main/java/io/myfinbox/spendingplan/application/AddOrRemoveJarCategoryService.java @@ -4,6 +4,7 @@ import io.myfinbox.spendingplan.domain.*; import io.vavr.control.Either; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -13,6 +14,7 @@ import static io.myfinbox.spendingplan.domain.Plan.PlanIdentifier; import static java.util.Objects.isNull; +@Slf4j @Service @Transactional @RequiredArgsConstructor @@ -36,23 +38,28 @@ public Either> addOrRemove(UUID planId, UUID j } // require plan jar to exist - var jar = jars.findByIdAndPlanId(new JarIdentifier(jarId), new PlanIdentifier(planId)); - if (jar.isEmpty()) { + var possibleJar = jars.findByIdAndPlanId(new JarIdentifier(jarId), new PlanIdentifier(planId)); + if (possibleJar.isEmpty()) { return Either.left(Failure.ofNotFound(PLAN_JAR_NOT_FOUND_MESSAGE)); } // select unchecked and delete - command.categories().stream() + var toDeleteCategories = command.categories().stream() .filter(jarCategoryToAddOrRemove -> !jarCategoryToAddOrRemove.toAdd()) .map(JarCategoryToAddOrRemove::categoryId) - .forEach(category -> - jarExpenseCategories.deleteByJarIdAndCategoryId(new JarIdentifier(jarId), new CategoryIdentifier(category))); + .toList(); + + toDeleteCategories.forEach(category -> + jarExpenseCategories.deleteByJarIdAndCategoryId(new JarIdentifier(jarId), new CategoryIdentifier(category))); // select checked and create if not exists - var toCreateCategories = filterToCreate(jar.get(), command); + var toCreateCategories = filterToCreate(possibleJar.get(), command); jarExpenseCategories.saveAll(toCreateCategories); + log.debug("Jar expense category {} were created", toCreateCategories); + log.debug("Jar expense category {} were deleted", toDeleteCategories); + return Either.right(toCreateCategories); } diff --git a/server/src/main/java/io/myfinbox/spendingplan/application/CreateJarService.java b/server/src/main/java/io/myfinbox/spendingplan/application/CreateJarService.java index f95a08d..a806113 100644 --- a/server/src/main/java/io/myfinbox/spendingplan/application/CreateJarService.java +++ b/server/src/main/java/io/myfinbox/spendingplan/application/CreateJarService.java @@ -8,6 +8,7 @@ import io.myfinbox.spendingplan.domain.Plans; import io.vavr.control.Either; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.javamoney.moneta.Money; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -22,6 +23,7 @@ import static java.math.RoundingMode.HALF_UP; import static java.util.Objects.isNull; +@Slf4j @Service @Transactional @RequiredArgsConstructor @@ -48,18 +50,18 @@ public Either create(UUID planId, JarCommand command) { } // find the plan - var plan = plans.findByIdEagerJars(new PlanIdentifier(planId)); - if (plan.isEmpty()) { + var possiblePlan = plans.findByIdEagerJars(new PlanIdentifier(planId)); + if (possiblePlan.isEmpty()) { return Either.left(Failure.ofNotFound(PLAN_NOT_FOUND_MESSAGE)); } // check if jar name exists as jar to provided plan - if (jars.existsByNameAndPlan(command.name(), plan.get())) { + if (jars.existsByNameAndPlan(command.name(), possiblePlan.get())) { return Either.left(Failure.ofConflict(JAR_NAME_DUPLICATE_MESSAGE.formatted(command.name()))); } // validate percentage total, must be up 100% - var existingTotalPercentage = plan.get().totalJarPercentage(); + var existingTotalPercentage = possiblePlan.get().totalJarPercentage(); if (isInvalidTotalPercentage(existingTotalPercentage, command.percentage())) { return Either.left(maxAllowedPercentageViolation(command.percentage(), 100 - existingTotalPercentage)); } @@ -67,13 +69,15 @@ public Either create(UUID planId, JarCommand command) { var jar = Jar.builder() .name(command.name()) .percentage(new Jar.Percentage(command.percentage())) - .amountToReach(amountToReach(command.percentage(), plan.get())) + .amountToReach(amountToReach(command.percentage(), possiblePlan.get())) .description(command.description()) - .plan(plan.get()) + .plan(possiblePlan.get()) .build(); jars.save(jar); + log.debug("Expense jar {} was created", jar.getId()); + return Either.right(jar); } diff --git a/server/src/main/java/io/myfinbox/spendingplan/application/CreatePlanService.java b/server/src/main/java/io/myfinbox/spendingplan/application/CreatePlanService.java index bead90e..4f4884d 100644 --- a/server/src/main/java/io/myfinbox/spendingplan/application/CreatePlanService.java +++ b/server/src/main/java/io/myfinbox/spendingplan/application/CreatePlanService.java @@ -6,10 +6,12 @@ import io.myfinbox.spendingplan.domain.Plans; import io.vavr.control.Either; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.javamoney.moneta.Money; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +@Slf4j @Service @Transactional @RequiredArgsConstructor @@ -41,6 +43,7 @@ public Either create(PlanCommand command) { .build(); plans.save(plan); + log.debug("Spending plan {} was created", plan.getId()); return Either.right(plan); } diff --git a/server/src/main/java/io/myfinbox/spendingplan/application/ExpenseRecordTrackerService.java b/server/src/main/java/io/myfinbox/spendingplan/application/ExpenseRecordTrackerService.java index 08f972e..cc481b7 100644 --- a/server/src/main/java/io/myfinbox/spendingplan/application/ExpenseRecordTrackerService.java +++ b/server/src/main/java/io/myfinbox/spendingplan/application/ExpenseRecordTrackerService.java @@ -5,6 +5,7 @@ import io.myfinbox.spendingplan.domain.ExpenseRecords; import io.myfinbox.spendingplan.domain.JarExpenseCategories; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -12,6 +13,7 @@ import static io.myfinbox.spendingplan.domain.ExpenseRecord.ExpenseIdentifier; +@Slf4j @Service @Transactional @RequiredArgsConstructor @@ -40,6 +42,7 @@ public List recordCreated(ExpenseCreatedRecord createdRecord) { .toList(); expenseRecords.saveAll(records); + log.debug("Expense records {} were created", records); return records; } diff --git a/server/src/main/java/io/myfinbox/spendingplan/domain/ExpenseRecord.java b/server/src/main/java/io/myfinbox/spendingplan/domain/ExpenseRecord.java index ce1e9fc..eb0bd44 100644 --- a/server/src/main/java/io/myfinbox/spendingplan/domain/ExpenseRecord.java +++ b/server/src/main/java/io/myfinbox/spendingplan/domain/ExpenseRecord.java @@ -18,7 +18,7 @@ @Entity @Getter -@ToString +@ToString(exclude = {"jarExpenseCategory"}) @Table(name = "jar_expense_record") @EqualsAndHashCode(of = {"expenseId", "jarExpenseCategory"}) @NoArgsConstructor(access = PACKAGE, force = true) diff --git a/server/src/main/java/io/myfinbox/spendingplan/domain/JarExpenseCategory.java b/server/src/main/java/io/myfinbox/spendingplan/domain/JarExpenseCategory.java index bab5da8..ee7486d 100644 --- a/server/src/main/java/io/myfinbox/spendingplan/domain/JarExpenseCategory.java +++ b/server/src/main/java/io/myfinbox/spendingplan/domain/JarExpenseCategory.java @@ -14,7 +14,7 @@ @Entity @Getter -@ToString +@ToString(exclude = {"jar", "expenseRecords"}) @Table(name = "spending_jar_expense_category") @EqualsAndHashCode(of = {"jar", "categoryId"}) @NoArgsConstructor(access = PACKAGE, force = true)