feat: DashboardView year selector
This commit is contained in:
parent
76e17cb152
commit
d67359ff11
3 changed files with 12 additions and 4 deletions
|
@ -12,6 +12,8 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
public interface ExpenseRepository extends JpaRepository<Expense, Long>, JpaSpecificationExecutor<Expense> {
|
||||
@Query("SELECT DISTINCT YEAR(e.date) FROM Expense e WHERE e.userId = :userId ORDER BY YEAR(e.date)")
|
||||
List<Integer> findExpenseYearsByUserId(@Param("userId") Long userId);
|
||||
|
||||
// Find expenses where the payer is a specific person
|
||||
@Query("SELECT e FROM Expense e WHERE e.payer.id = :personId")
|
||||
|
|
|
@ -10,7 +10,6 @@ import com.application.munera.security.SecurityUtils;
|
|||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
|
@ -204,6 +203,15 @@ public class ExpenseService {
|
|||
return totalExpenses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the list of years in which at least one expense has been made
|
||||
* @param userId the user from which to look into the expenses
|
||||
* @return the list of years found
|
||||
*/
|
||||
public List<Integer> getAvailableExpenseYearsForUser(Long userId) {
|
||||
return expenseRepository.findExpenseYearsByUserId(userId);
|
||||
}
|
||||
|
||||
// ================================
|
||||
// Private methods
|
||||
// ================================
|
||||
|
|
|
@ -44,7 +44,7 @@ public class DashboardView extends Div {
|
|||
addClassName("highcharts-view"); // Optional CSS class for styling
|
||||
|
||||
// Fetch available years from the database
|
||||
List<Integer> availableYears = List.of(Integer.valueOf("2024"), Integer.valueOf("2023"));
|
||||
List<Integer> availableYears = this.expenseService.getAvailableExpenseYearsForUser(loggedUser.getId());
|
||||
|
||||
// Initialize the ComboBox for year selection
|
||||
yearComboBox = new ComboBox<>("Select Year");
|
||||
|
@ -115,9 +115,7 @@ public class DashboardView extends Div {
|
|||
bottomRowLayout.add(bottomRightChartDiv);
|
||||
|
||||
mainLayout.add(bottomRowLayout);
|
||||
|
||||
add(mainLayout);
|
||||
|
||||
updateCharts(Year.now());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue