diff --git a/src/main/java/com/application/munera/repositories/CategoryRepository.java b/src/main/java/com/application/munera/repositories/CategoryRepository.java new file mode 100644 index 0000000..450a564 --- /dev/null +++ b/src/main/java/com/application/munera/repositories/CategoryRepository.java @@ -0,0 +1,9 @@ +package com.application.munera.repositories; + +import com.application.munera.data.Category; +import com.application.munera.data.Expense; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.JpaSpecificationExecutor; + +public interface CategoryRepository extends JpaRepository, JpaSpecificationExecutor { +} diff --git a/src/main/java/com/application/munera/services/CategoryService.java b/src/main/java/com/application/munera/services/CategoryService.java new file mode 100644 index 0000000..1c4a98c --- /dev/null +++ b/src/main/java/com/application/munera/services/CategoryService.java @@ -0,0 +1,40 @@ +package com.application.munera.services; + +import com.application.munera.data.Category; +import com.application.munera.repositories.CategoryRepository; +import jakarta.persistence.Cache; +import org.springframework.stereotype.Service; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import java.util.List; +import java.util.Optional; + +@Service +public class CategoryService { + + private final CategoryRepository categoryRepository; + + public CategoryService(final CategoryRepository categoryRepository){ + this.categoryRepository = categoryRepository; + } + + public Optional get(Long id) { + return categoryRepository.findById(id); + } + + public List findAll() { + return categoryRepository.findAll(); + } + + public Category update(Category category) { + return categoryRepository.save(category); + } + + public void delete(Category category) { + categoryRepository.delete(category); + } + + public Page list(Pageable pageable){ + return categoryRepository.findAll(pageable); + } +} diff --git a/src/main/java/com/application/munera/services/ExpenseService.java b/src/main/java/com/application/munera/services/ExpenseService.java index b6660f0..6defec3 100644 --- a/src/main/java/com/application/munera/services/ExpenseService.java +++ b/src/main/java/com/application/munera/services/ExpenseService.java @@ -7,6 +7,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.domain.Specification; import org.springframework.stereotype.Service; +import java.util.List; import java.util.Optional; @Service @@ -22,6 +23,8 @@ public class ExpenseService { return repository.findById(id); } + public List findAll() {return repository.findAll();} + public Expense update(Expense entity) { return repository.save(entity); } 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 a6eb01d..e50fad8 100644 --- a/src/main/java/com/application/munera/views/expenses/ExpensesView.java +++ b/src/main/java/com/application/munera/views/expenses/ExpensesView.java @@ -1,8 +1,7 @@ package com.application.munera.views.expenses; -import com.application.munera.data.Category; import com.application.munera.data.Expense; -import com.application.munera.repositories.ExpenseRepository; +import com.application.munera.services.ExpenseService; import com.application.munera.views.MainLayout; import com.vaadin.flow.component.grid.Grid; import com.vaadin.flow.component.orderedlayout.VerticalLayout; @@ -17,12 +16,12 @@ import java.util.List; @PermitAll public class ExpensesView extends VerticalLayout { - private final ExpenseRepository expenseRepository; + private final ExpenseService expenseService; private final Grid grid; @Autowired - public ExpensesView(ExpenseRepository expenseRepository) { - this.expenseRepository = expenseRepository; + public ExpensesView(ExpenseService expenseService) { + this.expenseService = expenseService; this.grid = new Grid<>(Expense.class); addClassName("expenses-view"); setSizeFull(); @@ -40,7 +39,7 @@ public class ExpensesView extends VerticalLayout { } private void updateList() { - List expenses = expenseRepository.findAll(); + List expenses = expenseService.findAll(); grid.setItems(expenses); } } \ No newline at end of file