docs: added javadocs
This commit is contained in:
parent
32c6c0de26
commit
cdf660e343
2 changed files with 58 additions and 2 deletions
|
@ -27,22 +27,47 @@ public class ExpenseService {
|
||||||
return repository.findById(id);
|
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<Expense> findDebtByUser(final Person person) {
|
public Collection<Expense> findDebtByUser(final Person person) {
|
||||||
return repository.findDebtorsExpensesByPersonId(person.getId());
|
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<Expense> findCreditByUser(final Person person) {
|
public Collection<Expense> findCreditByUser(final Person person) {
|
||||||
return repository.findCreditorsExpensesByPersonId(person.getId());
|
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<Expense> findUnpaidDebtByUser(final Person person) {
|
public Collection<Expense> findUnpaidDebtByUser(final Person person) {
|
||||||
return repository.findUnpaidDebtorsExpensesByPersonId(person.getId());
|
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<Expense> findUnpaidCreditByUser(final Person person) {
|
public Collection<Expense> findUnpaidCreditByUser(final Person person) {
|
||||||
return repository.findUnpaidCreditorsExpensesByPersonId(person.getId());
|
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<Expense> findExpenseByUser(final Person person) {
|
public List<Expense> findExpenseByUser(final Person person) {
|
||||||
final var credits = this.findCreditByUser(person);
|
final var credits = this.findCreditByUser(person);
|
||||||
final var debits = this.findDebtByUser(person);
|
final var debits = this.findDebtByUser(person);
|
||||||
|
@ -51,11 +76,19 @@ public class ExpenseService {
|
||||||
|
|
||||||
public List<Expense> findAll() {return repository.findAll();}
|
public List<Expense> findAll() {return repository.findAll();}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* updates an expense
|
||||||
|
* @param entity the expense to update
|
||||||
|
*/
|
||||||
public void update(Expense entity) {
|
public void update(Expense entity) {
|
||||||
if (Boolean.TRUE.equals(entity.getIsPaid())) entity.setPaymentDate(LocalDateTime.now());
|
if (Boolean.TRUE.equals(entity.getIsPaid())) entity.setPaymentDate(LocalDateTime.now());
|
||||||
repository.save(entity);
|
repository.save(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* deletes an expense given the ID
|
||||||
|
* @param id the id of the expense to delete
|
||||||
|
*/
|
||||||
public void delete(Long id) {
|
public void delete(Long id) {
|
||||||
repository.deleteById(id);
|
repository.deleteById(id);
|
||||||
}
|
}
|
||||||
|
@ -76,12 +109,20 @@ public class ExpenseService {
|
||||||
return this.repository.findAllByYear(year);
|
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());
|
return this.repository.existsByIdAndIsPaidTrue(expense.getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* fetches all expenses ordered by date descending
|
||||||
|
* @return the list of expenses found
|
||||||
|
*/
|
||||||
public List<Expense> findAllOrderByDateDescending() {
|
public List<Expense> findAllOrderByDateDescending() {
|
||||||
return this.repository.findAllByOrderByDateDesc();
|
return this.repository.findAllByOrderByDateDesc();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,14 +51,29 @@ public class PersonService {
|
||||||
return (int) this.personRepository.count();
|
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){
|
public BigDecimal calculateDebt(final Person person){
|
||||||
return this.expenseService.findDebtByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add);
|
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) {
|
public BigDecimal calculateCredit(final Person person) {
|
||||||
return this.expenseService.findCreditByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add);
|
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) {
|
public BigDecimal calculateNetBalance(final Person person) {
|
||||||
final var credit = this.expenseService.findUnpaidCreditByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add);
|
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);
|
final var debit = this.expenseService.findUnpaidDebtByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
|
Loading…
Reference in a new issue