henriquebarrosx / currency-converter

Home Page:currency-converter-six-omega.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Currency Converter

API for converting between BRL, USD, EUR, JPY currencies.


⚒️ Resources


🏃‍♂️ Running

Setup

  1. Setup a postgres database url in .env file DATABASE_URL, exemple:
API_KEY=123456990120310912031            # Visit https://apilayer.com and put your API key here
DATABASE_URL="postgresql://<DATABASE_USER>:<DATABASE_PASS>@localhost:5432/currency_converter_db"

OBS: If you don't have Postgres in your machine but have docker compose, just run docker-compose up to instantiate a postgres image

  1. Run Prisma migrations and Prisma Client setup
npm run prisma:migrate
npm run prisma:generate
  1. Run the project
npm run dev

Try to use the currency conversion doc


🍀 Features

  • Create transactions to convert currencies
  # /api/v1/transactions

  curl -X POST http://localhost:3333/api/v1/transactions \
       -H 'Content-Type: application/json' \
       -d '{ "from": "BRL", "to": "USD", "amount": 5 }'
  • List registered transactions
  # /api/v1/transactions

  curl -X GET http://localhost:3333/api/v1/transactions \
       -H 'Content-Type: application/json'

📦 Folder structure

📦 currency-converter
 ┣ 📂 prisma
 ┣ 📂 src
 ┃ ┣ 📂 common-types
 ┃ ┣ 📂 exception
 ┃ ┣ 📂 providers
 ┃ ┃ ┃ ┣ 📂 database
 ┃ ┃ ┃ ┣ 📂 http-client
 ┃ ┣ 📂 v1
 ┃ ┃ ┣ 📂 entities
 ┃ ┃ ┣ 📂 middlewares
 ┃ ┃ ┣ 📂 repositories
 ┃ ┃ ┣ 📂 use-cases
 ┃ ┃ ┃ ┣ 📂 create-transaction
 ┃ ┃ ┃ ┣ 📂 list-transaction
 ┃ ┣ 📜 routes
 ┃ ┣ 📜 index.ts
 ┣ 📜 .gitignore
 ┣ 📜 docker-compose.yml
 ┣ 📜 README.md
 ┣ 📜 LICENSE
 ┣ 📜 package-lock.json
 ┣ 📜 package.json
 ┣ 📜 tsconfig.json


🎯 Tools Motivation

Thinking about a simple project, easy to test and with high capacity to improvements, the API was built using the clean architecture principles. It came up with pros and cons, like tools limitation that could work togheter respecting these principles. Prisma and axios are one of those! Prisma combined the ability to work with repositories without dirt things in our entities and low accoplament, for example. Axios, on the other hand, provided a way to handle with http client to handle with requests.


👦 Developer


Henrique Barros

About

currency-converter-six-omega.vercel.app

License:MIT License


Languages

Language:TypeScript 98.0%Language:JavaScript 2.0%