Files
board-mate/api/src/main/java/be/naaturel/boardmateapi/controllers/PartyController.java
2025-12-11 19:07:30 +01:00

71 lines
2.1 KiB
Java

package be.naaturel.boardmateapi.controllers;
import be.naaturel.boardmateapi.common.models.Move;
import be.naaturel.boardmateapi.common.models.Game;
import be.naaturel.boardmateapi.services.GameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
@RestController
public class PartyController {
private final GameService service;
@Autowired
public PartyController(GameService service){
this.service = service;
}
@GetMapping("/games/")
public ResponseEntity<?> retrieveAllGames(){
try{
return ResponseEntity
.status(HttpStatus.INTERNAL_SERVER_ERROR)
.build();
} catch (Exception e){
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
@GetMapping("/games/{id}")
public ResponseEntity<Game> retrieveGames(@PathVariable String id){
try{
Game g = service.retrieveGame(id);
return ResponseEntity
.status(HttpStatus.OK)
.body(g);
} catch (Exception e){
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
@PostMapping("/create")
public ResponseEntity<?> CreateParty(@RequestBody Game game){
try{
service.create(game);
return ResponseEntity.
status(HttpStatus.INTERNAL_SERVER_ERROR)
.build();
} catch (Exception e){
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
@PostMapping("/moves/add")
public ResponseEntity<?> AddMove(@RequestBody String gameId, @RequestBody Move move){
try{
service.addMove(gameId, move);
return ResponseEntity
.status(HttpStatus.OK)
.build();
} catch (Exception e){
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
}
}
}