package de.fau.amos.virtualledger.server.savings;

import de.fau.amos.virtualledger.server.model.SavingsAccount;

import javax.enterprise.context.ApplicationScoped;
import java.util.ArrayList;
import java.util.List;

@ApplicationScoped
public class SavingsController {


    List<SavingsAccount> savingsAccountList = new ArrayList<>();

    public List<SavingsAccount> getSavingAccounts(String email) {

        return savingsAccountList;
    }

    public void addSavingAccount(String email, SavingsAccount savingsAccount) throws SavingsException {

        savingsAccount.id = savingsAccountList.size();
        savingsAccountList.add(savingsAccount);
    }
}


package de.fau.amos.virtualledger.server.savings;

import de.fau.amos.virtualledger.server.model.SavingsAccount;
import de.fau.amos.virtualledger.server.persistence.SavingsAccountRepository;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.util.List;

@ApplicationScoped
public class SavingsController {

    private SavingsAccountRepository savingsAccountRepository;

    @Inject
    public SavingsController(SavingsAccountRepository savingsAccountRepository) {
        this.savingsAccountRepository = savingsAccountRepository;
    }
    protected  SavingsController () { }

    public List<SavingsAccount> getSavingAccounts(String email) {

        return savingsAccountRepository.getSavingsAccountsByUserEmail(email);
    }

    public void addSavingAccount(String email, SavingsAccount savingsAccount) throws SavingsException {

        savingsAccountRepository.createSavingsAccount(email, savingsAccount);
    }
}


use the SavingsAccountRepository instead of storing in RAM in SavingsController