diff --git a/src/main/java/com/application/munera/services/CategoryService.java b/src/main/java/com/application/munera/services/CategoryService.java index a9dfbb4..51d3dbb 100644 --- a/src/main/java/com/application/munera/services/CategoryService.java +++ b/src/main/java/com/application/munera/services/CategoryService.java @@ -6,6 +6,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; +import java.util.Collection; import java.util.List; import java.util.Optional; @@ -37,4 +38,8 @@ public class CategoryService { public Page list(Pageable pageable){ return categoryRepository.findAll(pageable); } + + public Collection findNames() { + return categoryRepository.findAll().stream().map(Category::getName).toList(); + } } diff --git a/src/main/java/com/application/munera/services/PersonService.java b/src/main/java/com/application/munera/services/PersonService.java index 78e490c..23873dc 100644 --- a/src/main/java/com/application/munera/services/PersonService.java +++ b/src/main/java/com/application/munera/services/PersonService.java @@ -69,4 +69,8 @@ public class PersonService { final var debit = this.expenseService.findUnpaidDebtByUser(person).stream().map(Expense::getCost).reduce(BigDecimal.ZERO, BigDecimal::add); return credit.subtract(debit); } + + public List findNames() { + return personRepository.findAll().stream().map(Person::getFirstName).toList(); + } } diff --git a/src/main/java/com/application/munera/views/expenses/ExpensesView.java b/src/main/java/com/application/munera/views/expenses/ExpensesView.java index 66a2ee9..431d178 100644 --- a/src/main/java/com/application/munera/views/expenses/ExpensesView.java +++ b/src/main/java/com/application/munera/views/expenses/ExpensesView.java @@ -82,7 +82,10 @@ public class ExpensesView extends Div implements BeforeEnterObserver { this.eventService = eventService; addClassNames("expenses-view"); - Filters filters = new Filters(this::refreshGrid); + final var categoriesNames = this.categoryService.findAll(); + final var creditorsNames = this.personService.findAllAsList(); + Filters filters = new Filters(this::refreshGrid, categoriesNames, creditorsNames); + // Create UI SplitLayout splitLayout = new SplitLayout(); diff --git a/src/main/java/com/application/munera/views/expenses/Filters.java b/src/main/java/com/application/munera/views/expenses/Filters.java index 57d5974..e81d0f0 100644 --- a/src/main/java/com/application/munera/views/expenses/Filters.java +++ b/src/main/java/com/application/munera/views/expenses/Filters.java @@ -3,8 +3,6 @@ package com.application.munera.views.expenses; import com.application.munera.data.Category; import com.application.munera.data.Expense; import com.application.munera.data.Person; -import com.application.munera.services.CategoryService; -import com.application.munera.services.PersonService; import com.vaadin.flow.component.Component; import com.vaadin.flow.component.Text; import com.vaadin.flow.component.button.Button; @@ -19,7 +17,6 @@ import com.vaadin.flow.component.orderedlayout.FlexLayout; import com.vaadin.flow.component.textfield.TextField; import com.vaadin.flow.theme.lumo.LumoUtility; import jakarta.persistence.criteria.*; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.jpa.domain.Specification; import java.util.ArrayList; @@ -34,21 +31,15 @@ public class Filters extends Div implements Specification { private final MultiSelectComboBox creditors = new MultiSelectComboBox<>("Creditors"); private final CheckboxGroup isResolved = new CheckboxGroup<>("Role"); - @Autowired - private PersonService personService; - - @Autowired - private CategoryService categoryService; - - public Filters(Runnable onSearch) { + public Filters(Runnable onSearch, List categoriesNames, List creditorsNames) { setWidthFull(); addClassName("filter-layout"); addClassNames(LumoUtility.Padding.Horizontal.LARGE, LumoUtility.Padding.Vertical.MEDIUM, LumoUtility.BoxSizing.BORDER); name.setPlaceholder("Expense's name"); - - creditors.setItems(this.personService.findAllAsList()); - category.setItems(this.categoryService.findAll()); + final var names = creditorsNames.stream().map(Person::getFirstName).toArray(); + creditors.setItems((creditorsNames)); + isResolved.setItems("Worker", "Supervisor", "Manager", "External"); isResolved.addClassName("double-width");