Sign inSign up

gustosilva/log-api

By gustosilva

Updated over 3 years ago

Api REST usando java e Spring Boot, feita durante workshop MSR da algaworks

Image
0

10K+

gustosilva/log-api repository overview

Log API

Api REST usando java e Spring Boot, feita durante workshop MSR da algaworks. Alem disso, possui a documentaçao usando OpenAPI 3.0 e requisições HTTPS.

Features

  • CRUD completo de clientes e entregas
  • Listagem e registro de ocorrências a partir de uma entrega

Contrato da API

Arquivo para criar a API no Swagger
{
  "openapi": "3.0.1",
  "info": {
    "title": "Log Api",
    "description": "Aplicação desenvolvida para testes.",
    "contact": {
      "name": "gasfgrv",
      "url": "https://github.com/gasfgrv",
      "email": "[email protected]"
    },
    "license": {
      "name": "Apache License Version 2.0",
      "url": "https://www.apache.org/licenses/LICENSE-2.0"
    },
    "version": "v1"
  },
  "servers": [
    {
      "url": "https://localhost:8443/",
      "description": "Generated server url"
    }
  ],
  "tags": [
    {
      "name": "Ocorrências",
      "description": "Endpoint para tratamento de Ocorrências relacionadas a uma entrega"
    },
    {
      "name": "Clientes",
      "description": "Endpoint para manipulação dos dados de um cliente"
    },
    {
      "name": "Entregas",
      "description": "Endpoint para tratamento das entregas"
    }
  ],
  "paths": {
    "/entregas/{entregaId}/finalizacao": {
      "put": {
        "tags": [
          "Entregas"
        ],
        "summary": "Finalizar entrega",
        "description": "Finalizar uma determinada entregas a partir do id",
        "operationId": "finalizar",
        "parameters": [
          {
            "name": "entregaId",
            "in": "path",
            "description": "Id da entrega",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "200": {
            "description": "Entrega finalizada"
          },
          "204": {
            "description": "No Content"
          }
        }
      }
    },
    "/clientes/{clienteId}": {
      "get": {
        "tags": [
          "Clientes"
        ],
        "summary": "Buscar cliente",
        "description": "Buscar determinado cliente a partir do id",
        "operationId": "buscar_1",
        "parameters": [
          {
            "name": "clienteId",
            "in": "path",
            "description": "Id do cliente",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "404": {
            "description": "Cliente não encontrado",
            "content": {
              "application/json": {
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "200": {
            "description": "Cliente encontrado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Cliente"
                }
              }
            }
          }
        }
      },
      "put": {
        "tags": [
          "Clientes"
        ],
        "summary": "Atualizar cliente",
        "description": "Atualizar dados do cliente",
        "operationId": "atualizar",
        "parameters": [
          {
            "name": "clienteId",
            "in": "path",
            "description": "Id do cliente",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "requestBody": {
          "description": "Formulário de atualização",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClienteInput"
              }
            }
          },
          "required": true
        },
        "responses": {
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "200": {
            "description": "Cliente atualizado",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClienteModel"
                }
              }
            }
          }
        }
      },
      "delete": {
        "tags": [
          "Clientes"
        ],
        "summary": "Deletar cliente",
        "description": "Deletar dados do cliente",
        "operationId": "remover",
        "parameters": [
          {
            "name": "clienteId",
            "in": "path",
            "description": "Id do cliente",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "204": {
            "description": "Cliente apagado",
            "content": {
              "application/json": {
              }
            }
          }
        }
      }
    },
    "/entregas": {
      "get": {
        "tags": [
          "Entregas"
        ],
        "summary": "Listar entregas",
        "description": "Listar todas as entregas salvas",
        "operationId": "listar",
        "responses": {
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "200": {
            "description": "Todas as entregas",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EntregaModel"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Entregas"
        ],
        "summary": "Solicitar entrega",
        "description": "Vincula um clienate à entrega e cria a mesma",
        "operationId": "solicitar",
        "requestBody": {
          "description": "Formulário de cadastro",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/EntregaInput"
              }
            }
          },
          "required": true
        },
        "responses": {
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "201": {
            "description": "Entrega solicitada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EntregaModel"
                }
              }
            }
          }
        }
      }
    },
    "/entregas/{entregaId}/ocorrencias": {
      "get": {
        "tags": [
          "Ocorrências"
        ],
        "summary": "Listar ocorrências",
        "description": "Listar todas as ocorrências relacionadas a uma entrega",
        "operationId": "listar_1",
        "parameters": [
          {
            "name": "entregaId",
            "in": "path",
            "description": "Id da entrega",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "200": {
            "description": "Todos as ocorrências",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OcorrenciaModel"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Ocorrências"
        ],
        "summary": "Registrar ocorrencias",
        "description": "Vincula uma ocorrência a uma entrega",
        "operationId": "registrar",
        "parameters": [
          {
            "name": "entregaId",
            "in": "path",
            "description": "Id da entrega",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "requestBody": {
          "description": "dados da ocorrência",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/OcorrenciaInput"
              }
            }
          },
          "required": true
        },
        "responses": {
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "201": {
            "description": "Ocorrência registrada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/OcorrenciaModel"
                }
              }
            }
          }
        }
      }
    },
    "/clientes": {
      "get": {
        "tags": [
          "Clientes"
        ],
        "summary": "Listar clientes",
        "description": "Listar todos os clientes salvos",
        "operationId": "listar_2",
        "responses": {
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "200": {
            "description": "Todos os clientes",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClienteResumoModel"
                }
              }
            }
          }
        }
      },
      "post": {
        "tags": [
          "Clientes"
        ],
        "summary": "Salvar cliente",
        "description": "Salvar cliente na base",
        "operationId": "adicionar",
        "requestBody": {
          "description": "Formulário de cadastro",
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClienteInput"
              }
            }
          },
          "required": true
        },
        "responses": {
          "404": {
            "description": "Not Found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "201": {
            "description": "Cliente Salvo",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Cliente"
                }
              }
            }
          }
        }
      }
    },
    "/entregas/{entregaId}": {
      "get": {
        "tags": [
          "Entregas"
        ],
        "summary": "Buscar entrega",
        "description": "Buscar determinada entrega a partir do id",
        "operationId": "buscar",
        "parameters": [
          {
            "name": "entregaId",
            "in": "path",
            "description": "Id da entrega",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int64"
            }
          }
        ],
        "responses": {
          "404": {
            "description": "Entrega não encontrada",
            "content": {
              "application/json": {
              }
            }
          },
          "400": {
            "description": "Bad Request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Problema"
                }
              }
            }
          },
          "200": {
            "description": "Entrega encontrada",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EntregaModel"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Campo": {
        "type": "object",
        "properties": {
          "nome": {
            "type": "string"
          },
          "mensagem": {
            "type": "string"
          }
        }
      },
      "Problema": {
        "type": "object",
        "properties": {
          "status": {
            "type": "integer",
            "format": "int32"
          },
          "dataHora": {
            "type": "string",
            "format": "date-time"
          },
          "titulo": {
            "type": "string"
          },
          "campos": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Campo"
            }
          }
        }
      },
      "ClienteInput": {
        "required": [
          "email",
          "nome",
          "telefone"
        ],
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "nome": {
            "maxLength": 60,
            "minLength": 0,
            "type": "string"
          },
          "email": {
            "maxLength": 255,
            "minLength": 0,
            "type": "string"
          },
          "telefone": {
            "maxLength": 20,
            "minLength": 0,
            "type": "string"
          }
        }
      },
      "ClienteModel": {
        "type": "object",
        "properties": {
          "nome": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "telefone": {
            "type": "string"
          }
        }
      },
      "ClienteIdInput": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          }
        }
      },
      "DestinatarioInput": {
        "required": [
          "bairro",
          "complemento",
          "logradouro",
          "nome",
          "numero"
        ],
        "type": "object",
        "properties": {
          "nome": {
            "type": "string"
          },
          "logradouro": {
            "type": "string"
          },
          "numero": {
            "type": "string"
          },
          "complemento": {
            "type": "string"
          },
          "bairro": {
            "type": "string"
          }
        }
      },
      "EntregaInput": {
        "required": [
          "cliente",
          "destinatario",
          "taxa"
        ],
        "type": "object",
        "properties": {
          "cliente": {
            "$ref": "#/components/schemas/ClienteIdInput"
          },
          "destinatario": {
            "$ref": "#/components/schemas/DestinatarioInput"
          },
          "taxa": {
            "type": "number"
          }
        }
      },
      "ClienteResumoModel": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "nome": {
            "type": "string"
          }
        }
      },
      "DestinatarioModel": {
        "type": "object",
        "properties": {
          "nome": {
            "type": "string"
          },
          "logradouro": {
            "type": "string"
          },
          "numero": {
            "type": "string"
          },
          "complemento": {
            "type": "string"
          },
          "bairro": {
            "type": "string"
          }
        }
      },
      "EntregaModel": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "cliente": {
            "$ref": "#/components/schemas/ClienteResumoModel"
          },
          "destinatario": {
            "$ref": "#/components/schemas/DestinatarioModel"
          },
          "taxa": {
            "type": "number"
          },
          "status": {
            "type": "string",
            "enum": [
              "PENDENTE",
              "FINALIZADA",
              "CANCELADA"
            ]
          },
          "dataPedido": {
            "type": "string",
            "format": "date-time"
          },
          "dataFinalizacao": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "OcorrenciaInput": {
        "required": [
          "descricao"
        ],
        "type": "object",
        "properties": {
          "descricao": {
            "type": "string"
          }
        }
      },
      "OcorrenciaModel": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "descricao": {
            "type": "string"
          },
          "dataRegistro": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "Cliente": {
        "type": "object",
        "properties": {
          "id": {
            "type": "integer",
            "format": "int64"
          },
          "nome": {
            "type": "string"
          },
          "email": {
            "type": "string"
          },
          "telefone": {
            "type": "string"
          }
        }
      }
    }
  }
}

