Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions DSList.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
{
"info": {
"_postman_id": "014fa714-5c7b-44ca-a052-6900518a07ee",
"name": "DSList",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "1242165",
"_collection_link": "https://devsuperior-oficial.postman.co/workspace/Aula~cea0855a-8350-42de-9c9d-0c360fac7d27/collection/1242165-014fa714-5c7b-44ca-a052-6900518a07ee?action=share&creator=1242165&source=collection_link"
},
"item": [
{
"name": "Games",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:8080/games",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"games"
]
}
},
"response": []
},
{
"name": "Game by id",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:8080/games/1",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"games",
"1"
]
}
},
"response": []
},
{
"name": "Game lists",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "http://localhost:8080/lists",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"lists"
]
}
},
"response": []
},
{
"name": "Games by lists",
"protocolProfileBehavior": {
"disabledSystemHeaders": {}
},
"request": {
"method": "GET",
"header": [
{
"key": "",
"value": "",
"type": "text",
"disabled": true
}
],
"url": {
"raw": "http://localhost:8080/lists/2/games",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"lists",
"2",
"games"
]
}
},
"response": []
},
{
"name": "List replacement",
"protocolProfileBehavior": {
"disabledSystemHeaders": {}
},
"request": {
"method": "POST",
"header": [
{
"key": "",
"value": "",
"type": "text",
"disabled": true
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"sourceIndex\": 3,\r\n \"destinationIndex\": 1\r\n}\r\n",
"options": {
"raw": {
"language": "json"
}
}
},
"url": {
"raw": "http://localhost:8080/lists/2/replacement",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"lists",
"2",
"replacement"
]
}
},
"response": []
}
]
}
54 changes: 45 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

**1. Perdeu alguma aula ou material de apoio?**

Inscreva-se para receber no seu email:
Inscreva-se para receber os conteúdos no seu email:

https://devsuperior.com.br

Expand All @@ -14,18 +14,17 @@ Envie uma mensagem pra gente no email que chegou pra você no ato da sua inscri

## Calendário

Os conteúdos ficarão temporariamente disponíveis no nosso canal de eventos. Ative o lembrete:
Os conteúdos ficarão temporariamente disponíveis no nosso website.

https://www.youtube.com/@DevsuperiorJavaSpring
Horário: cada aula será liberada por volta das 9h, somente para quem estiver inscrito no treinamento. Fica de olho no seu email, Whatsapp ou Telegram.

| Dia / horário | Conteúdo |
| ------------- | ------------- |
| Segunda-feira 20h30 | Aula 1: Projeto estruturado |
| Terça-feira 20h30 | Aula 2: Modelo de domínio |
| Quarta-feira 20h30 | Aula 3: Deploy e caso de uso |
| Quinta-feira 20h30 | Aula 4: Endpoint especial |
| Sexta-feira 20h30 | Aula 5: Resumão e reforço do aprendizado |
| Domingo 16h00 | Oficina: Avançando na modelagem de dados |
| Segunda-feira 9h | Aula 1: Projeto estruturado |
| Terça-feira 9h | Aula 2: Domínio e consultas |
| Quarta-feira 9h | Aula 3: Homologação e CORS |
| Quinta-feira 9h | Aula 4: Endpoint especial |
| Sexta-feira 9h | Aula 5: Resumão e reforço do aprendizado

## Modelo de domínio DSList

Expand Down Expand Up @@ -69,6 +68,39 @@ spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
```

### application-dev.properties

```
#spring.jpa.properties.jakarta.persistence.schema-generation.create-source=metadata
#spring.jpa.properties.jakarta.persistence.schema-generation.scripts.action=create
#spring.jpa.properties.jakarta.persistence.schema-generation.scripts.create-target=create.sql
#spring.jpa.properties.hibernate.hbm2ddl.delimiter=;

spring.datasource.url=jdbc:postgresql://localhost:5432/dscatalog
spring.datasource.username=postgres
spring.datasource.password=1234567

spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.hibernate.ddl-auto=none
```

### application-prod.properties
```
spring.datasource.url=${DB_URL}
spring.datasource.username=${DB_USERNAME}
spring.datasource.password=${DB_PASSWORD}

spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.hibernate.ddl-auto=none
```

### system.properties
```
java.runtime.version=17
```

### WebConfig

```java
Expand Down Expand Up @@ -142,3 +174,7 @@ INSERT INTO tb_belonging (list_id, game_id, position) VALUES (2, 8, 2);
INSERT INTO tb_belonging (list_id, game_id, position) VALUES (2, 9, 3);
INSERT INTO tb_belonging (list_id, game_id, position) VALUES (2, 10, 4);
```

### Script Docker Compose

https://gist.github.com/acenelio/5e40b27cfc40151e36beec1e27c4ff71
25 changes: 19 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.0.6</version>
<relativePath/> <!-- lookup parent from repository -->
<version>3.4.1</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.devsuperior</groupId>
<artifactId>dslist</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>dslist</name>
<description>Intensivão Java Spring</description>
<url />
<licenses>
<license />
</licenses>
<developers>
<developer />
</developers>
<scm>
<connection />
<developerConnection />
<tag />
<url />
</scm>
<properties>
<java.version>17</java.version>
<java.version>21</java.version>
</properties>
<dependencies>
<dependency>
Expand All @@ -25,7 +39,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
Expand All @@ -50,7 +63,7 @@
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version> <!--$NO-MVN-MAN-VER$ -->
</plugin>

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/devsuperior/dslist/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.devsuperior.dslist.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig {

@Value("${cors.origins}")
private String corsOrigins;

@Bean
public WebMvcConfigurer corsConfigurer() {
return new WebMvcConfigurer() {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedMethods("*").allowedOrigins(corsOrigins);
}
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.devsuperior.dslist.dto.GameListDTO;
import com.devsuperior.dslist.dto.GameMinDTO;
import com.devsuperior.dslist.dto.ReplacementDTO;
import com.devsuperior.dslist.services.GameListService;
import com.devsuperior.dslist.services.GameService;

Expand All @@ -23,6 +26,12 @@ public class GameListController {
@Autowired
private GameService gameService;

@GetMapping(value = "/{id}")
public GameListDTO findById(@PathVariable Long id) {
GameListDTO result = gameListService.findById(id);
return result;
}

@GetMapping
public List<GameListDTO> findAll() {
List<GameListDTO> result = gameListService.findAll();
Expand All @@ -34,4 +43,9 @@ public List<GameMinDTO> findGames(@PathVariable Long listId) {
List<GameMinDTO> result = gameService.findByGameList(listId);
return result;
}

@PostMapping(value = "/{listId}/replacement")
public void move(@PathVariable Long listId, @RequestBody ReplacementDTO body) {
gameListService.move(listId, body.getSourceIndex(), body.getDestinationIndex());
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/devsuperior/dslist/dto/GameMinDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public GameMinDTO(Game entity) {
public GameMinDTO(GameMinProjection projection) {
id = projection.getId();
title = projection.getTitle();
year = projection.getYear();
year = projection.getGameYear();
imgUrl = projection.getImgUrl();
shortDescription = projection.getShortDescription();
}
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/com/devsuperior/dslist/dto/ReplacementDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.devsuperior.dslist.dto;

public class ReplacementDTO {

private Integer sourceIndex;
private Integer destinationIndex;

public Integer getSourceIndex() {
return sourceIndex;
}

public void setSourceIndex(Integer sourceIndex) {
this.sourceIndex = sourceIndex;
}

public Integer getDestinationIndex() {
return destinationIndex;
}

public void setDestinationIndex(Integer destinationIndex) {
this.destinationIndex = destinationIndex;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public interface GameMinProjection {

Long getId();
String getTitle();
Integer getYear();
Integer getGameYear();
String getImgUrl();
String getShortDescription();
Integer getPosition();
Expand Down
Loading