From cdf660e343bc7672231d3f04977b4e14ab54ea63 Mon Sep 17 00:00:00 2001 From: Filippo Ferrari Date: Mon, 5 Aug 2024 22:15:19 +0200 Subject: [PATCH] docs: added javadocs --- .../munera/services/ExpenseService.java | 45 ++++++++++++++++++- .../munera/services/PersonService.java | 15 +++++++ 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/application/munera/services/ExpenseService.java b/src/main/java/com/application/munera/services/ExpenseService.java index c57b43f..991ecd0 100644 --- a/src/main/java/com/application/munera/services/ExpenseService.java +++ b/src/main/java/com/application/munera/services/ExpenseService.java @@ -27,22 +27,47 @@ public class ExpenseService { return repository.findById(id); } + /** + * finds all expenses tagged as debit given a user + * @param person the user of the expenses + * @return the collections of expenses found + */ public Collection findDebtByUser(final Person person) { return repository.findDebtorsExpensesByPersonId(person.getId()); } + /** + * finds all expenses tagged as credit given a user + * @param person the user of the expenses + * @return the collections of expenses found + */ public Collection findCreditByUser(final Person person) { return repository.findCreditorsExpensesByPersonId(person.getId()); } + /** + * finds all expenses tagged as debit and unpaid given a user + * @param person the user of the expenses + * @return the collections of expenses found + */ public Collection findUnpaidDebtByUser(final Person person) { return repository.findUnpaidDebtorsExpensesByPersonId(person.getId()); } + /** + * finds all expenses tagged as credit and unpaid given a user + * @param person the user of the expenses + * @return the collections of expenses found + */ public Collection findUnpaidCreditByUser(final Person person) { return repository.findUnpaidCreditorsExpensesByPersonId(person.getId()); } + /** + * finds all expenses related to a user + * @param person the user of the expenses + * @return the collections of expenses found + */ public List findExpenseByUser(final Person person) { final var credits = this.findCreditByUser(person); final var debits = this.findDebtByUser(person); @@ -51,11 +76,19 @@ public class ExpenseService { public List findAll() {return repository.findAll();} + /** + * updates an expense + * @param entity the expense to update + */ public void update(Expense entity) { if (Boolean.TRUE.equals(entity.getIsPaid())) entity.setPaymentDate(LocalDateTime.now()); repository.save(entity); } + /** + * deletes an expense given the ID + * @param id the id of the expense to delete + */ public void delete(Long id) { repository.deleteById(id); } @@ -76,12 +109,20 @@ public class ExpenseService { return this.repository.findAllByYear(year); } - public boolean isExpenseResolved(final Expense expense) { + /** + * checks if an expense has been paid + * @param expense the expense to check + * @return true if the expense has been paid, false otherwise + */ + public boolean isExpensePaid(final Expense expense) { return this.repository.existsByIdAndIsPaidTrue(expense.getId()); } + /** + * fetches all expenses ordered by date descending + * @return the list of expenses found + */ public List findAllOrderByDateDescending() { return this.repository.findAllByOrderByDateDesc(); } - } diff --git a/src/main/java/com/application/munera/services/PersonService.java b/src/main/java/com/application/munera/services/PersonService.java index 3de2629..3538724 100644 --- a/src/main/java/com/application/munera/services/PersonService.java +++ b/src/main/java/com/application/munera/services/PersonService.java @@ -51,14 +51,29 @@ public class PersonService { return (int) this.personRepository.count(); } + /** + * calculates the debt a certain person has + * @param person the person of which you want to know the debt + * @return the debt that a certain person has + */ public BigDecimal calculateDebt(final Person person){ return this.expenseService.findDebtByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add); } + /** + * calculates the credit a certain person has + * @param person the person of which you want to know the credit + * @return the credit that a certain person has + */ public BigDecimal calculateCredit(final Person person) { return this.expenseService.findCreditByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add); } + /** + * calculates the balance of a person using the money owed or paid off to that person + * @param person the person of which you want to know the balance + * @return the amount of money owed or paid off to a certain person + */ public BigDecimal calculateNetBalance(final Person person) { final var credit = this.expenseService.findUnpaidCreditByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add); final var debit = this.expenseService.findUnpaidDebtByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add);