{ "swagger": "2.0", "info": { "description": "Esta é uma API para gerenciamento de finanças pessoais.", "title": "API do Sistema Financeiro", "contact": {}, "version": "1.0" }, "host": "localhost:8080", "basePath": "/v1", "paths": { "/accounts": { "get": { "security": [ { "BearerAuth": [] } ], "description": "Returns an array with all of the logged-in user's accounts", "produces": [ "application/json" ], "tags": [ "accounts" ], "summary": "List all user accounts", "responses": { "200": { "description": "OK", "schema": { "type": "array", "items": { "$ref": "#/definitions/dto.AccountResponse" } } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } }, "post": { "security": [ { "BearerAuth": [] } ], "description": "Adds a new financial account to the logged-in user's system", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "accounts" ], "summary": "Create a new account", "parameters": [ { "description": "Account Data for Creation", "name": "account", "in": "body", "required": true, "schema": { "$ref": "#/definitions/dto.AccountRequest" } } ], "responses": { "201": { "description": "Created", "schema": { "$ref": "#/definitions/dto.AccountResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } } }, "/accounts/{id}": { "get": { "security": [ { "BearerAuth": [] } ], "description": "Returns the details of a single account belonging to the logged-in user", "produces": [ "application/json" ], "tags": [ "accounts" ], "summary": "Get an account by ID", "parameters": [ { "type": "integer", "description": "Account Id", "name": "id", "in": "path", "required": true } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/dto.AccountResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "404": { "description": "Not Found", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } }, "put": { "security": [ { "BearerAuth": [] } ], "description": "Updates the details of an existing account", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "accounts" ], "summary": "Update an account", "parameters": [ { "type": "integer", "description": "Account ID", "name": "id", "in": "path", "required": true }, { "description": "Data for Update", "name": "account", "in": "body", "required": true, "schema": { "$ref": "#/definitions/dto.AccountRequest" } } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/dto.AccountResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "404": { "description": "Not Found", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } }, "delete": { "security": [ { "BearerAuth": [] } ], "description": "Removes an account from the system. It will fail if the account has associated transactions.", "tags": [ "accounts" ], "summary": "Delete an account", "parameters": [ { "type": "integer", "description": "Account ID", "name": "id", "in": "path", "required": true } ], "responses": { "204": { "description": "No Content" }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "404": { "description": "Not Found", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "409": { "description": "Conflict", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } } }, "/accounts/{id}/statement": { "get": { "security": [ { "BearerAuth": [] } ], "description": "Retrieves all transactions and balance details for a specific credit card billing cycle. Defaults to the current statement if month/year are not provided.", "produces": [ "application/json" ], "tags": [ "accounts" ], "summary": "Get a credit card statement", "parameters": [ { "type": "integer", "description": "Account Id", "name": "id", "in": "path", "required": true }, { "type": "integer", "description": "The month of the statement's due date (1-12)", "name": "month", "in": "query" }, { "type": "integer", "description": "The year of the statement's due date (e.g., 2025)", "name": "year", "in": "query" } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/dto.StatementResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "404": { "description": "Not Found", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } } }, "/auth/login": { "post": { "description": "Autentica o usuário e retorna um token JWT", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "auth" ], "summary": "Realiza o login do usuário", "parameters": [ { "description": "Credenciais de Login", "name": "credentials", "in": "body", "required": true, "schema": { "$ref": "#/definitions/dto.LoginRequest" } } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/dto.LoginResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } } }, "/budgets": { "get": { "security": [ { "BearerAuth": [] } ], "description": "Retrieves all budgets for the user for a specific month and year. Defaults to the current month/year.", "produces": [ "application/json" ], "tags": [ "budgets" ], "summary": "Lists budgets for a given period", "parameters": [ { "type": "integer", "description": "Month to filter (1-12)", "name": "month", "in": "query" }, { "type": "integer", "description": "Year to filter (e.g., 2025)", "name": "year", "in": "query" } ], "responses": { "200": { "description": "OK", "schema": { "type": "array", "items": { "$ref": "#/definitions/dto.BudgetResponse" } } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } }, "post": { "security": [ { "BearerAuth": [] } ], "description": "Adds a new monthly budget for a specific category.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "budgets" ], "summary": "Creates a new budget", "parameters": [ { "description": "Budget Creation Data", "name": "budget", "in": "body", "required": true, "schema": { "$ref": "#/definitions/dto.CreateBudgetRequest" } } ], "responses": { "201": { "description": "Created", "schema": { "$ref": "#/definitions/dto.BudgetResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "409": { "description": "Conflict", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } } }, "/budgets/{id}": { "put": { "security": [ { "BearerAuth": [] } ], "description": "Changes the amount for an existing budget.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "budgets" ], "summary": "Updates a budget's amount", "parameters": [ { "type": "integer", "description": "Budget Id", "name": "id", "in": "path", "required": true }, { "description": "New Budget Amount", "name": "budget", "in": "body", "required": true, "schema": { "$ref": "#/definitions/dto.UpdateBudgetRequest" } } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/dto.BudgetResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "404": { "description": "Not Found", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } }, "delete": { "security": [ { "BearerAuth": [] } ], "description": "Removes a budget for a specific category and period.", "tags": [ "budgets" ], "summary": "Deletes a budget", "parameters": [ { "type": "integer", "description": "Budget Id", "name": "id", "in": "path", "required": true } ], "responses": { "204": { "description": "No Content" }, "404": { "description": "Not Found", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } } }, "/categories": { "get": { "security": [ { "BearerAuth": [] } ], "description": "Retorna um array com todas as categorias do usuário logado", "produces": [ "application/json" ], "tags": [ "categories" ], "summary": "Lista todas as categorias do usuário", "responses": { "200": { "description": "OK", "schema": { "type": "array", "items": { "$ref": "#/definitions/dto.CategoryResponse" } } } } }, "post": { "security": [ { "BearerAuth": [] } ], "description": "Adiciona uma nova categoria financeira ao sistema", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "categories" ], "summary": "Cria uma nova categoria", "parameters": [ { "description": "Dados da Conta", "name": "account", "in": "body", "required": true, "schema": { "$ref": "#/definitions/dto.CategoryRequest" } } ], "responses": { "201": { "description": "Created", "schema": { "$ref": "#/definitions/dto.CategoryResponse" } } } } }, "/categories/{id}": { "get": { "security": [ { "BearerAuth": [] } ], "description": "Retorna os detalhes de uma única categoria", "produces": [ "application/json" ], "tags": [ "categories" ], "summary": "Busca uma categoria pelo ID", "parameters": [ { "type": "integer", "description": "Id da Conta", "name": "id", "in": "path", "required": true } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/dto.CategoryResponse" } } } }, "put": { "security": [ { "BearerAuth": [] } ], "description": "Atualiza os detalhes de uma categoria existente", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "categories" ], "summary": "Atualiza uma categoria", "parameters": [ { "type": "integer", "description": "Id da Conta", "name": "id", "in": "path", "required": true }, { "description": "Dados para Atualizar", "name": "account", "in": "body", "required": true, "schema": { "$ref": "#/definitions/dto.CategoryResponse" } } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/dto.CategoryResponse" } } } }, "delete": { "security": [ { "BearerAuth": [] } ], "description": "Remove uma categoria do sistema", "tags": [ "categories" ], "summary": "Deleta uma categoria", "parameters": [ { "type": "integer", "description": "Id da Conta", "name": "id", "in": "path", "required": true } ], "responses": { "204": { "description": "No Content" } } } }, "/transactions": { "get": { "security": [ { "BearerAuth": [] } ], "description": "Retrieves a list of transactions for the authenticated user, with optional filters.", "produces": [ "application/json" ], "tags": [ "transactions" ], "summary": "Lists and filters user transactions", "parameters": [ { "type": "string", "description": "Search text in description (case-insensitive)", "name": "description", "in": "query" }, { "enum": [ "income", "expense", "transfer" ], "type": "string", "description": "Filter by type (income, expense, transfer)", "name": "type", "in": "query" }, { "type": "integer", "description": "Filter by a specific account Id", "name": "account_id", "in": "query" }, { "type": "string", "description": "Filter by start date (format: YYYY-MM-DD)", "name": "start_date", "in": "query" }, { "type": "string", "description": "Filter by end date (format: YYYY-MM-DD)", "name": "end_date", "in": "query" }, { "type": "string", "description": "Filter by one or more category Ids (comma-separated, e.g., 1,5,8)", "name": "category_ids", "in": "query" } ], "responses": { "200": { "description": "OK", "schema": { "type": "array", "items": { "$ref": "#/definitions/dto.TransactionResponse" } } } } }, "post": { "security": [ { "BearerAuth": [] } ], "description": "Adiciona uma nova transação ao sistema. Para transferências, o campo destination_account_id é obrigatório.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "transactions" ], "summary": "Cria uma nova transação", "parameters": [ { "description": "Dados da Transação para Criar", "name": "transaction", "in": "body", "required": true, "schema": { "$ref": "#/definitions/dto.CreateTransactionRequest" } } ], "responses": { "201": { "description": "Created", "schema": { "$ref": "#/definitions/dto.TransactionResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } } }, "/transactions/{id}": { "get": { "security": [ { "BearerAuth": [] } ], "description": "Retorna os detalhes de uma única transação", "produces": [ "application/json" ], "tags": [ "transactions" ], "summary": "Busca uma transação pelo Id", "parameters": [ { "type": "integer", "description": "Id da Transação", "name": "id", "in": "path", "required": true } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/dto.TransactionResponse" } }, "404": { "description": "Not Found", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } }, "put": { "security": [ { "BearerAuth": [] } ], "description": "Atualiza os detalhes de uma transação com base no seu Id", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "transactions" ], "summary": "Atualiza uma transação existente", "parameters": [ { "type": "integer", "description": "Id da Transação", "name": "id", "in": "path", "required": true }, { "description": "Dados para Atualizar", "name": "transaction", "in": "body", "required": true, "schema": { "$ref": "#/definitions/dto.UpdateTransactionRequest" } } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/dto.TransactionResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "404": { "description": "Not Found", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } }, "delete": { "security": [ { "BearerAuth": [] } ], "description": "Remove uma transação do sistema pelo seu Id", "tags": [ "transactions" ], "summary": "Deleta uma transação", "parameters": [ { "type": "integer", "description": "Id da Transação", "name": "id", "in": "path", "required": true } ], "responses": { "204": { "description": "No Content" }, "404": { "description": "Not Found", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } }, "patch": { "security": [ { "BearerAuth": [] } ], "description": "Atualiza um ou mais campos de uma transação. Apenas os campos fornecidos no corpo serão alterados.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "transactions" ], "summary": "Atualiza uma transação parcialmente", "parameters": [ { "type": "integer", "description": "Transaction Id", "name": "id", "in": "path", "required": true }, { "description": "Fields to Update", "name": "transaction", "in": "body", "required": true, "schema": { "$ref": "#/definitions/dto.PatchTransactionRequest" } } ], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/dto.TransactionResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "404": { "description": "Not Found", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } } }, "/users": { "post": { "description": "Cria um novo usuário no sistema.", "consumes": [ "application/json" ], "produces": [ "application/json" ], "tags": [ "users" ], "summary": "Registra um novo usuário", "parameters": [ { "description": "Dados do Usuário para Registro", "name": "user", "in": "body", "required": true, "schema": { "$ref": "#/definitions/dto.CreateUserRequest" } } ], "responses": { "201": { "description": "Created", "schema": { "$ref": "#/definitions/dto.UserResponse" } }, "400": { "description": "Bad Request", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "500": { "description": "Internal Server Error", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } } }, "/users/me": { "get": { "security": [ { "BearerAuth": [] } ], "description": "Retorna os dados do usuário que está fazendo a requisição.", "produces": [ "application/json" ], "tags": [ "users" ], "summary": "Busca o perfil do usuário logado", "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/dto.UserResponse" } }, "401": { "description": "Unauthorized", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } }, "404": { "description": "Not Found", "schema": { "$ref": "#/definitions/dto.ErrorResponse" } } } } } }, "definitions": { "dto.AccountRequest": { "type": "object", "required": [ "initial_balance", "name", "type" ], "properties": { "credit_limit": { "type": "number", "example": 5000 }, "initial_balance": { "type": "number", "example": 1000.5 }, "name": { "type": "string", "maxLength": 100, "minLength": 2, "example": "Nubank Account" }, "payment_due_day": { "type": "integer", "example": 5 }, "statement_closing_day": { "type": "integer", "example": 28 }, "type": { "enum": [ "checking", "savings", "credit_card", "other" ], "allOf": [ { "$ref": "#/definitions/model.AccountType" } ], "example": "checking" } } }, "dto.AccountResponse": { "type": "object", "properties": { "balance": { "type": "number" }, "closing_day": { "type": "integer" }, "credit_limit": { "type": "number" }, "due_day": { "type": "integer" }, "id": { "type": "integer" }, "initial_balance": { "type": "number" }, "name": { "type": "string" }, "type": { "$ref": "#/definitions/model.AccountType" }, "user_id": { "type": "integer" } } }, "dto.BudgetResponse": { "type": "object", "properties": { "amount": { "description": "The planned budget amount", "type": "number" }, "balance": { "description": "The remaining balance (Amount - Spent)", "type": "number" }, "category_id": { "type": "integer" }, "category_name": { "type": "string" }, "created_at": { "type": "string" }, "id": { "type": "integer" }, "month": { "type": "integer" }, "spent_amount": { "description": "The calculated amount spent so far", "type": "number" }, "year": { "type": "integer" } } }, "dto.CategoryRequest": { "type": "object", "required": [ "name" ], "properties": { "name": { "type": "string", "minLength": 2 } } }, "dto.CategoryResponse": { "type": "object", "properties": { "id": { "type": "integer" }, "name": { "type": "string" } } }, "dto.CreateBudgetRequest": { "type": "object", "required": [ "amount", "category_id", "month", "year" ], "properties": { "amount": { "type": "number" }, "category_id": { "type": "integer" }, "month": { "type": "integer", "maximum": 12, "minimum": 1 }, "year": { "type": "integer" } } }, "dto.CreateTransactionRequest": { "type": "object", "properties": { "account_id": { "type": "integer" }, "amount": { "type": "number" }, "category_id": { "description": "Opcional", "type": "integer" }, "date": { "type": "string" }, "description": { "type": "string" }, "destination_account_id": { "description": "Opcional, mas necessário para transferências", "type": "integer" }, "type": { "$ref": "#/definitions/model.TransactionType" } } }, "dto.CreateUserRequest": { "type": "object", "required": [ "email", "name", "password" ], "properties": { "email": { "type": "string" }, "name": { "type": "string", "minLength": 2 }, "password": { "type": "string", "minLength": 6 } } }, "dto.ErrorResponse": { "type": "object", "properties": { "details": { "type": "object", "additionalProperties": { "type": "string" } }, "error": { "type": "string" } } }, "dto.LoginRequest": { "type": "object", "required": [ "email", "password" ], "properties": { "email": { "type": "string" }, "password": { "type": "string" } } }, "dto.LoginResponse": { "type": "object", "properties": { "token": { "type": "string" } } }, "dto.PatchTransactionRequest": { "type": "object", "properties": { "account_id": { "type": "integer" }, "amount": { "type": "number" }, "category_id": { "type": "integer" }, "date": { "type": "string" }, "description": { "type": "string" }, "type": { "$ref": "#/definitions/model.TransactionType" } } }, "dto.StatementPeriod": { "type": "object", "properties": { "end": { "type": "string" }, "start": { "type": "string" } } }, "dto.StatementResponse": { "type": "object", "properties": { "account_name": { "type": "string" }, "payment_due_date": { "type": "string" }, "period": { "$ref": "#/definitions/dto.StatementPeriod" }, "statement_total": { "type": "number" }, "transactions": { "description": "We reuse the existing TransactionResponse DTO", "type": "array", "items": { "$ref": "#/definitions/dto.TransactionResponse" } } } }, "dto.TransactionResponse": { "type": "object", "properties": { "account_id": { "type": "integer" }, "account_name": { "type": "string" }, "amount": { "type": "number" }, "category_id": { "type": "integer" }, "category_name": { "type": "string" }, "created_at": { "type": "string" }, "date": { "type": "string" }, "description": { "type": "string" }, "destination_account_id": { "type": "integer" }, "id": { "type": "integer" }, "type": { "$ref": "#/definitions/model.TransactionType" } } }, "dto.UpdateBudgetRequest": { "type": "object", "required": [ "amount" ], "properties": { "amount": { "type": "number" } } }, "dto.UpdateTransactionRequest": { "type": "object", "required": [ "account_id", "amount", "date", "description", "type" ], "properties": { "account_id": { "type": "integer" }, "amount": { "type": "number" }, "category_id": { "type": "integer" }, "date": { "type": "string" }, "description": { "type": "string" }, "destination_account_id": { "type": "integer" }, "type": { "$ref": "#/definitions/model.TransactionType" } } }, "dto.UserResponse": { "type": "object", "properties": { "created_at": { "type": "string" }, "email": { "type": "string" }, "id": { "type": "integer" }, "name": { "type": "string" } } }, "model.AccountType": { "type": "string", "enum": [ "checking", "savings", "credit_card", "other" ], "x-enum-varnames": [ "Checking", "Savings", "CreditCard", "Other" ] }, "model.TransactionType": { "type": "string", "enum": [ "income", "expense", "transfer" ], "x-enum-varnames": [ "Income", "Expense", "Transfer" ] } }, "securityDefinitions": { "BearerAuth": { "type": "apiKey", "name": "Authorization", "in": "header" } } }