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); + } + }