-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
MatheusCandido
committed
Sep 15, 2020
1 parent
44d8747
commit 6e44c22
Showing
7 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
Backend/src/main/java/com/dspesquisa/controllers/GamesController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.dspesquisa.controllers; | ||
|
||
import com.dspesquisa.dto.GameDTO; | ||
import com.dspesquisa.entities.Games; | ||
import com.dspesquisa.repositories.GameRepository; | ||
import com.dspesquisa.services.GamesService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping(value="/games") | ||
public class GamesController { | ||
|
||
@Autowired | ||
private GamesService service; | ||
|
||
@GetMapping() | ||
public ResponseEntity<List<GameDTO>> findAll(){ | ||
List<GameDTO> list = service.findAll(); | ||
return ResponseEntity.ok().body(list); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.dspesquisa.dto; | ||
|
||
import com.dspesquisa.entities.Games; | ||
import com.dspesquisa.entities.Plataform; | ||
|
||
import java.io.Serializable; | ||
|
||
public class GameDTO implements Serializable { | ||
|
||
private static final long serialvLersionUID =1L; | ||
private Long id; | ||
private String title; | ||
private Plataform platform; | ||
|
||
public GameDTO(Games entity){ | ||
id= entity.getId(); | ||
title = entity.getTitle(); | ||
platform= entity.getPlataform(); | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public Plataform getPlatform() { | ||
return platform; | ||
} | ||
|
||
public void setPlatform(Plataform platform) { | ||
this.platform = platform; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
Backend/src/main/java/com/dspesquisa/services/GamesService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.dspesquisa.services; | ||
|
||
import com.dspesquisa.dto.GameDTO; | ||
import com.dspesquisa.entities.Games; | ||
import com.dspesquisa.repositories.GameRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
public class GamesService { | ||
|
||
@Autowired | ||
private GameRepository repository; | ||
|
||
@Transactional(readOnly = true) | ||
public List<GameDTO> findAll(){ | ||
List<Games> list= repository.findAll(); | ||
return list.stream().map(x -> new GameDTO(x)).collect(Collectors.toList()); //Função lambda para converter o tipo Games em uma Lista de games DTO | ||
} | ||
} |