-
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
6e44c22
commit 0efdc49
Showing
5 changed files
with
142 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
Backend/src/main/java/com/dspesquisa/controllers/RecordsController.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,27 @@ | ||
package com.dspesquisa.controllers; | ||
|
||
import com.dspesquisa.dto.GameDTO; | ||
import com.dspesquisa.dto.RecordDTO; | ||
import com.dspesquisa.dto.RecordInsertDTO; | ||
import com.dspesquisa.services.GamesService; | ||
import com.dspesquisa.services.RecordService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping(value="/records") | ||
public class RecordsController { | ||
|
||
@Autowired | ||
private RecordService service; | ||
|
||
@PostMapping | ||
public ResponseEntity<RecordDTO> insert(@RequestBody RecordInsertDTO dto){ | ||
RecordDTO nDto = service.insert(dto); | ||
return ResponseEntity.ok().body(nDto); | ||
} | ||
|
||
} |
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,32 @@ | ||
package com.dspesquisa.dto; | ||
|
||
import com.dspesquisa.entities.Plataform; | ||
import com.dspesquisa.entities.Record; | ||
|
||
import java.io.Serializable; | ||
import java.time.Instant; | ||
|
||
public class RecordDTO implements Serializable { | ||
|
||
private static final long serialvLersionUID =1L; | ||
|
||
private Long id; | ||
private Instant moment; | ||
private String name; | ||
private Integer age; | ||
private String gameTitle; | ||
private Plataform gamePlatform; | ||
private String genreName; | ||
|
||
public RecordDTO(){} | ||
|
||
public RecordDTO(Record entity){ | ||
id = entity.getId(); | ||
moment= entity.getMoment(); | ||
name= entity.getName(); | ||
age = entity.getAge(); | ||
gameTitle = entity.getGame().getTitle(); | ||
gamePlatform = entity.getGame().getPlataform(); | ||
genreName = entity.getGame().getGenre().getName(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
Backend/src/main/java/com/dspesquisa/dto/RecordInsertDTO.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,38 @@ | ||
package com.dspesquisa.dto; | ||
|
||
import java.io.Serializable; | ||
|
||
public class RecordInsertDTO implements Serializable { | ||
|
||
private static final long serialvLersionUID =1L; | ||
private String name; | ||
private Integer age; | ||
private Long gameId; | ||
|
||
public RecordInsertDTO() { | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Integer getAge() { | ||
return age; | ||
} | ||
|
||
public void setAge(Integer age) { | ||
this.age = age; | ||
} | ||
|
||
public Long getGameId() { | ||
return gameId; | ||
} | ||
|
||
public void setGameId(Long gameId) { | ||
this.gameId = gameId; | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
Backend/src/main/java/com/dspesquisa/services/RecordService.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,41 @@ | ||
package com.dspesquisa.services; | ||
|
||
import com.dspesquisa.dto.GameDTO; | ||
import com.dspesquisa.dto.RecordDTO; | ||
import com.dspesquisa.dto.RecordInsertDTO; | ||
import com.dspesquisa.entities.Games; | ||
import com.dspesquisa.entities.Record; | ||
import com.dspesquisa.repositories.GameRepository; | ||
import com.dspesquisa.repositories.RecordRepository; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.time.Instant; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
public class RecordService { | ||
|
||
@Autowired | ||
private RecordRepository repository; | ||
|
||
@Autowired | ||
private GameRepository gameRepository; | ||
|
||
@Transactional | ||
public RecordDTO insert (RecordInsertDTO dto){ | ||
Record entity = new Record(); | ||
entity.setName(dto.getName()); | ||
entity.setAge(dto.getAge()); | ||
entity.setMoment(Instant.now()); | ||
|
||
Games game = gameRepository.getOne(dto.getGameId()); | ||
entity.setGame(game); | ||
|
||
entity = repository.save(entity); | ||
|
||
return new RecordDTO(entity); | ||
} | ||
} |