Application allows to:
- create bank accounts with sub-accounts in PLN and USD;
- enables the exchange in pair: PLN <-> USD at the current exchange rate taken from public NBP API;
- change in the balances on sub-accounts after the currency exchange.
Validated data: user data and his personal ID (PESEL), user age, initial amount, exchange currencies codes, exchange amounts, available funds.
The application downloads the data of current exchange rates from the public NBP API (https://api.nbp.pl/)
Application code: JAVA 17
- IntelliJ IDEA 2022.1.3 (Community Edition)
- Spring Boot v2.7.1
- Hibernate v6.2.3
- Maven v3.8.6
- Lombok v1.18.24
- H2 Database
Import the project as a maven application to your favorite IDE.
Run the app in IDE as 'Java application'
The REST API to the example app is described below:
POST /api/accounts/
curl --location --request POST 'localhost:8080/api/accounts' \
--header 'Content-Type: application/json' \
--data-raw '{
"name": "Adam",
"surname": "Test",
"pesel": "02070803628",
"amountPln": 1000
}'
HTTP/1.1 201 Created
Status: 201 Created
Content-Type: application/json
Location: /api/accounts/02070803628
{
"id": 1,
"name": "Adam",
"surname": "Test",
"pesel": "02070803628",
"subaccountList": [
{
"id": 2,
"currencyCode": "PLN",
"balance": 1000
},
{
"id": 3,
"currencyCode": "USD",
"balance": 0
}
]
}
POST /api/exchange/
curl --location --request POST 'localhost:8080/api/exchange/' \
--header 'Content-Type: application/json' \
--data-raw '{
"pesel": "02070803628",
"amountToExchange": 600,
"fromCurrency": "PLN",
"toCurrency": "USD"
}'
HTTP/1.1 200 OK
Status: 200 OK
Content-Type: application/json
{
"success": true,
"amountToExchange": 600,
"fromCurrency": "PLN",
"toCurrency": "USD",
"rate": 0.2197,
"result": 131.82
}
POST /api/exchange/
curl --location --request POST 'localhost:8080/api/exchange/' \
--header 'Content-Type: application/json' \
--data-raw '{
"pesel": "02070803628",
"amountToExchange": 100.00,
"fromCurrency": "PLN",
"toCurrency": "USD"
}'
HTTP/1.1 200 OK
Status: 200 OK
Content-Type: application/json
{
"success": true,
"amountToExchange": 100.00,
"fromCurrency": "USD",
"toCurrency": "PLN",
"rate": 4.4622,
"result": 446.22
}
GET /api/accounts/{pesel}
curl --location --request GET 'localhost:8080/api/accounts/02070803628'
HTTP/1.1 200 OK
Status: 200 OK
Content-Type: application/json
{
"id": 1,
"name": "Adam",
"surname": "Test",
"pesel": "02070803628",
"subaccountList": [
{
"id": 2,
"currencyCode": "PLN",
"balance": 846.22
},
{
"id": 3,
"currencyCode": "USD",
"balance": 31.82
}
]
}