This is a Symfony(7.1) application for fetching, storing, and converting currency exchange rates. It pulls exchange rates from two sources: the European Central Bank (ECB) and the Central Bank of Russia (CBR). The application can convert currencies directly or indirectly via available base currencies (EUR or RUB) and provides a REST API endpoint for currency conversion.
- Fetch daily exchange rates from the ECB and CBR.
- Store exchange rates in a database using Doctrine ORM.
- Support for conversion between any two currencies, including indirect conversions via EUR or RUB as base currencies.
- REST API endpoint to handle currency conversion requests.
- Unit and integration tests for command and service functionality.
- PHP 8.1 or higher
- Composer
- Symfony CLI
- MySQL or another supported database
-
Clone the Repository
git clone <repository-url> cd <repository-directory>
-
Install Dependencies
composer install
-
Configure Environment Variables
Copy
.env.example
to.env
and update the necessary variables:cp .env.example .env
Update the following environment variables:
DATABASE_URL=mysql://db_user:[email protected]:3306/currency_conversion_db ECB_URL=https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml CBR_URL=https://www.cbr.ru/scripts/XML_daily.asp
-
Set Up the Database
php bin/console doctrine:database:create php bin/console doctrine:migrations:migrate
-
Run the Application
You can use the Symfony CLI to run the development server:
symfony serve
The application will be available at
http://127.0.0.1:8000
.
The application provides a Symfony console command to fetch and store daily exchange rates from the ECB or CBR:
php bin/console app:fetch-exchange-rates [ECB|CBR]
- Replace
[ECB|CBR]
with eitherECB
orCBR
to specify the data source (defaults toECB
if omitted).
The application provides an API endpoint for currency conversion. You can use curl
or any REST client to interact with it.
-
Endpoint:
/api/convert
-
Method:
POST
-
Request Body:
{ "from": "USD", "to": "CZK", "amount": 100 }
-
Example Request:
curl --location 'http://127.0.0.1:8000/api/convert' \ --header 'Content-Type: application/json' \ --data '{ "from": "USD", "to": "CZK", "amount": 100 }'
-
Response:
{ "from": "USD", "to": "CZK", "original_amount": 100, "converted_amount": 2500.00 }
The application includes unit and integration tests to ensure functionality.
-
Run All Tests:
php bin/phpunit
-
Run Specific Tests:
php bin/phpunit tests/Service/CurrencyConverterTest.php php bin/phpunit tests/Command/FetchExchangeRatesCommandTest.php
src/Command/FetchExchangeRatesCommand.php
: Console command to fetch exchange rates from ECB or CBR.src/Service/CurrencyConverter.php
: Service to handle currency conversion, supporting both direct and indirect conversions.src/Controller/Api/CurrencyController.php
: REST API controller for handling currency conversion requests.tests/
: Contains unit and integration tests.
This project is open-source and available under the MIT License.