Sign inSign up

gustosilva/dynamodb-test

By gustosilva

Updated about 3 years ago

Image
0

504

gustosilva/dynamodb-test repository overview

Dynamodb test (Music API)

API para testes de consultas com a SDK da AWS para o DynamoDB.

Status do Projeto

Static Badge

Funcionalidades

Documentação da API

openapi: 3.0.1
info:
  title: Music API
  description: "This API serves as a test for the AWS SDK for DynamoDB functions (query,\
    \ scan, load and save)."
  contact:
    name: Gustavo Silva
    url: https://github.com/gasfgrv
    email: [email protected]
  version: "1.0"
servers:
  - url: http://localhost:8080
    description: Server URL in the development environment
paths:
  /music:
    post:
      tags:
        - Music
      operationId: saveMusic
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MusicRequest'
        required: true
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/MusicResponse'
  /music/find:
    get:
      tags:
        - Music
      operationId: loadMusic
      parameters:
        - name: song_title
          in: query
          required: true
          schema:
            type: string
        - name: artist
          in: query
          required: true
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/MusicResponse'
  /music/findBy:
    get:
      tags:
        - Music
      operationId: findMusicBy
      parameters:
        - name: album
          in: query
          required: false
          schema:
            type: string
        - name: produced_by
          in: query
          required: false
          schema:
            type: string
        - name: released_in
          in: query
          required: false
          schema:
            type: string
        - name: written_by
          in: query
          required: false
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/MusicsResponse'
  /music/filter:
    get:
      tags:
        - Music
      operationId: queryMusics
      parameters:
        - name: song_title
          in: query
          required: true
          schema:
            type: string
        - name: artist
          in: query
          required: false
          schema:
            type: string
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/MusicsResponse'
components:
  schemas:
    MusicRequest:
      required:
        - song_title
      type: object
      properties:
        song_title:
          type: string
        artist:
          type: string
        written_by:
          type: array
          items:
            type: string
        produced_by:
          type: array
          items:
            type: string
        album:
          type: string
        released_in:
          type: integer
          format: int32
    MusicResponse:
      type: object
      properties:
        song_title:
          type: string
        artist:
          type: string
        written_by:
          type: array
          items:
            type: string
        produced_by:
          type: array
          items:
            type: string
        album:
          type: string
        released_in:
          type: integer
          format: int32
    MusicsResponse:
      type: object
      properties:
        song_title:
          type: string
        artist:
          type: string
        album:
          type: string
        released_in:
          type: integer
          format: int32

Variáveis de Ambiente

Para rodar esse projeto, você vai precisar adicionar as seguintes variáveis de ambiente.

  • AWS_ACCESS_KEY: ID de chave de acesso para autenticação na AWS
  • AWS_REGION: Região onde se encontram recursos na AWS
  • AWS_SECRET_KEY: Chave de acesso secreta para autenticação na AWS
  • AWS_SERVICE_ENDPOINT: URL do ponto de entrada para um serviço da Web da AWS

Rodando localmente

Clone o projeto

  git clone [email protected]:gasfgrv/dynamodb-test.git

Entre no diretório do projeto

  cd dynamodb-test

Instale as dependências

  mvn clean package -DskipTests

Subir recursos na AWS

  cd infra/
  terraform init
  terraform plan
  terraform apply -auto-approve

Inicie a aplicação, pode ser pela IDE (Intellij ou Eclipse), ou rodando o seguinte comando:

    java \
    -Daws.serviceEndpoint=${AWS_SERVICE_ENDPOINT} \
    -Daws.signingRegion=${AWS_REGION} \
    -Daws.accessKey=${AWS_ACCESS_KEY} \
    -Daws.secretKey=${AWS_SECRET_KEY} \
    -jar target/dynamodb-test-0.0.1-SNAPSHOT.jar

Use a collection para ajudar com os endpoints:

Run in Insomnia}

Obs: Para remover os recursos da aws, evitando custos desncessários, use o comando terraform destroy -auto-approve dentro da pasta de infra

Rodando os testes

Para rodar os testes, rode o seguinte comando

  mvn tests

Stack utilizada

  • Java 17
  • Spring Boot 3
  • Maven
Dependências:
  • spring web
  • lombok
  • springdoc-openapi-starter-webmvc-ui
  • spring validation
  • aws sdk

Autores

Tag summary

Content type

Image

Digest

sha256:ada27bcf8

Size

215.4 MB

Last updated

about 3 years ago

docker pull gustosilva/dynamodb-test