Endpoints da Aplicação

Documentação dos endpoints
/entregas/{entregaId}/finalizacao
PUT
Summary:

Finalizar entrega

Description:

Finalizar uma determinada entregas a partir do id

Parameters
NameLocated inDescriptionRequiredSchema
entregaIdpathId da entregaYeslong
Responses
CodeDescription
200Entrega finalizada
204No Content
400Bad Request
404Not Found
/clientes/{clienteId}
GET
Summary:

Buscar cliente

Description:

Buscar determinado cliente a partir do id

Parameters
NameLocated inDescriptionRequiredSchema
clienteIdpathId do clienteYeslong
Responses
CodeDescription
200Cliente encontrado
400Bad Request
404Cliente não encontrado
PUT
Summary:

Atualizar cliente

Description:

Atualizar dados do cliente

Parameters
NameLocated inDescriptionRequiredSchema
clienteIdpathId do clienteYeslong
Responses
CodeDescription
200Cliente atualizado
400Bad Request
404Not Found
DELETE
Summary:

Deletar cliente

Description:

Deletar dados do cliente

Parameters
NameLocated inDescriptionRequiredSchema
clienteIdpathId do clienteYeslong
Responses
CodeDescription
204Cliente apagado
400Bad Request
404Not Found
/entregas
GET
Summary:

Listar entregas

Description:

Listar todas as entregas salvas

Responses
CodeDescription
200Todas as entregas
400Bad Request
404Not Found
POST
Summary:

Solicitar entrega

Description:

Vincula um clienate à entrega e cria a mesma

Responses
CodeDescription
201Entrega solicitada
400Bad Request
404Not Found
/entregas/{entregaId}/ocorrencias
GET
Summary:

Listar ocorrências

Description:

Listar todas as ocorrências relacionadas a uma entrega

Parameters
NameLocated inDescriptionRequiredSchema
entregaIdpathId da entregaYeslong
Responses
CodeDescription
200Todos as ocorrências
400Bad Request
404Not Found
POST
Summary:

Registrar ocorrencias

Description:

Vincula uma ocorrência a uma entrega

Parameters
NameLocated inDescriptionRequiredSchema
entregaIdpathId da entregaYeslong
Responses
CodeDescription
201Ocorrência registrada

Tag summary

Content type

Image

Digest

sha256:d2e75275d

Size

359.8 MB

Last updated

over 3 years ago

docker pull gustosilva/log-api