Skip to content

gasfgrv/dynamoDB-api

Repository files navigation

dynamoDB-API

API feita para testar a integração do Spring boot com o AWS DynamoDB.

Tabela de Conteúdos

Features

  • Cadastro de dados de funcionários e seus respectivos departamentos

  • Consulta de dados de funcionários e seus respectivos departamentos

  • Atualização de dados de funcionários e seus respectivos departamentos

  • Exclusão de dados de funcionários e seus respectivos departamentos

Contrato da API

{
  "swagger": "2.0",
  "info": {
    "description": "API using Spring Boot for dynamoDB testing",
    "version": "1.0.0",
    "title": "DynamoDB API",
    "license": {
      "name": "Apache License Version 2.0",
      "url": "https://www.apache.org/licenses/LICENSE-2.0"
    }
  },
  "host": "localhost:8080",
  "basePath": "/",
  "tags": [
    {
      "name": "employee-controller",
      "description": "Employee Controller"
    }
  ],
  "paths": {
    "/v1/employees": {
      "post": {
        "tags": [
          "employee-controller"
        ],
        "summary": "Saves a new employee",
        "description": "Saves a new employee in dynamoDB",
        "operationId": "saveEmployeeUsingPOST",
        "consumes": [
          "application/json"
        ],
        "produces": [
          "*/*"
        ],
        "parameters": [
          {
            "in": "body",
            "name": "employee",
            "description": "Form for creation of user",
            "required": true,
            "schema": {
              "$ref": "#/definitions/v1/employeesInput"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "$ref": "#/definitions/v1/employees"
            }
          },
          "201": {
            "description": "Created"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not Found"
          }
        },
        "deprecated": false
      }
    },
    "/v1/employees/{id}": {
      "get": {
        "tags": [
          "employee-controller"
        ],
        "summary": "Get data of specific employee",
        "description": "Get data of specific employee in dynamoDB",
        "operationId": "getEmployeeUsingGET",
        "produces": [
          "*/*"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Employee id",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "$ref": "#/definitions/v1/employeesDto"
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not Found"
          }
        },
        "deprecated": false
      },
      "put": {
        "tags": [
          "employee-controller"
        ],
        "summary": "Update data of specific employee",
        "description": "Update data of specific employee in dynamoDB",
        "operationId": "updateEmployeeUsingPUT",
        "consumes": [
          "application/json"
        ],
        "produces": [
          "*/*"
        ],
        "parameters": [
          {
            "in": "body",
            "name": "employee",
            "description": "Form to update user",
            "required": true,
            "schema": {
              "$ref": "#/definitions/v1/employeesInput"
            }
          },
          {
            "name": "id",
            "in": "path",
            "description": "Employee id",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "schema": {
              "$ref": "#/definitions/v1/employeesDto"
            }
          },
          "201": {
            "description": "Created"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          },
          "404": {
            "description": "Not Found"
          }
        },
        "deprecated": false
      },
      "delete": {
        "tags": [
          "employee-controller"
        ],
        "summary": "Deletes specific employee",
        "description": "Deletes employee in dynamoDB",
        "operationId": "deleteEmployeeUsingDELETE",
        "produces": [
          "*/*"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "Employee id",
            "required": true,
            "type": "string"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          },
          "204": {
            "description": "No Content"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Forbidden"
          }
        },
        "deprecated": false
      }
    }
  },
  "definitions": {
    "Department": {
      "type": "object",
      "properties": {
        "departmentCode": {
          "type": "string"
        },
        "departmentName": {
          "type": "string"
        }
      },
      "title": "Department"
    },
    "Employee": {
      "type": "object",
      "properties": {
        "department": {
          "$ref": "#/definitions/Department"
        },
        "email": {
          "type": "string"
        },
        "employeeId": {
          "type": "string"
        },
        "firstName": {
          "type": "string"
        },
        "lastName": {
          "type": "string"
        }
      },
      "title": "Employee"
    },
    "EmployeeDto": {
      "type": "object",
      "properties": {
        "departamentCode": {
          "type": "string"
        },
        "departamentName": {
          "type": "string"
        },
        "email": {
          "type": "string"
        },
        "firstName": {
          "type": "string"
        },
        "lastName": {
          "type": "string"
        }
      },
      "title": "EmployeeDto"
    },
    "EmployeeInput": {
      "type": "object",
      "properties": {
        "department": {
          "$ref": "#/definitions/Department"
        },
        "email": {
          "type": "string"
        },
        "employeeId": {
          "type": "string"
        },
        "firstName": {
          "type": "string"
        },
        "lastName": {
          "type": "string"
        }
      },
      "title": "EmployeeInput"
    }
  }
}

Endpoints da Aplicação

/v1/employees

POST

Summary:

Saves a new employee

Description:

Saves a new employee in dynamoDB

Parameters
Name Located in Description Required Schema
employee body Form for creation of user Yes EmployeeInput
Responses
Code Description Schema
200 OK Employee
201 Created
401 Unauthorized
403 Forbidden
404 Not Found

/v1/employees/{id}

GET

Summary:

Get data of specific employee

Description:

Get data of specific employee in dynamoDB

Parameters
Name Located in Description Required Schema
id path Employee id Yes string
Responses
Code Description Schema
200 OK EmployeeDto
401 Unauthorized
403 Forbidden
404 Not Found

PUT

Summary:

Update data of specific employee

Description:

Update data of specific employee in dynamoDB

Parameters
Name Located in Description Required Schema
employee body Form to update user Yes EmployeeInput
id path Employee id Yes string
Responses
Code Description Schema
200 OK EmployeeDto
201 Created
401 Unauthorized
403 Forbidden
404 Not Found

DELETE

Summary:

Deletes specific employee

Description:

Deletes employee in dynamoDB

Parameters
Name Located in Description Required Schema
id path Employee id Yes string
Responses
Code Description
200 OK
204 No Content
401 Unauthorized
403 Forbidden

Models

Department

Name Type Description Required
departmentCode string No
departmentName string No

Employee

Name Type Description Required
department Department No
email string No
employeeId string No
firstName string No
lastName string No

EmployeeDto

Name Type Description Required
departamentCode string No
departamentName string No
email string No
firstName string No
lastName string No

EmployeeInput

Name Type Description Required
department Department No
email string No
employeeId string No
firstName string No
lastName string No

Coleção para testar os endpoints da aplicação

Run in Insomnia}

Pré-requisitos e como rodar a aplicação/testes

Pré-requisitos para rodar localmente:

  • JDK 11 ou superior
  • Maven 3
  • Uma conta na AWS com uma tabela chamada empoyee no dynamoDB
    • Um usuário com as permissões (de preferencia a de full access ao bd)

Para rodar via docker, rode os comandos abaixo:

# Baixar a imagem
docker pull gustosilva/dynamodb-api:latest

# Gerar o containter
docker run \
  --env ACCESS_KEY=<ACCESS_KEY> \
  --env SECRET_KEY=<SECRET_KEY> \
  --env SERVICE_ENDPOINT=<SERVICE_ENDPOINT> \
  --env SIGNING_REGION=<SIGNING_REGION> \
  -p 8080:8080 gustosilva/dynamodb-api:latest

Tecnologias utilizadas

Projeto feito usando Java 11 e Maven 3.8 como ferramenta de build.

Dependencias

  • spring validation
  • spring web
  • lombok
  • spring test
  • spring cache
  • modelmapper
  • aws-java-sdk-dynamodb
  • springfox-swagger2
  • springfox-swagger-ui

Licença

Apache License Version 2.0

Autor

Feito por Gustavo Silva: