Skip to content
Snippets Groups Projects
Commit 17e3e027 authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Fixed #477 - error while deleting default account with transactions

parent 0da013e8
No related branches found
No related tags found
No related merge requests found
Pipeline #2204 failed
......@@ -3,7 +3,7 @@ package de.deadlocker8.budgetmaster.accounts;
import de.deadlocker8.budgetmaster.authentication.User;
import de.deadlocker8.budgetmaster.authentication.UserRepository;
import de.deadlocker8.budgetmaster.services.Resetable;
import de.deadlocker8.budgetmaster.transactions.TransactionRepository;
import de.deadlocker8.budgetmaster.transactions.TransactionService;
import de.deadlocker8.budgetmaster.utils.Strings;
import de.thecodelabs.utils.util.Localization;
import org.slf4j.Logger;
......@@ -19,14 +19,14 @@ public class AccountService implements Resetable
{
private final Logger LOGGER = LoggerFactory.getLogger(this.getClass());
private AccountRepository accountRepository;
private TransactionRepository transactionRepository;
private TransactionService transactionService;
private UserRepository userRepository;
@Autowired
public AccountService(AccountRepository accountRepository, TransactionRepository transactionRepository, UserRepository userRepository)
public AccountService(AccountRepository accountRepository, TransactionService transactionService, UserRepository userRepository)
{
this.accountRepository = accountRepository;
this.transactionRepository = transactionRepository;
this.transactionService = transactionService;
this.userRepository = userRepository;
createDefaults();
......@@ -47,7 +47,7 @@ public class AccountService implements Resetable
public void deleteAccount(int ID)
{
Account accountToDelete = accountRepository.findOne(ID);
transactionRepository.delete(accountToDelete.getReferringTransactions());
transactionService.deleteTransactionsWithAccount(accountToDelete);
accountToDelete.setReferringTransactions(new ArrayList<>());
List<Account> accounts = accountRepository.findAll();
......
......@@ -31,4 +31,6 @@ public interface TransactionRepository extends JpaRepository<Transaction, Intege
@Query(value = "SELECT SUM(t.amount) FROM `transaction` as t WHERE t.transfer_account_id = ?1 AND t.date BETWEEN ?2 AND ?3", nativeQuery = true)
Integer getRestForTransferDestination(int accountID, String startDate, String endDate);
List<Transaction> findAllByTransferAccount(Account account);
}
\ No newline at end of file
......@@ -167,6 +167,18 @@ public class TransactionService implements Resetable
}
}
public void deleteTransactionsWithAccount(Account account) {
for(Transaction referringTransaction : account.getReferringTransactions())
{
deleteTransactionInRepo(referringTransaction.getID());
}
for(Transaction referringTransaction : transactionRepository.findAllByTransferAccount(account))
{
deleteTransactionInRepo(referringTransaction.getID());
}
}
@Override
public void createDefaults()
{
......
......@@ -292,6 +292,12 @@ public class DatabaseImportTest
return null;
}
@Override
public List<Transaction> findAllByTransferAccount(Account account)
{
return null;
}
@Override
public List<Transaction> findAll()
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment