Integrated MQTT clients
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package be.naaturel.boardmateapi.controllers;
|
||||
|
||||
import be.naaturel.boardmateapi.common.exceptions.ServiceException;
|
||||
import be.naaturel.boardmateapi.common.models.Game;
|
||||
import be.naaturel.boardmateapi.controllers.dtos.GameDto;
|
||||
import be.naaturel.boardmateapi.controllers.mappings.GameMapper;
|
||||
@@ -33,53 +34,57 @@ public class GameController {
|
||||
|
||||
@GetMapping("/games/{id}")
|
||||
public ResponseEntity<ResponseBody<GameDto>> retrieveGames(@PathVariable String id){
|
||||
ResponseBody<GameDto> response = ResponseBody.createEmpty();
|
||||
ResponseBody<GameDto> result = ResponseBody.createEmpty();
|
||||
try{
|
||||
Game g = service.retrieveGame(id);
|
||||
GameDto dto = GameMapper.toDto(g);
|
||||
response.setData(dto);
|
||||
response.setSuccess(true);
|
||||
result.setData(dto);
|
||||
result.setSuccess(true);
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.OK)
|
||||
.body(response);
|
||||
.body(result);
|
||||
} catch (Exception e){
|
||||
response.setMessage(e.getMessage());
|
||||
result.setMessage(e.getMessage());
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body(response);
|
||||
.body(result);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public ResponseEntity<ResponseBody<String>> CreateParty(@RequestBody GameDto game){
|
||||
ResponseBody<String> response = ResponseBody.createEmpty();
|
||||
ResponseBody<String> result = ResponseBody.createEmpty();
|
||||
try{
|
||||
Game model = GameMapper.toModel(game);
|
||||
String result = service.create(model);
|
||||
response.setData(result);
|
||||
response.setSuccess(true);
|
||||
String id = service.create(model);
|
||||
result.setData(id);
|
||||
result.setSuccess(true);
|
||||
return ResponseEntity.
|
||||
status(HttpStatus.OK)
|
||||
.body(response);
|
||||
.body(result);
|
||||
} catch (Exception e){
|
||||
response.setMessage(e.getMessage());
|
||||
result.setMessage(e.getMessage());
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body(response);
|
||||
.body(result);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/moves/add/{gameId}")
|
||||
public ResponseEntity<?> AddMove(@PathVariable String gameId, @RequestBody String move){
|
||||
public ResponseEntity<ResponseBody<String>> AddMove(@PathVariable String gameId, @RequestBody String move){
|
||||
ResponseBody<String> result = ResponseBody.createEmpty();
|
||||
try{
|
||||
service.addMove(gameId, move);
|
||||
String gamedId = service.addMove(gameId, move);
|
||||
result.setSuccess(true);
|
||||
result.setData(gamedId);
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.OK)
|
||||
.build();
|
||||
} catch (Exception e){
|
||||
.body(result);
|
||||
} catch (ServiceException e){
|
||||
result.setMessage(e.getMessage());
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.build();
|
||||
.body(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user