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
- Node 20.10
- Docker
- Make
- Windows
- Linux
sudo apt update sudo apt install make
Install project dependencies with:
npm run install
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
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
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.
We developed few endpoints which can be found in consumidores.controller.ts, produtos.controller.ts and pedidos.controller.ts files
- Cadastro do Cliente
POST {irango_host}/v1/consumidores
- Identificação do Cliente via CPF
GET {irango_host}/v1/consumidores/cpf
- Criar, editar e remover de produto
POST {irango_host}/v1/produtos
PUT {irango_host}/v1/produtos/:id
DELETE {irango_host}/v1/produtos/:id
- Buscar produtos por categoria
GET {irango_host}/v1/produtos/categorias/:termo
- Checkout
POST {irango_host}/v1/pedidos
- Verificar status do Pedido
GET {irango_host}/v1/pedidos/:id
- Atualizar status do pedido
PUT {irango_host}/v1/produtos/:id
- Webhook de Pagamento (Mercado Pago)
POST {irango_host}/v1/pedidos/pagamento-webhook/mercado-pago
- Listar os pedidos
GET {irango_host}/v1/pedidos
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
# With docker
docker-compose run service-irango-api npm run test
# local
npm run test
# With docker
docker-compose run service-irango-api npm run test:integration
# local
npm run test:integration
# With docker
docker-compose run service-irango-api npm run test:integration:one <FILE_NAME>
# local
npm run test:integration:one <FILE_NAME>
- 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