From 036a495bc7ae77d1d21e5943f75ff932e8aa450f Mon Sep 17 00:00:00 2001 From: s-choi Date: Thu, 17 Sep 2026 11:00:40 +0900 Subject: [PATCH] =?UTF-8?q?[EDIT]=20userId=E3=81=AB=E3=82=88=E3=82=8B?= =?UTF-8?q?=E5=8F=8E=E6=94=AF=E6=A4=9C=E7=B4=A2=E3=80=81=E6=9C=9F=E9=96=93?= =?UTF-8?q?=E8=A8=AD=E5=AE=9A=E6=A9=9F=E8=83=BD=E3=81=8C=E3=81=82=E3=82=8B?= =?UTF-8?q?=E6=A4=9C=E7=B4=A2=E3=80=81=E5=8F=8E=E5=85=A5=E3=83=BB=E6=94=AF?= =?UTF-8?q?=E5=87=BA=E3=81=AE=E6=A4=9C=E7=B4=A2=E6=A9=9F=E8=83=BD=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0=E3=81=97=E3=81=BE=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/TransactionRepository.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java b/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java index 4d768bc..a65d524 100644 --- a/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java +++ b/src/main/java/com/example/demo/app/infra/repository/TransactionRepository.java @@ -1,9 +1,26 @@ package com.example.demo.app.infra.repository; +import java.time.LocalDate; +import java.util.List; + import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; +import org.springframework.data.repository.query.Param; import com.example.demo.app.infra.entity.TransactionEntity; -public interface TransactionRepository extends JpaRepository{ +public interface TransactionRepository extends JpaRepository { + + @Query("select t from TransactionEntity t where t.userEntity.userId = :userId") + public TransactionEntity findByUserId(@Param("userId") Long userId); + + @Query("select t from TransactionEntity t where (t.transactionDate between :startDate and :endDate) and (t.userId = :userId) order by t.transactionDate asc") + public List findAllByDateAndUserId(LocalDate startDate, LocalDate endDate, Long userId); + + @Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryId = c.categoryId where (t.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 0") + public Integer findTotalExpense(LocalDate startDate, LocalDate endDate, Long userId); + + @Query("select sum(t.amount) from TransactionEntity t inner join CategoryEntity c on t.categoryId = c.categoryId where (t.userId = :userId and t.transactionDate between :startDate and :endDate) and c.transactionType = 1") + public Integer findTotalIncome(LocalDate startDate, LocalDate endDate, Long userId); }