/currency_converter

Handling currency conversions with Elixir Phoenix.

Primary LanguageElixir

Currency Converter

Currency converter is a microservice dedicated to easily convert currencies given a value, using an external API.

Installation

To use this service you'll need Elixir, Phoenix e PostgreSql.

You may wanna use postgres from a docker container, for that, type the following command to create an up and running postgres container automatically for you docker-compose -f postgres-compose.yml up -d

  • Install dependencies by using mix deps.get
  • Setup your database structure by using mix ecto.setup
  • Initialize Phoenix locally by typing mix phx.server

Now you can visit localhost:4000 from your browser or api tool to access routes.

Tests

  • Run the tests using the command mix test

  • Check tests coverage with the command mix coveralls.html

API

To use this service, you might wanna first create an user with your name on it.

After successfully creating it, you'll want to copy your user_id to use it for currency conversions afterwards.

To convert you will have to provide your user_id, value to convert value, currencies origin and destiny currency_origin, currency_destiny.

Check the endpoints below in which you can accomplish this.

Routes

Create User

endpoint: /users/create

type: POST

Params

  • Name: name string

Body Params (JSON)

{
 "user": {
  "name": "Rick"
 }
}

Response

{
  "data": {
    "id": "259fd896-3d89-4765-9547-727f28bc8e19",
    "name": "Rick"
  }
}

Show user

endpoint: /users/show/{user_id}

type: GET

Response

{
  "data": {
    "id": "d45fdb57-744f-43c5-b342-25f5453573bb",
    "name": "Rick"
  }
}

List Users

endpoint: /users/list

type: GET

Response

"data": [
    {
      "id": "259fd896-3d89-4765-9547-727f28bc8e19",
      "name": "Rick"
    },
    {
      "id": "94f372b1-558e-426d-a23f-a6f3543783d1",
      "name": "Ana"
    }
  ]

Convert

endpoint: /currency/convert

type: POST

Params

  • Id of user created: user_id string

  • Value: value string|integer|decimal value does not matter because it's handled in the process.

  • Currency in which you wish to convert from: currency_origin

  • Currency in which you wish to have converted to: currency_destiny

Remember to use the id of the user created at endpoint /users/create.

Body Params (JSON)

{
  "user_id": "d45fdb57-744f-43c5-b342-25f5453573bb",
  "value": "100",
  "currency_origin": "BRL",
  "currency_destiny": "EUR"
}

Response

{
  "conversion_rate": 1.0,
  "currency_destiny": "EUR",
  "currency_origin": "BRL",
  "date": "2021-12-25T16:46:35",
  "message": "Converted Successfully!",
  "transaction_id": "763db094-1082-4b03-a6db-64b26060b6aa",
  "user_id": "d45fdb57-744f-43c5-b342-25f5453573bb",
  "value_converted": "643.5513000",
  "value_given": "100"
}

List Conversions

endpoint: /currency/list

type: GET

Response

{
  "data": [
    {
      "conversion_rate": 1.0,
      "currency_destiny": "EUR",
      "currency_origin": "BRL",
      "date": "2021-12-25T14:50:57",
      "transaction_id": "4383954d-b0e4-4690-93e1-0f9414e615b1",
      "value_converted": "643.5513000",
      "value_given": "100"
    },
    {
      "conversion_rate": 1.0,
      "currency_destiny": "EUR",
      "currency_origin": "BRL",
      "date": "2021-12-25T14:51:01",
      "transaction_id": "b20ceda1-cabf-47a7-962d-192d453050f8",
      "value_converted": "643.5513000",
      "value_given": "100"
    }
  ]
}