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 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 update
      date - the new date for the transaction
      description - the new description for the transaction
      name - the new name for the transaction
      value - the new value for the transaction