Interface TransactionRepository
- All Superinterfaces:
org.springframework.data.repository.CrudRepository<Transaction,
,Long> org.springframework.data.repository.Repository<Transaction,
Long>
public interface TransactionRepository
extends org.springframework.data.repository.CrudRepository<Transaction,Long>
A repository for transactions, which extends CrudRepository.
This repository provides methods for retrieving transactions from the
database, as well as updating existing transactions.
- Since:
- 16.04.2023
- Version:
- 23.04.2023
- Author:
- Group19
-
Method Summary
Modifier and TypeMethodDescriptiongetExpensesByBudgetIdOrderByDateAsc
(int budgetId) Retrieves all expenses for a given budget, ordered by date in ascending order.getIncomesByBudgetIdOrderByDateAsc
(int budgetId) Retrieves all incomes for a given budget, ordered by date in ascending order.getTransactionsDatesByBudgetIdOrderByDateAsc
(long budgetId) Retrieves all dates for transactions associated with a given budget, ordered by date in ascending order.void
updateTransaction
(long tid, LocalDate date, String description, String name, int value) Updates an existing transaction with new information.Methods inherited from interface org.springframework.data.repository.CrudRepository
count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findAll, findAllById, findById, save, saveAll
-
Method Details
-
getExpensesByBudgetIdOrderByDateAsc
@Query(value="select * from transaction t where t.value < 0 and t.budget_id = ?1 order by t.date asc", nativeQuery=true) List<Transaction> getExpensesByBudgetIdOrderByDateAsc(int budgetId) Retrieves all expenses for a given budget, ordered by date in ascending order.- Parameters:
budgetId
- the ID of the budget to retrieve expenses for- Returns:
- a list of expenses for the given budget, ordered by date in ascending order
-
getIncomesByBudgetIdOrderByDateAsc
@Query(value="select * from transaction t where t.value > 0 and t.budget_id = ?1 order by t.date asc", nativeQuery=true) List<Transaction> getIncomesByBudgetIdOrderByDateAsc(int budgetId) Retrieves all incomes for a given budget, ordered by date in ascending order.- Parameters:
budgetId
- the ID of the budget to retrieve incomes for- Returns:
- a list of incomes for the given budget, ordered by date in ascending order
-
getTransactionsDatesByBudgetIdOrderByDateAsc
@Query(value="select t.date from transaction t where t.budget_id = ?1 order by t.date asc", nativeQuery=true) List<String> getTransactionsDatesByBudgetIdOrderByDateAsc(long budgetId) Retrieves all dates for transactions associated with a given budget, ordered by date in ascending order.- Parameters:
budgetId
- the ID of the budget to retrieve transaction dates for- Returns:
- a list of transaction dates for the given budget, ordered by date in ascending order
-
updateTransaction
@Transactional @Modifying @Query(value="update transaction t set t.date = ?2, t.description = ?3, t.tname = ?4, t.value = ?5 where t.tid = ?1", nativeQuery=true) void updateTransaction(long tid, LocalDate date, String description, String name, int value) Updates an existing transaction with new information.- Parameters:
tid
- the ID of the transaction to updatedate
- the new date for the transactiondescription
- the new description for the transactionname
- the new name for the transactionvalue
- the new value for the transaction
-