Package api.mpba.rastvdmy.service.impl
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 Summary
ConstructorDescriptionBankAccountServiceImpl
(BankAccountRepository accountRepository, BankIdentityRepository bankIdentityRepository, CardService cardService, TokenVerifierService tokenVerifierService) Constructs a new instance ofBankAccountServiceImpl
. -
Method Summary
Modifier and TypeMethodDescriptionaddAccount
(jakarta.servlet.http.HttpServletRequest request, String bankName) Adds a new bank account for the user.void
connectAccounts
(BankIdentity bankIdentity) Connects multiple bank accounts to a user's bank identity.protected BankAccount
generateAccountData
(Random generateBalance, Currency accountCurrency, BankIdentity bankIdentity) Generates and saves a new bank account with random data for the specified bank identity.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.getTotalBalance
(jakarta.servlet.http.HttpServletRequest request) Retrieves the total balance across all bank accounts associated with the user.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.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.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.Methods inherited from class api.mpba.rastvdmy.service.generator.FinancialDataGenerator
generateAccountNumber, generateBankNumber, generateCardNumber, generateCvv, generateIban, generatePin, generateSwift, getRandomExpirationDate, getRandomStartDate
-
Constructor Details
-
BankAccountServiceImpl
@Autowired public BankAccountServiceImpl(BankAccountRepository accountRepository, BankIdentityRepository bankIdentityRepository, CardService cardService, TokenVerifierService tokenVerifierService) Constructs a new instance ofBankAccountServiceImpl
.- Parameters:
accountRepository
- the repository for bank account operationsbankIdentityRepository
- the repository for bank identity operationscardService
- the service for handling card operationstokenVerifierService
- 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 interfaceBankAccountService
- Parameters:
request
- the HTTP request containing user informationbankName
- 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 interfaceBankAccountService
- Parameters:
request
- the HTTP request containing user informationbankName
- the name of the bankaccountId
- the ID of the bank accounttype
- the type of visibility ("visible" to unmask)- Returns:
- the requested bank account
- Throws:
ApplicationException
- if the requested account is not found
-
getTotalBalance
Retrieves the total balance across all bank accounts associated with the user.- Specified by:
getTotalBalance
in interfaceBankAccountService
- 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 interfaceBankAccountService
- Parameters:
request
- the HTTP request containing user informationbankName
- the name of the bank- Returns:
- the created bank account
- Throws:
Exception
- if an error occurs during account creation
-
connectAccounts
Connects multiple bank accounts to a user's bank identity.- Specified by:
connectAccounts
in interfaceBankAccountService
- 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 balanceaccountCurrency
- the currency for the accountbankIdentity
- 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 interfaceBankAccountService
- Parameters:
request
- the HTTP request containing user informationbankName
- the name of the bankaccountId
- 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 interfaceBankAccountService
- Parameters:
request
- the HTTP request containing user informationbankName
- 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
-