From 7e15be27c1c563eb362eab767fe4c1011270ce0d Mon Sep 17 00:00:00 2001 From: effe Date: Tue, 10 Sep 2024 14:09:30 -0400 Subject: [PATCH] docs: added javadocs and TODOs --- .../application/munera/services/ExpenseService.java | 7 ++++++- .../com/application/munera/services/UserService.java | 10 ++++++++++ .../application/munera/services/PersonServiceTest.java | 6 +++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/application/munera/services/ExpenseService.java b/src/main/java/com/application/munera/services/ExpenseService.java index 94d03d2..7a83fb0 100644 --- a/src/main/java/com/application/munera/services/ExpenseService.java +++ b/src/main/java/com/application/munera/services/ExpenseService.java @@ -183,6 +183,12 @@ public class ExpenseService { 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 fetchExpensesForDashboard(Person loggedInPerson, Year year) { List totalExpenses = new ArrayList<>(); final var yearValue = year.getValue(); @@ -218,7 +224,6 @@ public class ExpenseService { if (userDetails == null) { throw new IllegalStateException("No logged-in user found"); } - // Fetch the logged-in user final var loggedInUserId = userRepository.findByUsername(userDetails.getUsername()).getId(); Person loggedInPerson = this.personRepository.findByUserId(loggedInUserId).orElse(null); diff --git a/src/main/java/com/application/munera/services/UserService.java b/src/main/java/com/application/munera/services/UserService.java index 0cf5048..1828d32 100644 --- a/src/main/java/com/application/munera/services/UserService.java +++ b/src/main/java/com/application/munera/services/UserService.java @@ -37,6 +37,10 @@ public class UserService { 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) { userRepository.save(user); final var person = personRepository.findByUserId(user.getId()) @@ -46,7 +50,13 @@ public class UserService { 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) { + //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 final var existingUserOptional = userRepository.findOptionalByUsername(user.getUsername()); diff --git a/src/test/java/com/application/munera/services/PersonServiceTest.java b/src/test/java/com/application/munera/services/PersonServiceTest.java index 776da5b..a5715b0 100644 --- a/src/test/java/com/application/munera/services/PersonServiceTest.java +++ b/src/test/java/com/application/munera/services/PersonServiceTest.java @@ -38,9 +38,9 @@ class PersonServiceTest { person2.setLastName("second"); person2.setFirstName("person"); - Person person3 = new Person(); - person3.setLastName("third"); - person3.setFirstName("person"); +// Person person3 = new Person(); +// person3.setLastName("third"); +// person3.setFirstName("person"); Expense expense1 = mock(Expense.class); when(expense1.getPayer()).thenReturn(person);