/dindin

A Rest API for personal finance management. A challenge proposed by @Cubos-Academy.

Primary LanguageJavaScriptMIT LicenseMIT

Dindin

GitHub language count Repository size GitHub last commit License

πŸ’» About the Project

A Rest API for personal finance management, that allows users to track their expenses and incomes in a simple and secure way. With Dindin, users can have an overview of their financial situation, set goals and plan for the future. This project, part of a challenge proposed by Cubos Academy.


πŸ›£οΈ How to Run the Project

Follow these instructions to run the project in your local environment.

πŸš€ Pre-requisites

  • You'll need Git and Node.js installed on your computer to build this app.
  • Use Insomnia or Postman to perform the API requests.
  • Additionally, having an editor like VSCode for coding is quite advantageous.

🎲 Building

# Clone the project and access the folder
$ git clone https://github.com/hamomgs/dindin.git
$ cd dindin

# Install the dependencies
$ npm install

# Make a copy of file '.env.example' to '.env'
$ cp .env.example .env

# Acess the .env
$ code .env

# Fill it with your port, database and jwt config.
PORT=3000

# JWT Config
JWT_PASS=YourPassword

# Database Config
DB_HOST=YourDbHost
DB_PORT=YourDbPort
DB_USER=YourDbUser
DB_PASS=YourDbPassword
DB_NAME=YourDbName

Run the application in development mode.

$ npm run dev

# The application will be accessible on port:3000 by default via http://localhost:3000.

Import on Insomnia or Postman the request collection.

Run in Insomnia


πŸ“š API Reference

Base URL

http://localhost:3000/

🧩 Endpoits

User

Create user | POST /usuario

Param Type Origin Description
nome string Body Required. User name.
email string Body Required. User email.
senha string Body Required. User password.
// Example Response
// HTTP Status 201 
{
  "id": 1,
  "nome": "JosΓ©",
  "email": "jose@email.com"
}

User login | POST /login

Param Type Origin Description
email string Body Required. User email.
senha string Body Required. User password.
// Example Response
// HTTP Status 200
{
  "usuario": {
    "id": 1,
    "nome": "JosΓ©",
    "email": "jose@email.com"
  },
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwiaWF0IjoxNjIzMjQ5NjIxLCJleHAiOjE2MjMyNzg0MjF9.KLR9t7m_JQJfpuRv9_8H2-XJ92TSjKhGPxJXVfX6wBI"
}

Get logged user details | GET /usuario

Param Type Origin Description
token Beater Authentication Required. Token returned to the user after logging in.
// Example Response
// HTTP Status 200
{
  "id": 1,
  "nome": "JosΓ©",
  "email": "jose@email.com"
}

Edit user profile | PUT /usuario

Param Type Origin Description
token Beater Authentication Required. Token returned to the user after logging in.
nome string Body Required. User name.
email string Body Required. User email.
senha string Body Required. User password.
// Example Response
// HTTP Status 204
// No body response.

Category

List all categories | GET /categoria

Param Type Origin Description
token Beater Authentication Required. Token returned to the user after logging in.
// Example Response
// HTTP Status 200
[
  {
    "id": 1,
    "descricao": "Roupas"
  },
  {
    "id": 2,
    "descricao": "Mercado"
  }
]

Transaction

List all transactions | GET /transacao

Param Type Origin Description
token Beater Authentication Required. Token returned to the user after logging in.
// Example Response
// HTTP Status 200
[
  {
    "id": 1,
    "tipo": "saida",
    "descricao": "Sapato amarelo",
    "valor": 15800,
    "data": "2023-03-23T15:35:00.000Z",
    "usuario_id": 5,
    "categoria_id": 4,
    "categoria_nome": "Roupas"
  },
  {
    "id": 3,
    "tipo": "entrada",
    "descricao": "SalΓ‘rio",
    "valor": 300000,
    "data": "2023-03-24T15:30:00.000Z",
    "usuario_id": 5,
    "categoria_id": 6,
    "categoria_nome": "SalΓ‘rios"
  }
]

List all filtered transactions | GET /transacao?filtro[]=categoria1&filtro[]=categoria2

Param Type Origin Description
token Beater Authentication Required. Token returned to the user after logging in.
filtro[] array Query Optional. Category name.
// Example Response | GET /transacao?filtro[]=roupas&filtro[]=salΓ‘rios
// HTTP Status 200
[
  {
    "id": 1,
    "tipo": "saida",
    "descricao": "Sapato amarelo",
    "valor": 15800,
    "data": "2022-03-23T15:35:00.000Z",
    "usuario_id": 5,
    "categoria_id": 4,
    "categoria_nome": "Roupas"
  },
  {
    "id": 3,
    "tipo": "entrada",
    "descricao": "SalΓ‘rio",
    "valor": 300000,
    "data": "2022-03-24T15:30:00.000Z",
    "usuario_id": 5,
    "categoria_id": 6,
    "categoria_nome": "SalΓ‘rios"
  }
]

