Added move registration and validation

This commit is contained in:
2025-12-12 16:45:12 +01:00
parent 47e812d710
commit f457911f3b
17 changed files with 269 additions and 45 deletions

View File

@@ -1,8 +1,10 @@
package be.naaturel.boardmateapi.controllers;
import be.naaturel.boardmateapi.common.models.Move;
import be.naaturel.boardmateapi.common.models.Game;
import be.naaturel.boardmateapi.controllers.dtos.GameDto;
import be.naaturel.boardmateapi.controllers.mappings.GameMapper;
import be.naaturel.boardmateapi.services.GameService;
import jakarta.websocket.server.PathParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -30,47 +32,54 @@ public class GameController {
}
@GetMapping("/games/{id}")
public ResponseEntity<Game> retrieveGames(@PathVariable String id){
public ResponseEntity<ResponseBody<GameDto>> retrieveGames(@PathVariable String id){
ResponseBody<GameDto> response = ResponseBody.createEmpty();
try{
Game g = service.retrieveGame(id);
GameDto dto = GameMapper.toDto(g);
response.setData(dto);
response.setSuccess(true);
return ResponseEntity
.status(HttpStatus.OK)
.body(g);
.body(response);
} catch (Exception e){
e.printStackTrace();
response.setMessage(e.getMessage());
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.build();
.body(response);
}
}
@PostMapping("/create")
public ResponseEntity<?> CreateParty(@RequestBody Game game){
public ResponseEntity<ResponseBody<String>> CreateParty(@RequestBody GameDto game){
ResponseBody<String> response = ResponseBody.createEmpty();
try{
service.create(game);
Game model = GameMapper.toModel(game);
String result = service.create(model);
response.setData(result);
response.setSuccess(true);
return ResponseEntity.
status(HttpStatus.INTERNAL_SERVER_ERROR)
.build();
status(HttpStatus.OK)
.body(response);
} catch (Exception e){
e.printStackTrace();
response.setMessage(e.getMessage());
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.body(e.getStackTrace());
.body(response);
}
}
@PostMapping("/moves/add")
public ResponseEntity<?> AddMove(@RequestBody String gameId, @RequestBody Move move){
@PostMapping("/moves/add/{gameId}")
public ResponseEntity<?> AddMove(@PathVariable String gameId, @RequestBody String move){
try{
service.addMove(gameId, move);
return ResponseEntity
.status(HttpStatus.OK)
.build();
} catch (Exception e){
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.build();
}
}
}