[EDIT] userIdによる収支検索、期間設定機能がある検索、収入・支出の検索機能を追加しました。

This commit is contained in:
s-choi
2026-09-17 11:00:40 +09:00
parent 534fc2683d
commit 036a495bc7

View File

@@ -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<TransactionEntity, Long> {
@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<TransactionEntity> 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);
}