Skip to content

Repository files navigation

GitHub CI - Tests

FIAP Tech Challenge-1 - G20 Fast Food

Go Gin PostgreSQL Swagger Uber FX Docker

💬 About

Repository for the FIAP Tech Challenge 1, focused on developing a monolith backend system for managing orders in a fast-food restaurant.

Tech Challenge 1 specifications can be found here.

📚 Dictionary - Ubiquitous Language

  • Customer (actor): Actor responsible for initiating the purchasing process
  • Cook (actor): Actor responsible for preparing the customer's order
  • Attendant (actor): Actor responsible for interacting with the customer, providing support for the order
  • Identification method: Format in which the customer is identified on the platform: via CPF or anonymous.
  • Identification: Customer identification on the platform
  • Authorization: Grants permission to the customer to perform operations on the platform, such as placing an order, changing registration information
  • Order: Represents all items selected by the customer in the store
  • Order Status: Represents the stage of order preparation after payment is confirmed.

📊 Diagrams

Event Storming - Order & Payment

Event Storming - Order & Payment

Event Storming - Preparation & Delivery

Event Storming - Preparation & Delivery

Full Event Storming Board can be found here.

📦 Database

🗃️ Database Schema

Database Diagram

DBML file can be found here.

📂 Project Structure

.
├── bin
├── cmd
│   └── http
├── docs
└── internal
    ├── adapter
    │   ├── handler
    │   │   └── http
    │   ├── repository
    │       └── postgres
    │           └── migrations
    └── core
        ├── domain
        ├── port
        ├── service
        └── util

Project Structure Explanation
  • bin: directory to store compiled executable binary.
  • docs: directory to store project's documentation, such as swagger static files.
  • cmd: directory for main entry points or commands of the application. The http sub-directory holds the main HTTP server entry point.
  • internal: directory for containing application code that should not exposed to external packages.
  • core: directory that contains the central business logic of the application. Inside it there are 4 sub-directories.
  • domain: directory that contains domain models/entities representing core business concepts.
  • port: directory that contains defined interfaces or contracts that adapters must follow.
  • service: directory that contains the business logic or services of the application.
  • util: directory that contains utility functions that reused in the service package.
  • adapters: directory for containing external services that will interact with the core of application. There are 4 external services used in this application.
  • handler/http: directory that contains HTTP request and response handler.
  • repository/postgres: directory that contains database adapters for PostgreSQL.

🧐 Decisions

  1. Language: We chose Go as the programming language for its performance, simplicity, and concurrency features.
  2. Framework: We chose the Gin framework for its simplicity and performance.
  3. Database: We chose PostgreSQL as the database for its performance, scalability, and reliability.

✨ Features

  • Dockerfile: small image with multi-stage docker build, and independent of the host environment
  • Makefile: to simplify the build and run commands
  • Hexagonal architecture
  • PostgreSQL database
  • Conventional commits
  • Unit tests
  • Code coverage
  • Swagger documentation
  • Postman collection
  • Feature branch workflow
  • Air to run go
  • Pagination
  • Health Check
  • Lint
  • Vulnerability check

💻 Technologies

(back to top)

📜 Requirements

Build/Run with Docker

Build/Run Locally

Note

You need to have Go (> 1.18) installed in your machine to build, run and test the application locally

(back to top)

💿 Installation

git clone https://github.com/FIAP-SOAT-G20/FIAP-TechChallenge-Fase1.git
cd FIAP-TechChallenge-Fase1

[Optional] Set the environment variables

cp .env.example .env

Note

If you want to run the application locally, you need to set the environment variables in the .env file
If you want to run the application using Docker, you don't need to set the environment variables because they are already set in the .env.local file used by Docker Compose

🐳 Docker

make compose-build

The binary will be created in the bin folder

(back to top)

🏃 Running

🐳 Docker

make compose-run

Note

To stop the application, run compose-stop To remove the application, run compose-clean

(back to top)

🚀 Routes

sign-up

