docs: added javadocs and TODOs

This commit is contained in:
effe 2024-09-10 14:09:30 -04:00
parent 0377d15501
commit 7e15be27c1
3 changed files with 19 additions and 4 deletions

View file

@ -183,6 +183,12 @@ public class ExpenseService {
return (int) expenseRepository.count(); return (int) expenseRepository.count();
} }
/**
* Fetches the yearly net expenses of the user
* @param loggedInPerson the logged-in user
* @param year the year from which we want the expenses
* @return the list of expenses of that user in that year
*/
public List<Expense> fetchExpensesForDashboard(Person loggedInPerson, Year year) { public List<Expense> fetchExpensesForDashboard(Person loggedInPerson, Year year) {
List<Expense> totalExpenses = new ArrayList<>(); List<Expense> totalExpenses = new ArrayList<>();
final var yearValue = year.getValue(); final var yearValue = year.getValue();
@ -218,7 +224,6 @@ public class ExpenseService {
if (userDetails == null) { if (userDetails == null) {
throw new IllegalStateException("No logged-in user found"); throw new IllegalStateException("No logged-in user found");
} }
// Fetch the logged-in user // Fetch the logged-in user
final var loggedInUserId = userRepository.findByUsername(userDetails.getUsername()).getId(); final var loggedInUserId = userRepository.findByUsername(userDetails.getUsername()).getId();
Person loggedInPerson = this.personRepository.findByUserId(loggedInUserId).orElse(null); Person loggedInPerson = this.personRepository.findByUserId(loggedInUserId).orElse(null);

View file

@ -37,6 +37,10 @@ public class UserService {
return null; return null;
} }
/**
* Updates the user's data and its connected person entity
* @param user the user of which we update the data
*/
public void updateUser(User user) { public void updateUser(User user) {
userRepository.save(user); userRepository.save(user);
final var person = personRepository.findByUserId(user.getId()) final var person = personRepository.findByUserId(user.getId())
@ -46,7 +50,13 @@ public class UserService {
personRepository.save(person); personRepository.save(person);
} }
/**
* Saves a user and connected person entity
* @param user the user of which we update the data
*/
public void saveUserAndConnectedPerson(User user) { public void saveUserAndConnectedPerson(User user) {
//TODO: look if this method can substitute the one above: updateUser, they seem to do similar things
// Check if the user already exists in the database // Check if the user already exists in the database
final var existingUserOptional = userRepository.findOptionalByUsername(user.getUsername()); final var existingUserOptional = userRepository.findOptionalByUsername(user.getUsername());

View file

@ -38,9 +38,9 @@ class PersonServiceTest {
person2.setLastName("second"); person2.setLastName("second");
person2.setFirstName("person"); person2.setFirstName("person");
Person person3 = new Person(); // Person person3 = new Person();
person3.setLastName("third"); // person3.setLastName("third");
person3.setFirstName("person"); // person3.setFirstName("person");
Expense expense1 = mock(Expense.class); Expense expense1 = mock(Expense.class);
when(expense1.getPayer()).thenReturn(person); when(expense1.getPayer()).thenReturn(person);