Class BankAccountServiceImpl

java.lang.Object
api.mpba.rastvdmy.service.generator.FinancialDataGenerator
api.mpba.rastvdmy.service.impl.BankAccountServiceImpl
All Implemented Interfaces:
BankAccountService

@Service public class BankAccountServiceImpl extends FinancialDataGenerator implements BankAccountService
Service implementation for managing bank accounts, including account retrieval, creation, and deletion functionalities. It also handles user-related operations related to bank accounts, ensuring that user data is appropriately encrypted and masked.
  • Constructor Details

    • BankAccountServiceImpl

      @Autowired public BankAccountServiceImpl(BankAccountRepository accountRepository, BankIdentityRepository bankIdentityRepository, CardService cardService, TokenVerifierService tokenVerifierService)
      Constructs a new instance of BankAccountServiceImpl.
      Parameters:
      accountRepository - the repository for bank account operations
      bankIdentityRepository - the repository for bank identity operations
      cardService - the service for handling card operations
      tokenVerifierService - the service for extracting user token and getting user data from the request
  • Method Details

    • getUserAccounts

      public List<BankAccount> getUserAccounts(jakarta.servlet.http.HttpServletRequest request, String bankName)
      Retrieves a list of bank accounts associated with the specified bank for the user identified by the request.
      Specified by:
      getUserAccounts in interface BankAccountService
      Parameters:
      request - the HTTP request containing user information
      bankName - the name of the bank
      Returns:
      a list of bank accounts
      Throws:
      ApplicationException - if no accounts are found for the user, or if there is an error during decryption
    • getAccountById

      public BankAccount getAccountById(jakarta.servlet.http.HttpServletRequest request, String bankName, UUID accountId, String type)
      Retrieves a specific bank account by its ID for the user identified by the request and bank name.
      Specified by:
      getAccountById in interface BankAccountService
      Parameters:
      request - the HTTP request containing user information
      bankName - the name of the bank
      accountId - the ID of the bank account
      type - the type of visibility ("visible" to unmask)
      Returns:
      the requested bank account
      Throws:
      ApplicationException - if the requested account is not found
    • getTotalBalance

      public Map<String,BigDecimal> getTotalBalance(jakarta.servlet.http.HttpServletRequest request)
      Retrieves the total balance across all bank accounts associated with the user.
      Specified by:
      getTotalBalance in interface BankAccountService
      Parameters:
      request - the HTTP request containing user information
      Returns:
      a map of total balances for each currency
      Throws:
      ApplicationException - if no bank identities are found for the user
    • addAccount

      @Transactional public BankAccount addAccount(jakarta.servlet.http.HttpServletRequest request, String bankName) throws Exception
      Adds a new bank account for the user.
      Specified by:
      addAccount in interface BankAccountService
      Parameters:
      request - the HTTP request containing user information
      bankName - the name of the bank
      Returns:
      the created bank account
      Throws:
      Exception - if an error occurs during account creation
    • connectAccounts

      @Transactional public void connectAccounts(BankIdentity bankIdentity) throws Exception
      Connects multiple bank accounts to a user's bank identity.
      Specified by:
      connectAccounts in interface BankAccountService
      Parameters:
      bankIdentity - the bank identity to connect accounts to
      Throws:
      Exception - if an error occurs during account creation
    • generateAccountData

      @Transactional protected BankAccount generateAccountData(Random generateBalance, Currency accountCurrency, BankIdentity bankIdentity) throws Exception
      Generates and saves a new bank account with random data for the specified bank identity.
      Parameters:
      generateBalance - the random number generator for account balance
      accountCurrency - the currency for the account
      bankIdentity - the bank identity associated with the account
      Returns:
      the generated bank account
      Throws:
      Exception - if an error occurs during account generation
    • removeAccount

      @Transactional public void removeAccount(jakarta.servlet.http.HttpServletRequest request, String bankName, UUID accountId)
      Removes a specific bank account for the user identified by the request and bank name.
      Specified by:
      removeAccount in interface BankAccountService
      Parameters:
      request - the HTTP request containing user information
      bankName - the name of the bank
      accountId - the ID of the bank account to be removed
      Throws:
      ApplicationException - if the requested account is not found, or if there is an error during card removal
    • removeAllAccounts

      @Transactional public void removeAllAccounts(jakarta.servlet.http.HttpServletRequest request, String bankName)
      Removes all bank accounts associated with the specified bank for the user identified by the request.
      Specified by:
      removeAllAccounts in interface BankAccountService
      Parameters:
      request - the HTTP request containing user information
      bankName - the name of the bank
      Throws:
      ApplicationException - if no bank identities or accounts are found for the user, or if there is an error during card removal