1 interface AccountRepository extends JpaRepository<AccountJpaEntity, Long> {
2 }

 1 interface ActivityRepository extends
 2         JpaRepository<ActivityJpaEntity, Long> {
 3
 4     @Query("""
 5             select a from ActivityJpaEntity a
 6             where a.ownerAccountId = :ownerAccountId
 7             and a.timestamp ≥ :since
 8             """)
 9     List<ActivityJpaEntity> findByOwnerSince(
10             @Param("ownerAccountId") long ownerAccountId,
11             @Param("since") LocalDateTime since);
12
13     @Query("""
14             select sum(a.amount) from ActivityJpaEntity a
15             where a.targetAccountId = :accountId
16             and a.ownerAccountId = :accountId
17             and a.timestamp < :until
18             """)
19     Optional<Long> getDepositBalanceUntil(
20             @Param("accountId") Long accountId,
21             @Param("until") LocalDateTime until);
22
23     @Query("""
24             select sum(a.amount) from ActivityJpaEntity a
25             where a.sourceAccountId = :accountId
26             and a.ownerAccountId = :accountId
27             and a.timestamp < :until
28             """)
29     Optional<Long> getWithdrawalBalanceUntil(
30             @Param("accountId") long accountId,
31             @Param("until") LocalDateTime until);
32
33 }
