From e50a3f1387134774117b302e01fb922f3f64320f Mon Sep 17 00:00:00 2001 From: filippo-ferrari Date: Tue, 2 Jul 2024 22:16:16 +0200 Subject: [PATCH] feat: added service method --- .../application/munera/repositories/ExpenseRepository.java | 4 ++++ .../java/com/application/munera/services/ExpenseService.java | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/main/java/com/application/munera/repositories/ExpenseRepository.java b/src/main/java/com/application/munera/repositories/ExpenseRepository.java index 0e0e586..8893a3b 100644 --- a/src/main/java/com/application/munera/repositories/ExpenseRepository.java +++ b/src/main/java/com/application/munera/repositories/ExpenseRepository.java @@ -7,6 +7,7 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; +import java.util.List; import java.util.Set; public interface ExpenseRepository extends JpaRepository, JpaSpecificationExecutor { @@ -16,4 +17,7 @@ public interface ExpenseRepository extends JpaRepository, JpaSpec @Query("SELECT e FROM Expense e JOIN e.debtors d WHERE d.id = :personId") Set findDebtorsExpensesByPersonId(@Param("personId") Long personId); + + @Query("SELECT e FROM Expense e WHERE YEAR(e.date) = :year") + List findAllByYear(@Param("year") int year); } \ 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 d0393f9..d92fc9f 100644 --- a/src/main/java/com/application/munera/services/ExpenseService.java +++ b/src/main/java/com/application/munera/services/ExpenseService.java @@ -54,4 +54,8 @@ public class ExpenseService { return (int) repository.count(); } + public List findAllByYear(final int year ) { + return this.repository.findAllByYear(year); + } + }