POST /api/v1/customers - Create a customer (2.b: i.Cadastro do Cliente)
POST /api/v1/staffs - Create a staff


products

2.b: iii. Criar, editar e remover produtos;

POST /api/v1/payments/callback - Update a payment on a order
POST /api/v1/payments/{order_id}/checkout - Create a checkout on a order
GET /api/v1/products - List products
POST /api/v1/products - Create a product
GET /api/v1/products/{id} - Get a product (2.b: iv. Buscar produtos por categoria;)
PUT /api/v1/products/{id} - Update a product
DELETE /api/v1/products/{id} - Delete a product


payments

2.b: v. Fake checkout

POST /api/v1/payments/callback - Update a payment on a order
POST /api/v1/payments/{order_id}/checkout - Create a checkout on a order


sign-in

2.b: ii. Identificação do Cliente via CPF

POST /api/v1/sign-in - Sign in a customer


categories

GET /api/v1/categories - List categories
POST /api/v1/categories - Create a new category
GET /api/v1/categories/{id} - Get a category
PUT /api/v1/categories/{id} - Update a category
DELETE /api/v1/categories/{id} - Delete a category


customers

GET /api/v1/customers - List customers
POST /api/v1/customers - Create a customer
GET /api/v1/customers/{id} - Get a customer
PUT /api/v1/customers/{id} - Update a customer
DELETE /api/v1/customers/{id} - Delete a customer


orders

GET /api/v1/orders - List orders (2.b: vi. Listar os pedidos.)
POST /api/v1/orders - Create an order
GET /api/v1/orders/products/{order_id}/{product_id} - Get an order product
PUT /api/v1/orders/products/{order_id}/{product_id} - Update an order product
POST /api/v1/orders/products/{order_id}/{product_id} - Create an order product
DELETE /api/v1/orders/products/{order_id}/{product_id} - Delete an order product
PUT /api/v1/orders/status/{id} - Update an order status
GET /api/v1/orders/{id} - Get an order
DELETE /api/v1/orders/{id} - Delete an order


order-histories

GET /api/v1/orders/histories - List order histories
GET /api/v1/orders/histories/{id} - Get an order history
GET /api/v1/orders/products - List order products


staffs

GET /api/v1/staffs - List staffs
POST /api/v1/staffs - Create a staff
GET /api/v1/staffs/{id} - Get a staff
PUT /api/v1/staffs/{id} - Update a staff
DELETE /api/v1/staffs/{id} - Delete a staff


healthcheck

GET /health - Application HealthCheck

Follows the Health Check Response Format for HTTP APIs


Note

You can check the application swagger documentation at http://localhost:8080/docs/index.html
Alternatively, a postman collection is available at here

(back to top)

🛠️ Development

  1. Install Go: https://golang.org/doc/install
  2. Clone this repository: git clone https://github.com/FIAP-SOAT-G20/FIAP-TechChallenge-Fase1
  3. Change to the project directory: cd FIAP-TechChallenge-Fase1
  4. Set the environment variables: cp .env.example .env
  5. Install dependencies by running make build
  6. Run the application by running make run-air or make run
  7. Access the application at http://localhost:8080
  8. Dont forget to run the tests by running make test
  9. Check the coverage report by running make coverage
  10. Check the lint by running make lint
  11. Update the swagger documentation by running make docs-swag

Note

make run will run the application locally, and will build and run PostgreSQL container using Docker Compose
Alternatively, you can run make run-air to run the application using Air (live reload)

(back to top)

✅ Tests

make test

Note

It will run the unit tests and generate the coverage report as coverage.out
You can check the coverage report by running make coverage

(back to top)

👏 Acknowledgments

(back to top)

👥 Contributors


Alice Tomaz


Filipe Leuch Bonfim


Hugo Kishi


Marcos Santos


Vitor Parras

(back to top)

About

FIAP Tech Challenge 1 - 10SOAT - G20 - Fast Food API - Golang Hexagonal Architecture

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages