From 579f52ed04876176449b0f27e524f6990da76f81 Mon Sep 17 00:00:00 2001 From: djmil Date: Mon, 20 Nov 2023 15:51:54 +0100 Subject: [PATCH] GameBoard: move --- .../cordacheckers/api/GameController.java | 20 +++++++++++++++++++ webapp/src/api/games.js | 2 +- webapp/src/container/Games.jsx | 2 +- webapp/src/container/games/GameBoard.jsx | 1 + 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/djmil/cordacheckers/api/GameController.java b/backend/src/main/java/djmil/cordacheckers/api/GameController.java index 25aaa16..9452d77 100644 --- a/backend/src/main/java/djmil/cordacheckers/api/GameController.java +++ b/backend/src/main/java/djmil/cordacheckers/api/GameController.java @@ -9,11 +9,14 @@ import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import djmil.cordacheckers.cordaclient.CordaClient; import djmil.cordacheckers.cordaclient.dao.GameView; +import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameBoardMove; +import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameProposalCreate; import djmil.cordacheckers.user.HoldingIdentityResolver; import djmil.cordacheckers.user.User; @@ -92,4 +95,21 @@ public class GameController { return ResponseEntity .ok(drawRejGame); } + + @PutMapping("/{uuid}/move") + public ResponseEntity move( + @AuthenticationPrincipal User issuer, + @PathVariable UUID uuid, + @RequestBody ReqGameBoardMove request + ) { + final GameView movedGame = cordaClient.gameBoardMove( + issuer.getHoldingIdentity(), + uuid, + request.move(), + request.message() + ); + + return ResponseEntity + .ok(movedGame); + } } diff --git a/webapp/src/api/games.js b/webapp/src/api/games.js index ff93fa7..675e829 100644 --- a/webapp/src/api/games.js +++ b/webapp/src/api/games.js @@ -70,7 +70,7 @@ export default function useGamesApi(gamesReducer, config) { }), pushGameMove: ({ uuid, move, message }) => ifNot(games.isPushingGameMove) && - doPushing(`/api/game/${uuid}/move`, 'PUT', null, { + doPushing(`/api/game/${uuid}/move`, 'PUT', { move, message }, { onPushing: (isPushingGameMove) => dispatchGames({ type: 'next', isPushingGameMove }), onSuccess: (game) => dispatchGames({ type: 'next', gamesList: games.nextGame(game), active: gamesInitialState.active }) }), diff --git a/webapp/src/container/Games.jsx b/webapp/src/container/Games.jsx index 472e172..25c2053 100644 --- a/webapp/src/container/Games.jsx +++ b/webapp/src/container/Games.jsx @@ -119,7 +119,7 @@ function GameBoardRoutes({ gamesReducer, gamesApi, username }) { dispatchGames({ type: 'nextNewGame', board }); } - const onStoneMove = (uuid, move) => console.log(uuid, 'move', move); + const onStoneMove = (uuid, move) => gamesApi.pushGameMove({uuid, move, message: games.active.message}); return ( diff --git a/webapp/src/container/games/GameBoard.jsx b/webapp/src/container/games/GameBoard.jsx index e1e1ffd..2d741d0 100644 --- a/webapp/src/container/games/GameBoard.jsx +++ b/webapp/src/container/games/GameBoard.jsx @@ -33,6 +33,7 @@ export default function GameBoard({ username, onStoneClick, onStoneMove }) { + { games.isPushingGameMove ? Moving... : null} ) } \ No newline at end of file