Sign inSign up

gustosilva/easy-notes-api

By gustosilva

Updated over 3 years ago

Api REST de CRUD de notas usando Spring Boot e MariaDB

Image
0

10K+

gustosilva/easy-notes-api repository overview

Easy notes API

Api REST de CRUD de notas usando Spring Boot e MariaDB. Projeto feito para estudar Spring Hateoas.

Features

  • Crud completo de notas
  • Respostas usando hateoas

Contrato da API

openapi: 3.0.1
info:
  title: OpenAPI definition
  version: v0
servers:
- url: http://localhost:8080
  description: Generated server url
paths:
  /v1/notes/{id}:
    get:
      tags:
      - notes-controller
      operationId: getNoteById
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: integer
          format: int64
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/NoteDetailsDto'
    put:
      tags:
      - notes-controller
      operationId: updateNote
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: integer
          format: int64
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NoteForm'
        required: true
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/NoteDto'
    delete:
      tags:
      - notes-controller
      operationId: deleteNote
      parameters:
      - name: id
        in: path
        required: true
        schema:
          type: integer
          format: int64
      responses:
        "200":
          description: OK
  /v1/notes:
    get:
      tags:
      - notes-controller
      operationId: getAllNotes
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/CollectionModelNoteDto'
    post:
      tags:
      - notes-controller
      operationId: createNote
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/NoteForm'
        required: true
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/NoteDto'
  /v1:
    get:
      tags:
      - root-controller
      operationId: root
      responses:
        "200":
          description: OK
          content:
            '*/*':
              schema:
                $ref: '#/components/schemas/EntryPointDto'
components:
  schemas:
    NoteForm:
      required:
      - content
      - title
      type: object
      properties:
        title:
          type: string
        content:
          type: string
    Link:
      type: object
      properties:
        rel:
          type: string
        href:
          type: string
        hreflang:
          type: string
        media:
          type: string
        title:
          type: string
        type:
          type: string
        deprecation:
          type: string
        profile:
          type: string
        name:
          type: string
    NoteDto:
      type: object
      properties:
        title:
          type: string
        content:
          type: string
        links:
          type: array
          items:
            $ref: '#/components/schemas/Link'
    EntryPointDto:
      type: object
      properties:
        links:
          type: array
          items:
            $ref: '#/components/schemas/Link'
    CollectionModelNoteDto:
      type: object
      properties:
        links:
          type: array
          items:
            $ref: '#/components/schemas/Link'
        content:
          type: array
          items:
            $ref: '#/components/schemas/NoteDto'
    NoteDetailsDto:
      type: object
      properties:
        title:
          type: string
        content:
          type: string
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
        links:
          type: array
          items:
            $ref: '#/components/schemas/Link'

Endpoints da Aplicação

/v1/notes/{id}
GET
Parameters
NameLocated inDescriptionRequiredSchema
idpathYeslong
Responses
CodeDescription
200OK
PUT
Parameters
NameLocated inDescriptionRequiredSchema
idpathYeslong
Responses
CodeDescription
200OK
DELETE
Parameters
NameLocated inDescriptionRequiredSchema
idpathYeslong
Responses
CodeDescription
200OK
/v1/notes
GET
Responses
CodeDescription
200OK
POST
Responses
CodeDescription
200OK
/v1
GET
Responses
CodeDescription
200OK

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

Run in Insomnia}

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

Criar arquivo docker-compose.yaml:

version: "3.7"
services:
  mariadb:
    container_name: notes_db
    image: mariadb:10.7
    restart: unless-stopped
    networks:
      - easy-notes-network
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_PASSWORD: root
      MYSQL_USER: root
      MYSQL_DATABASE: notes-api

networks:
  easy-notes-network:
    driver: bridge

Rodar os seguintes comados

# Subir container do MariaDB
docker-compose up -d

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

# Gerar o containter
docker run --network easy-notes_easy-notes-network \
  --env DB_USER=root \
  --env DB_PASSWORD=root \
  -p 8080:8080 gustosilva/easy-notes-api:latest

Tecnologias utilizadas

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

Dependencias

  • spring-boot-starter-data-jpa
  • spring-boot-starter-web
  • slf4j-api
  • logback-classic
  • logback-core
  • spring-boot-devtools
  • spring-boot-starter-test
  • spring-boot-starter-hateoas
  • spring-boot-starter-validation
  • mariadb-java-client
  • modelmapper
  • springdoc-openapi-ui

Autor

Feito por Gustavo Silva:

Tag summary

Content type

Image

Digest

sha256:ce4c16c4c

Size

112.5 MB

Last updated

over 3 years ago

docker pull gustosilva/easy-notes-api