FINALLY FIXED DATABASE ACCESS OH MY FUCKING I'M EXHAUSTED
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
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 GameController {
|
||||
|
||||
private final GameService service;
|
||||
|
||||
@Autowired
|
||||
public GameController(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){
|
||||
e.printStackTrace();
|
||||
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){
|
||||
e.printStackTrace();
|
||||
return ResponseEntity
|
||||
.status(HttpStatus.INTERNAL_SERVER_ERROR)
|
||||
.body(e.getStackTrace());
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user