From 435ddd65a29bd0a8e97d9a0502a8a1f763ce97bd Mon Sep 17 00:00:00 2001 From: filippo-ferrari Date: Mon, 15 Jul 2024 19:38:43 +0200 Subject: [PATCH] feat: added default sorting to grid --- .../application/munera/repositories/ExpenseRepository.java | 3 ++- .../java/com/application/munera/services/ExpenseService.java | 4 ++++ .../com/application/munera/views/expenses/ExpensesView.java | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/application/munera/repositories/ExpenseRepository.java b/src/main/java/com/application/munera/repositories/ExpenseRepository.java index da13977..cbc9f26 100644 --- a/src/main/java/com/application/munera/repositories/ExpenseRepository.java +++ b/src/main/java/com/application/munera/repositories/ExpenseRepository.java @@ -28,4 +28,5 @@ public interface ExpenseRepository extends JpaRepository, JpaSpec Set findUnpaidDebtorsExpensesByPersonId(@Param("personId") Long personId); boolean existsByIdAndIsResolvedTrue(Long id); -} \ No newline at end of file + + List findAllByOrderByDateDesc();} \ No newline at end of file diff --git a/src/main/java/com/application/munera/services/ExpenseService.java b/src/main/java/com/application/munera/services/ExpenseService.java index 534454d..d7c1204 100644 --- a/src/main/java/com/application/munera/services/ExpenseService.java +++ b/src/main/java/com/application/munera/services/ExpenseService.java @@ -70,4 +70,8 @@ public class ExpenseService { return this.repository.existsByIdAndIsResolvedTrue(expense.getId()); } + public List findAllOrderByDateDescending() { + return this.repository.findAllByOrderByDateDesc(); + } + } 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 c691a7f..fc06a49 100644 --- a/src/main/java/com/application/munera/views/expenses/ExpensesView.java +++ b/src/main/java/com/application/munera/views/expenses/ExpensesView.java @@ -99,7 +99,7 @@ public class ExpensesView extends Div implements BeforeEnterObserver { grid.addColumn(new ComponentRenderer<>(expense1 -> createBadge(expenseService.isExpenseResolved(expense1)))).setHeader("Status").setSortable(true); grid.getColumns().forEach(col -> col.setAutoWidth(true)); - grid.setItems(this.expenseService.findAll()); + grid.setItems(this.expenseService.findAllOrderByDateDescending()); grid.setPaginatorSize(5); grid.setPageSize(25); // setting page size grid.addThemeVariants(GridVariant.LUMO_NO_BORDER);