Patterns: Singleton, Strategy, Facade
Currency Conversion System and Calculation of the Total Price of a Product Based on the Selected Currency
- supported currencies: ARS, BRL, EUR, GBP, JPY, USD
- API Documentation
- API Registration : get key
clone
git clone git@github.com:bianavic/formacao-java-desafio-padrao-projeto.git
access
cd formacao-java-desafio-padrao-projeto
ps: before executing this project, make sure you configure your api key at application.properties file like the example above
execute
./gradlew bootrun
curl -X 'GET' \
'http://localhost:8282/latest/EUR' \
-H 'accept: */*'
Parameter | Type | Description |
---|---|---|
base_code |
String |
Required. Código da moeda |
ps: return all supported currencies from exchange rate api
{
"result":"success",
"documentation":"https://www.exchangerate-api.com/docs",
"terms_of_use":"https://www.exchangerate-api.com/terms",
"time_last_update_unix":1699142401,
"time_last_update_utc":"Sun, 05 Nov 2023 00:00:01 +0000",
"time_next_update_unix":1699228801,
"time_next_update_utc":"Mon, 06 Nov 2023 00:00:01 +0000",
"base_code":"EUR",
"conversion_rates":{
"EUR":1,
"AED":3.9287,
"AFN":78.3934,
"ALL":105.5830,
"AMD":427.5039,
"ANG":1.9149,
"AOA":894.1269,
"ARS":374.4460,
"AUD":1.6491,
"AWG":1.9149,
"AZN":1.8050,
"BAM":1.9558,
"BBD":2.1395,
}
}
curl -X 'GET' \
'http://localhost:8282/pair/BRL/USD' \
-H 'accept: */*'
Parameter | Type | Description |
---|---|---|
base_code |
String |
Required. Código da moeda |
target_code |
String |
Required. Código da moeda |
{"base_code":"BRL","target_code":"USD","conversion_rate":0.2024,"time_last_update_utc":"Sun, 05 Nov 2023 00:00:01 +0000"}
curl -X 'GET' \
'http://localhost:8282/pair/BRL/USD/1000' \
-H 'accept: */*'
Parameter | Type | Description |
---|---|---|
base_code |
String |
Required. Código da moeda |
target_code |
String |
Required. Código da moeda |
amount |
BigDecimal |
Required. Código da moeda |
{"base_code":"BRL","target_code":"USD","conversion_rate":0.2024,"conversion_result":202.4,"time_last_update_utc":"Sun, 05 Nov 2023 00:00:01 +0000"}
curl -X 'POST' \
'http://localhost:8282/products' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"name": "product 1",
"description": "product description 1",
"quantity": 1,
"price": 100,
"currency": "USD"
}'
Parameter | Type | Description |
---|---|---|
id |
Long |
NOT Required. product id |
name |
String |
Required. product name |
description |
String |
Required. product description |
quantity |
Integer |
Required. product quantity |
price |
BigDecimal |
Required. product price |
currency |
BigDecimal |
Required. product currency will not be converted here |
{
"id": 1,
"name": "product 1",
"description": "product description 1",
"quantity": 10,
"price": 100,
"currency": "USD"
}
curl -X 'GET' \
'http://localhost:8282/products' \
-H 'accept: */*'
[
{
"id": 1,
"name": "product 1",
"description": "product description 1",
"quantity": 10,
"price": 100,
"currency": "USD"
},
{
"id": 2,
"name": "product 2",
"description": "product description 2",
"quantity": 20,
"price": 200,
"currency": "ARS"
}
]
curl -X 'GET' \
'http://localhost:8282/products/2' \
-H 'accept: */*'
{
"id": 2,
"name": "product 2",
"description": "product description 2",
"quantity": 20,
"price": 200,
"currency": "ARS"
}
curl -X 'PUT' \
'http://localhost:8282/products/2' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-d '{
"id": 2,
"name": "update product 2",
"description": "description 2",
"quantity": 100,
"price": 99.99,
"currency": "USD"
}'
Parameter | Type | Description |
---|---|---|
id |
Long |
NOT Required. product id |
name |
String |
Required. product name |
description |
String |
Required. product description |
quantity |
Integer |
Required. product quantity |
price |
BigDecimal |
Required. product price |
currency |
BigDecimal |
Required. product currency will not be converted here |
{
"id": 2,
"name": "update product 2",
"description": "description 2",
"quantity": 100,
"price": 99.99,
"currency": "USD"
}
curl -X 'DELETE' \
'http://localhost:8282/products/2' \
-H 'accept: */*'
curl -X 'PUT' \
curl -X 'GET' \
'http://localhost:8282/products/1/totalPrice/BRL' \
-H 'accept: */*'
PathParameter | Type | Description |
---|---|---|
id |
Long |
Required. product id |
targetCurrency |
String |
Required. currency symbol |
4941.7
while running this application, you can test and visualize at: Documentação do Swagger