Desenvolvimento de uma API utilizando SpringBoot + Kotlin com o intuito de cadastro de Vingadores.

Overview

Avengers API - Curso de introdução á Arquitetura Hexagonal com Spring Boot e Kotlin

Desenvolvimento de uma API utilizando SpringBoot + Kotlin com o intuito de cadastro de Vingadores.

Tecnologias / Frameworks / IDE

  • Android Studio
  • SpringBoot 2.4.4
  • Maven
  • Kotlin
  • SpringData JPA
  • PostgreSQL
  • Flyway
  • Java 8
  • Heroku

Criação do esqueleto do projeto

Definir contrato API

  • https://editor.swagger.io/

  • Recurso avenger

  • GET - 200 OK

  • GET {id}/detail - 200 OK ou 404 Not Found

  • POST - 201 Created ou 400 Bad Request

  • PUT {id} - 202 Accepted ou 404 Not Found

  • DELETE {id} - 202 Accepted ou 404 Not Found

{
  "nick": "spider-man",
  "person": "Peter Parker",
  "description": "sobre poderes",
  "history": "a história"
}

Design Arquitetural

  • Camada de Aplicação (controllers, configs, exception handle, request e response dtos, bean validations)
  • Camada de Domínio (modelo avenger, interface repositório, serviço)
  • Camada de Infraestrutura (jpa repository, entidade avenger, proxy implementa interface repositorio e utiliza o jpa repositorio para comunicação com banco de dados)
  • Testes

Flyway (db/migration)

create table avenger (
    id bigserial not null,
    nick varchar(36),
    person varchar(128),
    description varchar(128),
    history text
    primary key (id)
);

alter table avenger add constraint UK_5r88eemotwgru6k0ilqb2ledh unique (nick);

Profiles

  • application.yaml
  • application-dev.yaml
  • application-heroku.yaml
spring:
  application:
    name: avengers
  config:
    # This configuration allow use profiles as spring 2.3.x version
    # In spring 2.4.x version, has changed to:
    # spring:
    #  profiles:
    #    group:
    #      <group>: dev, auth
    use-legacy-processing: true
  profiles:
    active: dev
  jmx:
    enabled: false
  data:
    jpa:
      repositories:
        bootstrap-mode: deferred
  jpa:
    open-in-view: false
    properties:
      hibernate.jdbc.time_zone: UTC
      hibernate.generate_statistics: false
      hibernate.jdbc.batch_size: 25
      hibernate.order_inserts: true
      hibernate.order_updates: true
      hibernate.query.fail_on_pagination_over_collection_fetch: true
      hibernate.query.in_clause_parameter_padding: true
    hibernate:
      ddl-auto: none
      naming:
        physical-strategy: org.springframework.boot.orm.jpa.hibernate.SpringPhysicalNamingStrategy
        implicit-strategy: org.springframework.boot.orm.jpa.hibernate.SpringImplicitNamingStrategy
  main:
    allow-bean-definition-overriding: true
  task:
    execution:
      thread-name-prefix: avengers-task-
      pool:
        core-size: 2
        max-size: 50
        queue-capacity: 10000
    scheduling:
      thread-name-prefix: avengers-scheduling-
      pool:
        size: 2
  output:
    ansi:
      console-available: true

server:
  port: 9090
  servlet:
    session:
      cookie:
        http-only: true
    context-path: /avengers
spring:
  profiles:
    active: dev
  jackson:
    serialization:
      indent-output: true
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    url: jdbc:postgresql://localhost:25433/${DB_NAME}
    username: ${DB_USER}
    password: ${DB_PASSWORD}
  jpa:
    database-platform: org.hibernate.dialect.PostgreSQLDialect
    show-sql: true
spring:
  profiles:
    active: heroku
  jackson:
    serialization:
      indent-output: true
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    url: jdbc:postgresql://${HOST}/${DB_NAME}
    username: ${DB_USER}
    password: ${DB_PASSWORD}
  jpa:
    database-platform: org.hibernate.dialect.PostgreSQLDialect
    show-sql: false

Dcoker

Environment Config

DB_USER=dio.avenger
DB_PASSWORD=dio.avenger
DB_NAME=avengers

YAML (backend-services.yaml)

version: '3.2'
services:
  postgres:
    image: postgres:12-alpine
    environment:
      POSTGRES_USER: ${DB_USER}
      POSTGRES_DB: ${DB_NAME}
      POSTGRES_PASSWORD: ${DB_PASSWORD}
      ALLOW_IP_RANGE: 0.0.0.0/0
    ports:
      - "25433:5432"
    volumes:
      - pdb12:/var/lib/postgresql/data
    networks:
      - postgres-compose-network

  teste-pgadmin-compose:
    image: dpage/pgadmin4
    environment:
      PGADMIN_DEFAULT_EMAIL: "[email protected]"
      PGADMIN_DEFAULT_PASSWORD: "123456"
    ports:
      - "5556:80"
    depends_on:
      - postgres
    networks:
      - postgres-compose-network

volumes:
  pdb12:
networks:
  postgres-compose-network:
    driver: bridge

Script / Comandos

  • docker-compose -f backend-services.yaml up -d (deploy) / docker-compose -f backend-services.yaml down (undeploy)

  • Start API

./mvnw spring-boot:run -Dspring-boot.run.profiles=dev -Dspring-boot.run.jvmArguments="-Xmx256m -Xms128m" -Dspring-boot.run.arguments="'--DB_USER=dio.avenger' '--DB_PASSWORD=dio.avenger' '--DB_NAME=avengers'"

