Skip to content

anton-kulakov/CurrencyExchange

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Currency exchange

Currency exchange is a REST API application for managing exchange rates and performing currency conversions. This project is based on the technical specification provided in the Java Backend Roadmap by Sergey Zhukov (link here).

🧱Built with

Java Java-Servlet JDBC SQLite APACHE MAVEN Apache Tomcat Lombok

⚙️Application features

  • add currencies and exchange rates
  • update exchange rates
  • convert amounts of money between different currencies based on the latest exchange rates

📝REST API description

  1. Database:

The project uses SQLite as the database, which allows embedding a file with populated tables into the project resources for the application's functionality.

Database diagram:

Описание
  1. REST API endpoints:

GET /currencies - returns list of all currencies

Example of response:

[
    {
        "id": 0,
        "name": "United States dollar",
        "code": "USD",
        "sign": "$"
    },   
    {
        "id": 0,
        "name": "Euro",
        "code": "EUR",
        "sign": ""
    }
]

GET /currency/EUR - returns a specific currency.

The currency code is specified in the query address

Example of response:

{
    "id": 0,
    "name": "Euro",
    "code": "EUR",
    "sign": ""
}

POST /currencies - adding a new currency to the database.

The data is sent in the request body as form fields (x-www-form-urlencoded). The form fields are name, code, and sign.

Example of response: a JSON representation of the inserted record in the database, including its ID:

{
    "id": 0,
    "name": "Euro",
    "code": "EUR",
    "sign": ""
}

GET /exchangeRates - returns list of all exchange rates

Example of response:

[
    {
        "id": 0,
        "baseCurrency": {
            "id": 0,
            "name": "United States dollar",
            "code": "USD",
            "sign": "$"
        },
        "targetCurrency": {
            "id": 1,
            "name": "Euro",
            "code": "EUR",
            "sign": ""
        },
        "rate": 0.99
    }
]

GET /exchangeRate/USDRUB - returns a specific exchange rate.

The currency pair is specified by consecutive currency codes in the request URL Example of response:

{
    "id": 0,
    "baseCurrency": {
        "id": 0,
        "name": "United States dollar",
        "code": "USD",
        "sign": "$"
    },
    "targetCurrency": {
        "id": 1,
        "name": "Euro",
        "code": "EUR",
        "sign": ""
    },
    "rate": 0.99
}

POST /exchangeRates - adding a new exchange rate to the database.

The data is sent in the request body as form fields (x-www-form-urlencoded). The form fields are baseCurrencyCode, targetCurrencyCode, and rate.

Example form fields:

  • baseCurrencyCode - USD
  • targetCurrencyCode - EUR
  • rate - 0.99

Example of response: a JSON representation of the inserted record in the database, including its ID:

{
    "id": 0,
    "baseCurrency": {
        "id": 0,
        "name": "United States dollar",
        "code": "USD",
        "sign": "$"
    },
    "targetCurrency": {
        "id": 1,
        "name": "Euro",
        "code": "EUR",
        "sign": ""
    },
    "rate": 0.99
}

PATCH /exchangeRate/USDRUB - updating an existing exchange rate in the database.

The currency pair is specified by consecutive currency codes in the request URL. The data is sent in the request body as form fields (x-www-form-urlencoded).

The only form field is rate.

Example of response: a JSON representation of the inserted record in the database, including its ID:

{
    "id": 0,
    "baseCurrency": {
        "id": 0,
        "name": "United States dollar",
        "code": "USD",
        "sign": "$"
    },
    "targetCurrency": {
        "id": 1,
        "name": "Euro",
        "code": "EUR",
        "sign": ""
    },
    "rate": 0.99
}

GET /exchange?from=BASE_CURRENCY_CODE&to=TARGET_CURRENCY_CODE&amount=$AMOUNT - calculating the conversion of a specific amount of funds from one currency to another.

Example of request:

GET /exchange?from=USD&to=AUD&amount=10

Example of response:

{
    "baseCurrency": {
        "id": 0,
        "name": "United States dollar",
        "code": "USD",
        "sign": "$"
    },
    "targetCurrency": {
        "id": 1,
        "name": "Australian dollar",
        "code": "AUD",
        "sign": "A€"
    },
    "rate": 1.45,
    "amount": 10.00,
    "convertedAmount": 14.50
}

Obtaining the exchange rate for conversion can occur through one of three scenarios. Let's assume we're making a transfer from currency A to currency B:

  • There is a currency pair AB in the ExchangeRates table – we take its rate
  • There is a currency pair BA in the ExchangeRates table – we take its rate and calculate the inverse to obtain AB
  • There are currency pairs USD-A and USD-B in the ExchangeRates table – we calculate the rate for AB from these rates

👩‍💻Launching the application in IntelliJ IDEA

To run the application, make sure that you have Java (JDK), Apache Maven and Apache Tomcat installed on your computer.

  1. Go to the configurations menu

1  Открываем конфигуратор

  1. Select "Edit configurations"

2  Раскрываем конфигуратор

  1. Click the plus sign

3  Нажимаем плюс

  1. Select Tomcat -> Local

4  Выбираем томкат

  1. Select Tomcat as a Application server

5  Выбираем томкат2

  1. Click "Fix"

6  Нажимаем фикс

  1. Select CurrencyExchange:war exploded

7  Выбираем вар эксплодед

  1. Remove "CurrencyExchange_war_exploded" from the application context

8  Убираем лишнее

  1. Click "Run"

9  Run

Apache Maven will build the project and run it using Tomcat.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages