This project involves the development of a RESTful API (Representational State Transfer) that offers CRUD (Create, Read, Update, Delete) operations to manage user-related, category, and transaction information. PostgreSQL is used as the database, with a defined structure of tables and columns for data storage.
- Cadastrar Usuário
- Fazer Login
- Detalhar Perfil do Usuário Logado
- Editar Perfil do Usuário Logado
- Listar categorias
- Listar transações
- Detalhar transação
- Cadastrar transação
- Editar transação
- Remover transação
- Obter extrato de transações
- Filtrar transações por categoria
To clone the repository, you will need to have Git installed on your machine. Additionally, to run the server and interact with the PostgreSQL database, you will need to have Node.js and PostgreSQL installed.
- Clone the project and navigate to the directory
git clone git@github.com:jhonatavbrg/project-api-restful-crud-postgresql.git && cd project-api-restful-crud-postgresql- Install project dependencies
npm i- Supported Methods
GET,POST,PUTandDELETE - For requests that use methods other than
GET, such asPOST,PUT, andDELETE, it will be necessary to use a client tool like Insomnia, Postman, or any other of your choice - You will need to set up the .env file. Inside the project, there is a file called .env.example, where all the environment variables for the project are listed. In the .env file, you should configure all the variables for both the database, such as user, password, port, and host, and for the project, such as the JWT password to generate the token for the user and also the port where the server will run. It's very important that you configure everything with great care because each credential is unique, so you cannot set them with default values. If you configure something incorrectly, it will result in an error.
- Inside the
src/databasefolder, there is a file nameddatabase.sql. You should open it with an SQL editor such as Beekeeper Studio, DBeaver, or any other of your choice. After opening it, execute the queries within this file. These queries will create a database nameddindinand the respective tables that were modeled specifically for this project. Remember that after executing the first query to create a database, you need to select it before creating the tables, as SQL editors do not automatically select. If you do not select the created database, the tables will be created in the current database you are connected to, causing issues when interacting with the project's routes. - Inside the project directory, run the command
npm run dev- After that, the server will be running the API, and you can configure your routes in Insomnia, Postman, or any other client of your choice. The routes to be configured are as follows: (Remember to change the port)
// POST /usuario
{
"nome": "José",
"email": "jose@email.com",
"senha": "123456"
}// HTTP Status 201
{
"id": 1,
"nome": "José",
"email": "jose@email.com"
}// HTTP Status 409
{
"mensagem": "Já existe usuário cadastrado com o e-mail informado."
}// POST /login
{
"email": "jose@email.com",
"senha": "123456"
}// HTTP Status 200 / 201 / 204
{
"usuario": {
"id": 1,
"nome": "José",
"email": "jose@email.com"
},
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MiwiaWF0IjoxNjIzMjQ5NjIxLCJleHAiOjE2MjMyNzg0MjF9.KLR9t7m_JQJfpuRv9_8H2-XJ92TSjKhGPxJXVfX6wBI"
}// HTTP Status 400
{
"mensagem": "Usuário e/ou senha inválido(s)."
}ATTENTION: Starting from this route, all functionalities (endpoints) require an authentication token. This token is generated after logging in with your previously registered account. In both programs (Insomnia and Postman), there is a specific place where you can put this token. It is a Bearer token and is placed in the request header. Its duration is 8 hours; after that, it is necessary to log in again to generate another token.
// GET /usuario
// No content in the request body// HTTP Status 200
{
"id": 1,
"nome": "José",
"email": "jose@email.com"
}// HTTP Status 401
{
"mensagem": "Para acessar este recurso um token de autenticação válido deve ser enviado."
}// PUT /usuario
{
"nome": "José de Abreu",
"email": "jose_abreu@email.com",
"senha": "j4321"
}// HTTP Status 204
// No content in the response body// HTTP Status 409
{
"mensagem": "O e-mail informado já está sendo utilizado por outro usuário."
}// GET /categoria
// No content in the request body// HTTP Status 200
[
{
id: 1,
descricao: "Roupas",
},
{
id: 2,
descricao: "Mercado",
},
...
];// HTTP Status 200
[];// GET /transacao
// No content in the request body// 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",
},
];// HTTP Status 200
[];// GET /transacao/2
// No content in the request body// 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",
}// HTTP Status 404
{
"mensagem": "Transação não encontrada."
}// POST /transacao
{
"tipo": "entrada",
"descricao": "Salário",
"valor": 300000,
"data": "2022-03-24T15:30:00.000Z",
"categoria_id": 6
}// 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",
}// HTTP Status 400
{
"mensagem": "Todos os campos obrigatórios devem ser informados."
}// PUT /transacao/2
{
"descricao": "Sapato amarelo",
"valor": 15800,
"data": "2022-03-23 12:35:00",
"categoria_id": 4,
"tipo": "saida"
}// HTTP Status 204
// No content in the response body// HTTP Status 400
{
"mensagem": "Todos os campos obrigatórios devem ser informados."
}// DELETE /transacao/2
// No content in the request body// HTTP Status 204
// No content in the response body// HTTP Status 404
{
"mensagem": "Transação não encontrada."
}// GET /transacao/extrato
// No content in the request body// HTTP Status 200
{
"entrada": 300000,
"saida": 15800
}// GET /transacao?filtro[]=roupas&filtro[]=salários
// No content in the request body// 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",
},
...
];// HTTP Status 200
[];- If you encounter any issues (bugs) or have suggestions for improving this project, please feel free to report them on the Issue-tracker

