From ba4876bf8c6985e012017c30ad8da9d0f56980b1 Mon Sep 17 00:00:00 2001 From: filippo-ferrari Date: Sun, 22 Sep 2024 15:52:03 +0200 Subject: [PATCH] refactor: services and facades --- .../application/munera/facades/PersonFacade.java | 2 +- .../application/munera/services/ExpenseService.java | 13 +++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/application/munera/facades/PersonFacade.java b/src/main/java/com/application/munera/facades/PersonFacade.java index f7dd58d..3f3248c 100644 --- a/src/main/java/com/application/munera/facades/PersonFacade.java +++ b/src/main/java/com/application/munera/facades/PersonFacade.java @@ -134,7 +134,7 @@ public class PersonFacade { */ public void setCreditPaid(Person person, TreeGrid grid, Long userId) { try { - List expenses = expenseService.findExpensesWhereBeneficiary(person).stream().toList(); + List expenses = (List) expenseService.findExpensesWhereBeneficiary(person); for (Expense expense : expenses) { expense.setIsPaid(true); expenseService.update(expense, userId); diff --git a/src/main/java/com/application/munera/services/ExpenseService.java b/src/main/java/com/application/munera/services/ExpenseService.java index e98cf88..24a4503 100644 --- a/src/main/java/com/application/munera/services/ExpenseService.java +++ b/src/main/java/com/application/munera/services/ExpenseService.java @@ -216,15 +216,8 @@ public class ExpenseService { Person beneficiary = expense.getBeneficiary(); // Determine the expense type - if (payer.equals(loggedInPerson) && !beneficiary.equals(loggedInPerson)) { - // Logged-in user is the payer, and the beneficiary is someone else - expense.setExpenseType(ExpenseType.CREDIT); - } else if (!payer.equals(loggedInPerson) && beneficiary.equals(loggedInPerson)) { - // Logged-in user is the beneficiary, and the payer is someone else - expense.setExpenseType(ExpenseType.DEBIT); - } else if (payer.equals(loggedInPerson) && beneficiary.equals(loggedInPerson)) { - // Both payer and beneficiary are the logged-in user - expense.setExpenseType(ExpenseType.NONE); - } + if (payer.equals(loggedInPerson) && !beneficiary.equals(loggedInPerson)) expense.setExpenseType(ExpenseType.CREDIT); // Logged-in user is the payer, and the beneficiary is someone else + else if (!payer.equals(loggedInPerson) && beneficiary.equals(loggedInPerson)) expense.setExpenseType(ExpenseType.DEBIT); // Logged-in user is the beneficiary, and the payer is someone else + else if (payer.equals(loggedInPerson)) expense.setExpenseType(ExpenseType.NONE); // Both payer and beneficiary are the logged-in user } } \ No newline at end of file