Skip to content

Create an REST API integrated to an external API to study the application of some design patters

Notifications You must be signed in to change notification settings

bianavic/formacao-java-desafio-padrao-projeto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Formacao Java - Desafio Padrao de Projeto (tema livre)

Patterns: Singleton, Strategy, Facade

Exchange Rate Conversion

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

external api: get your api-key

How To

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

api key configuration

execute

./gradlew bootrun

Exchange Rate Endpoints

standard conversion

curl -X 'GET' \
  'http://localhost:8282/latest/EUR' \
  -H 'accept: */*'
Parameter Type Description
base_code String Required. Código da moeda
Resposta da requisição 200 OK

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,
 }
}

pair conversion

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
HttpResponse 200 OK
{"base_code":"BRL","target_code":"USD","conversion_rate":0.2024,"time_last_update_utc":"Sun, 05 Nov 2023 00:00:01 +0000"}

pair conversion base amount

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
HttpResponse 200 OK
{"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"}

Product Endpoints

add a product

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
HttpResponse 200 OK
{
  "id": 1,
  "name": "product 1",
  "description": "product description 1",
  "quantity": 10,
  "price": 100,
  "currency": "USD"
}

get all products

curl -X 'GET' \
  'http://localhost:8282/products' \
  -H 'accept: */*'
HttpResponse 200 OK
[
  {
    "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"
  }
]

get product by ID

curl -X 'GET' \
  'http://localhost:8282/products/2' \
  -H 'accept: */*'
HttpResponse 200 OK
{
  "id": 2,
  "name": "product 2",
  "description": "product description 2",
  "quantity": 20,
  "price": 200,
  "currency": "ARS"
}

update product by ID

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
HttpResponse 200 OK
{
  "id": 2,
  "name": "update product 2",
  "description": "description 2",
  "quantity": 100,
  "price": 99.99,
  "currency": "USD"
}

delete product by ID

curl -X 'DELETE' \
  'http://localhost:8282/products/2' \
  -H 'accept: */*'
HttpResponse 200 OK

convert total product price to supported currency

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
HttpResponse 200 OK
4941.7

swagger documentation

while running this application, you can test and visualize at: Documentação do Swagger

About

Create an REST API integrated to an external API to study the application of some design patters

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages