Package api.mpba.rastvdmy.service.impl
Class CurrencyDataServiceImpl
java.lang.Object
api.mpba.rastvdmy.service.impl.CurrencyDataServiceImpl
- All Implemented Interfaces:
 CurrencyDataService
Service implementation for managing currency data.
 This service handles retrieving currency information from the database and external APIs.
- 
Constructor Summary
ConstructorsConstructorDescriptionCurrencyDataServiceImpl(CurrencyDataRepository currencyDataRepository, org.springframework.web.client.RestTemplate restTemplate, org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, TokenVerifierService tokenVerifierService) Constructs a new CurrencyDataServiceImpl with the specified repositories, RestTemplate, JdbcTemplate, JwtService, and UserProfileRepository. - 
Method Summary
Modifier and TypeMethodDescriptionconvertCurrency(String baseCurrency, String targetCurrency) Converts an amount from the base currency to the target currency using an external API.findAllCurrencies(jakarta.servlet.http.HttpServletRequest request) Retrieves all available currencies.voidRetrieves all exchange rates from an external API and updates the database.findByCurrency(jakarta.servlet.http.HttpServletRequest request, String currencyType) Retrieves currency data for a specified currency type.voidInitializes the database with currency data and connects the admin user to all currencies. 
- 
Constructor Details
- 
CurrencyDataServiceImpl
@Autowired public CurrencyDataServiceImpl(CurrencyDataRepository currencyDataRepository, org.springframework.web.client.RestTemplate restTemplate, org.springframework.jdbc.core.JdbcTemplate jdbcTemplate, TokenVerifierService tokenVerifierService) Constructs a new CurrencyDataServiceImpl with the specified repositories, RestTemplate, JdbcTemplate, JwtService, and UserProfileRepository.- Parameters:
 currencyDataRepository- the repository for currency datarestTemplate- the RestTemplate for making HTTP requestsjdbcTemplate- the JdbcTemplate for executing SQL queriestokenVerifierService- the service for extracting user token and getting user data from the request
 
 - 
 - 
Method Details
- 
findAllCurrencies
Retrieves all available currencies.- Specified by:
 findAllCurrenciesin interfaceCurrencyDataService- Parameters:
 request- the HTTP request containing user data- Returns:
 - a list of all available currencies
 
 - 
findByCurrency
public CurrencyData findByCurrency(jakarta.servlet.http.HttpServletRequest request, String currencyType) Retrieves currency data for a specified currency type. If the currency is not found in the database, it fetches it from an external API.- Specified by:
 findByCurrencyin interfaceCurrencyDataService- Parameters:
 request- the HTTP request containing user datacurrencyType- the type of currency to retrieve- Returns:
 - the currency data for the specified type
 - Throws:
 ApplicationException- if the specified currency type is invalid or not found
 - 
convertCurrency
Converts an amount from the base currency to the target currency using an external API.- Specified by:
 convertCurrencyin interfaceCurrencyDataService- Parameters:
 baseCurrency- the currency from which to converttargetCurrency- the currency to which to convert- Returns:
 - the currency data for the target currency
 
 - 
initializeData
@PostConstruct public void initializeData()Initializes the database with currency data and connects the admin user to all currencies. - 
findAllExchangeRates
@Scheduled(fixedRate=86400000L) public void findAllExchangeRates()Retrieves all exchange rates from an external API and updates the database. This method is scheduled to run every 24 hours.- Specified by:
 findAllExchangeRatesin interfaceCurrencyDataService
 
 -