Get transaction details by id | GET /transacao/:id

Param Type Origin Description
token Beater Authentication Required. Token returned to the user after logging in.
id number Parameter Required. Transaction id.
// Example Response
// HTTP Status 200
{
  "id": 3,
  "tipo": "entrada",
  "descricao": "SalΓ‘rio",
  "valor": 300000,
  "data": "2022-03-24T15:30:00.000Z",
  "usuario_id": 5,
  "categoria_id": 6,
  "categoria_nome": "SalΓ‘rios"
}

Create transaction | POST /transacao

Param Type Origin Description
token Beater Authentication Required. Token returned to the user after logging in.
tipo string Body Required. Transaction type. entrada or saida.
descricao string Body Required. Transaction description.
valor number Body Required. Transaction value.
data timestamp Body Required. Transaction date.
categoria_id number Body Required. Category id.
// Example Response
// HTTP Status 204
{
  "id": 3,
  "tipo": "entrada",
  "descricao": "SalΓ‘rio",
  "valor": 300000,
  "data": "2022-03-24T15:30:00.000Z",
  "usuario_id": 5,
  "categoria_id": 6,
  "categoria_nome": "SalΓ‘rios"
}

Edit specific transacion | PUT /transacao/:id

Param Type Origin Description
token Beater Authentication Required. Token returned to the user after logging in.
id string Parameter Required. Transaction id.
tipo string Body Required. Transaction type. entrada or saida.
descricao string Body Required. Transaction description.
valor number Body Required. Transaction value.
data timestamp Body Required. Transaction date.
categoria_id number Body Required. Category id.
// Example Response
// HTTP Status 204
// No body response.

Remove transaction | DELETE /transacao/:id

Param Type Origin Description
token Beater Authentication Required. Token returned to the user after logging in.
id string Parameter Required. Transaction id.
// Example Response
// HTTP Status 204
// No body response.

Get transaction statement | GET /transacao/extrato

Param Type Origin Description
token Beater Authentication Required. Token returned to the user after logging in.
// Example Response
// HTTP Status 200
{
	"entrada": 300000,
	"saida": 15800
}

πŸ—ƒοΈ Database Schema Diagram

database schema diagram

πŸ“‚ Directory Structure

dindin/
β”œβ”€β”€ node_modules
β”œβ”€β”€ sql
β”‚   β”œβ”€β”€ schema
β”‚   β”‚   └── 1.sql
β”‚   └── db-schema-diagram.png
β”œβ”€β”€ src
β”‚   β”œβ”€β”€ controllers
β”‚   β”‚   β”œβ”€β”€ categoryController.js
β”‚   β”‚   β”œβ”€β”€ transactionController.js
β”‚   β”‚   └── userController.js
β”‚   β”œβ”€β”€ middlewares
β”‚   β”‚   └── userAuth.js
β”‚   β”œβ”€β”€ routes
β”‚   β”‚   β”œβ”€β”€ categoryRouter.js
β”‚   β”‚   β”œβ”€β”€ index.js
β”‚   β”‚   β”œβ”€β”€ loginRouter.js
β”‚   β”‚   β”œβ”€β”€ transactionRouter.js
β”‚   β”‚   └── userRouter.js
β”‚   β”œβ”€β”€ services
β”‚   β”‚   β”œβ”€β”€ database.js
β”‚   β”‚   └── jwt.js
β”‚   β”œβ”€β”€ validations
β”‚   β”‚   └── index.js
β”‚   └── index.js   
β”œβ”€β”€ .env
β”œβ”€β”€ .eslintrc.json           
β”œβ”€β”€ .gitignore       
β”œβ”€β”€ .prettierrc 
β”œβ”€β”€ LICENCE
β”œβ”€β”€ package-lock.json 
β”œβ”€β”€ package.json
└── README.md

πŸ›  Technologies

Tech Version
Node.js 4.18.2
Express.js 4.18.2
Nodemon 3.0.1
Pg 8.11.3
Dotenv 16.3.1
Json Web Token 9.0.2
Bcrypt 5.1.1
Eslint 8.49.0
Prettier 3.0.3

πŸ“ License

This project is under the license MIT.

πŸ§‘β€πŸ’» Authors


Gabriel ApolinΓ‘rio

πŸ‘¨β€πŸ’»

Hamom Silva

πŸ‘¨β€πŸ’»