Code Monkey home page Code Monkey logo

fiap-irango-api's Introduction

iRango API

typescript Node 20.10 nestjs mysql redis docker swagger make jest eslint editorconfig typeorm

This project involves the development of an API for a fast food self-service system, proposed as a Tech Challenge for the Software Architecture Postgraduate Course at FIAP.

For this project, we utilized the TypeScript programming language with Node.js and the Nest.js framework. The database management includes MySQL 5.7 to handle information related to Consumidor, Produto, and Pedido. Additionally, an in-memory Redis database is employed for caching.

To build the API documentation, we've used Swagger tool integrated with Nest.js, accessible through the endpoint: {irango_host}/docs

Workspace Dependencies

Project Dependencies

Install project dependencies with:

npm run install

Start Project using Docker

Configure all docker containers and volumes and start the application

make setup

# or try without make

docker network create -d bridge local-network
cp .env.example .env
docker-compose build --progress=plain
docker-compose up
docker-compose exec -it service-irango-api npm run migration:run
docker-compose exec -it service-irango-api npm run seed:run

Start project using npm

Watch mode:

npm run start:dev

Compiled mode:

npm run build
npm run start

Migrations and Seeds:

npm run migration:run
npm run seed:run

How to Use

We developed a seed to populate database with some products and one Consumidor with CPF 123.456.789-00. You can use it or create a new Consumidor.

Endpoints

We developed few endpoints which can be found in consumidores.controller.ts, produtos.controller.ts and pedidos.controller.ts files

Business Requirements:

  1. Cadastro do Cliente

POST {irango_host}/v1/consumidores

  1. Identificação do Cliente via CPF

GET {irango_host}/v1/consumidores/cpf

  1. Criar, editar e remover de produto

POST {irango_host}/v1/produtos

PUT {irango_host}/v1/produtos/:id

DELETE {irango_host}/v1/produtos/:id

  1. Buscar produtos por categoria

GET {irango_host}/v1/produtos/categorias/:termo

  1. Checkout

POST {irango_host}/v1/pedidos

  1. Verificar status do Pedido

GET {irango_host}/v1/pedidos/:id

  1. Atualizar status do pedido

PUT {irango_host}/v1/produtos/:id

  1. Webhook de Pagamento (Mercado Pago)

POST {irango_host}/v1/pedidos/pagamento-webhook/mercado-pago

  1. Listar os pedidos

GET {irango_host}/v1/pedidos

Automated Tests

We developed integration tests which can be run using docker or in directly in local machine (in this case you need change the DB_HOSTNAME env to localhost). Before run the tests, we need to create the test database using:

make test.integration.createdb

# or try without make
docker exec -it ${CONTAINER_MYSQL} mysql -uroot -ppassword -e "DROP DATABASE IF EXISTS ${DATABASE}_test; CREATE DATABASE ${DATABASE}_test;"
docker-compose exec -it ${CONTAINER_BACKEND} npm run migration:run:test

Run all tests (We just have integrations for while)

# With docker
docker-compose run service-irango-api npm run test

# local
npm run test

Run only integration tests

# With docker
docker-compose run service-irango-api npm run test:integration

# local
npm run test:integration

Run a specifc test file

# With docker
docker-compose run service-irango-api npm run test:integration:one <FILE_NAME>

# local
npm run test:integration:one <FILE_NAME>

Make commands

Using Docker

  • Setup Project: make setup. This command will create docker network, containers and volumes. It will also start the project and show its logs.
  • Start Project: make up
  • Stop Projects: make down
  • Show logs: make logs
  • Add Migration: make migration.generate name=MigrationName
  • Run Migrations: make migration.run
  • Add Seed: make seed.generate name=SeedName
  • Run Seeds: make seed.run
  • Access container bash: make bash
  • Access Redis container: make redis

fiap-irango-api's People

Contributors

m4tob avatar ianoliv avatar heliodantas avatar

Watchers

 avatar  avatar  avatar

Forkers

ianoliv

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.