Package api.mpba.rastvdmy.service.impl
Class CardServiceImpl
java.lang.Object
api.mpba.rastvdmy.service.generator.FinancialDataGenerator
api.mpba.rastvdmy.service.impl.CardServiceImpl
- All Implemented Interfaces:
CardService
Implementation of the CardService interface for managing user bank cards.
This service provides methods for adding, retrieving, and removing cards associated with bank accounts.
It includes functionality for card encryption and data masking to ensure sensitive information is handled securely.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Maximum number of cards that can be created per user.static final int
Minimum number of cards that can be created per user. -
Constructor Summary
ConstructorDescriptionCardServiceImpl
(CardRepository cardRepository, BankIdentityRepository bankIdentityRepository, BankAccountRepository bankAccountRepository, TokenVerifierService tokenVerifierService) Constructs a CardServiceImpl with the specified repositories and services. -
Method Summary
Modifier and TypeMethodDescriptionaddAccountCard
(String bankName, UUID accountId, jakarta.servlet.http.HttpServletRequest request) Adds a new card associated with the specified bank account.void
connectCards
(BankAccount account) Connects a number of cards to a specified bank account.boolean
decryptCardData
(Card card, boolean unmask) Decrypts the sensitive data of a card, optionally unmasking it.protected Card
generateCard
(String cardNumber, String cvv, String pin, BankAccount account) Generates and encrypts a new card with the provided details.getAccountCardById
(String bankName, UUID accountId, UUID cardId, jakarta.servlet.http.HttpServletRequest request, String type) Retrieves a specific card associated with a bank account by card ID.getAccountCards
(String bankName, UUID accountId, jakarta.servlet.http.HttpServletRequest request) Retrieves all cards associated with a specific bank account.void
removeAccountCard
(String bankName, UUID accountId, UUID cardId, jakarta.servlet.http.HttpServletRequest request) Removes a specific card associated with a bank account.void
removeAllCards
(BankAccount account) Removes all cards associated with a specified bank account.Methods inherited from class api.mpba.rastvdmy.service.generator.FinancialDataGenerator
generateAccountNumber, generateBankNumber, generateCardNumber, generateCvv, generateIban, generatePin, generateSwift, getRandomExpirationDate, getRandomStartDate
-
Field Details
-
MAX_AVAILABLE_CARDS
public static final int MAX_AVAILABLE_CARDSMaximum number of cards that can be created per user.- See Also:
-
MIN_AVAILABLE_CARDS
public static final int MIN_AVAILABLE_CARDSMinimum number of cards that can be created per user.- See Also:
-
-
Constructor Details
-
CardServiceImpl
@Autowired public CardServiceImpl(CardRepository cardRepository, BankIdentityRepository bankIdentityRepository, BankAccountRepository bankAccountRepository, TokenVerifierService tokenVerifierService) Constructs a CardServiceImpl with the specified repositories and services.- Parameters:
cardRepository
- the repository for card databankIdentityRepository
- the repository for bank identity databankAccountRepository
- the repository for bank account datatokenVerifierService
- the service for extracting user token and getting user data from the request
-
-
Method Details
-
getAccountCards
public List<Card> getAccountCards(String bankName, UUID accountId, jakarta.servlet.http.HttpServletRequest request) Retrieves all cards associated with a specific bank account.- Specified by:
getAccountCards
in interfaceCardService
- Parameters:
bankName
- the name of the bankaccountId
- the ID of the bank accountrequest
- the HTTP request containing user data- Returns:
- a list of cards associated with the specified account
- Throws:
ApplicationException
- if no cards are found for the specified account
-
getAccountCardById
public Card getAccountCardById(String bankName, UUID accountId, UUID cardId, jakarta.servlet.http.HttpServletRequest request, String type) Retrieves a specific card associated with a bank account by card ID.- Specified by:
getAccountCardById
in interfaceCardService
- Parameters:
bankName
- the name of the bankaccountId
- the ID of the bank accountcardId
- the ID of the card to retrieverequest
- the HTTP request containing user datatype
- the visibility type (e.g., "visible" or "hidden")- Returns:
- the specified card if found
- Throws:
ApplicationException
- if the specified card is not found
-
decryptCardData
Decrypts the sensitive data of a card, optionally unmasking it.- Parameters:
card
- the card to decryptunmask
- whether to unmask the data- Returns:
- true if decryption was successful; false otherwise
-
addAccountCard
@Transactional public Card addAccountCard(String bankName, UUID accountId, jakarta.servlet.http.HttpServletRequest request) throws Exception Adds a new card associated with the specified bank account.- Specified by:
addAccountCard
in interfaceCardService
- Parameters:
bankName
- the name of the bankaccountId
- the ID of the bank accountrequest
- the HTTP request containing user data- Returns:
- the created Card
- Throws:
Exception
- if there is an error while adding the card
-
connectCards
Connects a number of cards to a specified bank account.- Specified by:
connectCards
in interfaceCardService
- Parameters:
account
- the bank account to connect cards to- Throws:
Exception
- if there is an error while connecting cards
-
generateCard
@Transactional protected Card generateCard(String cardNumber, String cvv, String pin, BankAccount account) throws Exception Generates and encrypts a new card with the provided details.- Parameters:
cardNumber
- the card numbercvv
- the CVV of the cardpin
- the PIN for the cardaccount
- the bank account associated with the card- Returns:
- the generated Card
- Throws:
Exception
- if there is an error while generating the card
-
removeAccountCard
public void removeAccountCard(String bankName, UUID accountId, UUID cardId, jakarta.servlet.http.HttpServletRequest request) Removes a specific card associated with a bank account.- Specified by:
removeAccountCard
in interfaceCardService
- Parameters:
bankName
- the name of the bankaccountId
- the ID of the bank accountcardId
- the ID of the card to removerequest
- the HTTP request containing user data- Throws:
ApplicationException
- if the specified card is not found
-
removeAllCards
Removes all cards associated with a specified bank account.- Specified by:
removeAllCards
in interfaceCardService
- Parameters:
account
- the bank account whose cards should be removed- Throws:
ApplicationException
- if no cards are found for the specified account
-