Heroku

  • Criar app
  • Linkar com Github
  • Setar vairáveis de ambiente

Procfile

web: java -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap $JAVA_OPTS -Dserver.port=$PORT -Dspring.profiles.active=heroku -jar target/*.jar
You might also like...
Criação de um App de Dicionário dividido em duas etapas utilizando Activities, Intents, Fragments e o componente de navegação

Words App This folder contains the source code for the Words app codelab. Introduction Words app allows you to select a letter and use Intents to navi

Exercício utilizando ViewModel e LiveData

Unscramble App Starter code for Android Basics codelab - Store the data in a ViewModel Unscramble is a single player game app that displays scrambled

Aagent-new-service-parent - A Springboot Rest Webservice Project that can be deployed to a Docker container

Webservice in a Docker Container A Springboot Rest Webservice Project that can b

SpringBoot SpringDoc JWT
SpringBoot SpringDoc JWT

springboot-springdoc-jwt Things todo list Clone this repository: git clone https

Resoluções a problemas e desafios comuns da plataforma Android, que todo desenvolvedor profissional cedo ou tarde irá enfrentar e deveria ter visto, ao menos, uma única vez na vida!
Resoluções a problemas e desafios comuns da plataforma Android, que todo desenvolvedor profissional cedo ou tarde irá enfrentar e deveria ter visto, ao menos, uma única vez na vida!

Resoluções a problemas e desafios comuns da plataforma Android, que todo desenvolvedor profissional cedo ou tarde irá enfrentar e deveria ter visto, ao menos, uma única vez na vida!

intera.kt is a Kotlin library for interacting with the Discord Interactions API through a gateway service or a REST API.

🗿 Overview ⚠️ WARNING: intera.kt is a work in progress. It is not yet ready for use. You may encounter bugs and other issues, but please report if yo

intera.kt is a Kotlin library for interacting with the Discord Interactions API through a gateway service or a REST API.

🗿 Overview ⚠️ WARNING: intera.kt is a work in progress. It is not yet ready for use. You may encounter bugs and other issues, but please report if yo

Postman-API-Fest-22 - Project for Postman API Fest 22
Postman-API-Fest-22 - Project for Postman API Fest 22

Project for Postman API Fest 22 Team Moon With only two members on the board, we

EduApp is a mini e-learning platform based on udemy's public api. It has 4 main navigation destinations (Home, Search, Wishlist, Cart). Users can search courses from different categories and get real-time results from the api using Chips for a smooth filtering experience. It has different theme for dark mode.
Owner
Gian Felipe
Gian Felipe
Blog Backend Api built with Kotlin, Springboot and AWS

Kotlin, Spring Boot, MySQL, JPA, Hibernate Rest API for Blogs A Restful CRUD API using Kotlin, Spring Boot, Mysql, JPA and Hibernate hosted on AWS Ela

Nick Ang 1 Nov 15, 2021
Desenvolvimento de um CRUD sabendo lidar com requisições GET, POST, PUT e DELETE. E CAMADA DE PERSISTENCIA

API-REST-com-Kotlin-e-Spring-Boot Aprendemos nesse projeto: Parte 1 - DESENVOLVIMENTO WEB 1- Criação de classes de domínio que representam os recursos

Marcello Eduardo 4 Aug 9, 2021
O projeto Calling-Therapies é um aplicativo em desenvolvimento para o Trabalho de Conclusão de Curso da faculdade.

Calling-Therapies ?? Informações sobre o projeto O projeto Calling-Therapies é um aplicativo em desenvolvimento para o Trabalho de Conclusão de Curso

Diego Silva 12 Mar 10, 2022
Aplicativo simples de piadas do Chuck Norris fazendo o consumo de uma API com Retrofit.

Chuck-Norris-API-Android Aplicativo simples de piadas do Chuck Norris fazendo o consumo de uma API com Retrofit. A API NÃO FOI CRIADA POR MIM! Disponí

Marcos Lopes da Silva Junior 0 Nov 26, 2021
Aplicação Micronaut GRPC utilizando Kotlin e arquitetura Hexagonal

micronaut-grpc-demo Aplicação Micronaut GRPC utilizando Kotlin e arquitetura Hexagonal #Baixando e configurando um container Postgres: Postgres: docke

Paulo César de Souza 0 Nov 15, 2021
For Kotlin with SpringBoot project that have multi-module-structure template

Goals kotlin + spring-boot + gradle + multi-module building Module-Structure ---root |--- src.main.kotlin.KotlinSpringbootMultiModuleTemplateAppl

pguma 1 Jul 24, 2022
Kotlin SpringBoot REST Service

Kotlin SpringBoot REST Service Servicio web para API REST con Kotlin y SpringBoot. Kotlin SpringBoot REST Service Acerca de Autor Contacto Licencia Ac

José Luis González Sánchez 2 Mar 10, 2022
POC de uma aplicação de domínio financeiro.

Financial Overview Domínio Arquitetura Organização da aplicação Casos de uso Instalação Repositório Configuração Roadmap Verificando o ambiente Execut

Gustavo Santos 62 Sep 27, 2022
A springboot secure web app with thymeleaf support.

kotlin-web-maven-spring-thyme-challenge-question-aes-encoded-scrypt-encode Description A springboot secure web app with thymeleaf support. Three roles

null 0 Nov 23, 2021
A springboot secure web app with jsp support.

kotlin-web-maven-spring-jsp-register-rsa-encrypt-argon2-encoded Description A springboot secure web app with jsp support. Three roles are defined; USE

null 0 Nov 24, 2021