backend: handle corda errors as HTTP_BAD_REQ
This commit is contained in:
parent
77eb2d0013
commit
2ef63cf494
@ -4,6 +4,7 @@ import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@ -12,14 +13,15 @@ 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 org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
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.RspFailureException;
|
||||
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
||||
import djmil.cordacheckers.user.User;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("api/game")
|
||||
public class GameController {
|
||||
@ -32,83 +34,95 @@ public class GameController {
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<List<GameView>> list(
|
||||
@AuthenticationPrincipal User player
|
||||
) {
|
||||
final List<GameView> gsList = cordaClient.gameStateList(player.getHoldingIdentity());
|
||||
@AuthenticationPrincipal User player) {
|
||||
try {
|
||||
final List<GameView> gsList = cordaClient.gameStateList(
|
||||
player.getHoldingIdentity());
|
||||
|
||||
return ResponseEntity.ok(gsList);
|
||||
return ResponseEntity.ok(gsList);
|
||||
} catch (RspFailureException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{uuid}/surrender")
|
||||
public ResponseEntity<GameView> surrender(
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid
|
||||
) {
|
||||
final GameView finishedGame = cordaClient.gameBoardSurrender(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid
|
||||
);
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid) {
|
||||
try {
|
||||
final GameView finishedGame = cordaClient.gameBoardSurrender(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid);
|
||||
|
||||
return ResponseEntity
|
||||
.ok(finishedGame);
|
||||
return ResponseEntity.ok(finishedGame);
|
||||
|
||||
} catch (RspFailureException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{uuid}/drawreq")
|
||||
public ResponseEntity<GameView> drawRequest(
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid
|
||||
) {
|
||||
final GameView drawReqGame = cordaClient.gameDrawRequest(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid
|
||||
);
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid) {
|
||||
try {
|
||||
final GameView drawReqGame = cordaClient.gameDrawRequest(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid);
|
||||
|
||||
return ResponseEntity
|
||||
.ok(drawReqGame);
|
||||
return ResponseEntity.ok(drawReqGame);
|
||||
} catch (RspFailureException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{uuid}/drawacc")
|
||||
public ResponseEntity<GameView> drawAccept(
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid
|
||||
) {
|
||||
final GameView drawAccGame = cordaClient.gameDrawAccept(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid
|
||||
);
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid) {
|
||||
try {
|
||||
final GameView drawAccGame = cordaClient.gameDrawAccept(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid);
|
||||
|
||||
return ResponseEntity
|
||||
.ok(drawAccGame);
|
||||
return ResponseEntity.ok(drawAccGame);
|
||||
} catch (RspFailureException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{uuid}/drawrej")
|
||||
public ResponseEntity<GameView> drawReject(
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid
|
||||
) {
|
||||
final GameView drawRejGame = cordaClient.gameDrawReject(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid
|
||||
);
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid) {
|
||||
try {
|
||||
final GameView drawRejGame = cordaClient.gameDrawReject(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid);
|
||||
|
||||
return ResponseEntity
|
||||
.ok(drawRejGame);
|
||||
return ResponseEntity
|
||||
.ok(drawRejGame);
|
||||
} catch (RspFailureException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{uuid}/move")
|
||||
public ResponseEntity<GameView> move(
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid,
|
||||
@RequestBody ReqGameBoardMove request
|
||||
) {
|
||||
final GameView movedGame = cordaClient.gameBoardMove(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid,
|
||||
request.move(),
|
||||
request.message()
|
||||
);
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid,
|
||||
@RequestBody ReqGameBoardMove request) {
|
||||
try {
|
||||
final GameView movedGame = cordaClient.gameBoardMove(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid,
|
||||
request.move(),
|
||||
request.message());
|
||||
|
||||
return ResponseEntity
|
||||
.ok(movedGame);
|
||||
return ResponseEntity
|
||||
.ok(movedGame);
|
||||
} catch (RspFailureException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import java.net.URI;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@ -12,6 +13,7 @@ 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 org.springframework.web.server.ResponseStatusException;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
@ -22,6 +24,7 @@ import djmil.cordacheckers.cordaclient.dao.GameView;
|
||||
import djmil.cordacheckers.cordaclient.dao.HoldingIdentity;
|
||||
import djmil.cordacheckers.cordaclient.dao.Stone;
|
||||
import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameProposalCreate;
|
||||
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspFailureException;
|
||||
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
||||
import djmil.cordacheckers.user.User;
|
||||
|
||||
@ -39,69 +42,78 @@ public class GameProposalController {
|
||||
public ResponseEntity<GameView> create(
|
||||
@AuthenticationPrincipal User sender,
|
||||
@RequestBody ReqGameProposalCreate gpRequest,
|
||||
UriComponentsBuilder ucb) throws JsonMappingException, JsonProcessingException
|
||||
{
|
||||
final HoldingIdentity gpSender = sender.getHoldingIdentity();
|
||||
final HoldingIdentity gpReceiver = holdingIdentityResolver.getByUsername(gpRequest.opponentName());
|
||||
final Stone.Color gpReceiverColor = gpRequest.opponentColor();
|
||||
UriComponentsBuilder ucb) throws JsonMappingException, JsonProcessingException {
|
||||
try {
|
||||
final HoldingIdentity gpSender = sender.getHoldingIdentity();
|
||||
final HoldingIdentity gpReceiver = holdingIdentityResolver.getByUsername(gpRequest.opponentName());
|
||||
final Stone.Color gpReceiverColor = gpRequest.opponentColor();
|
||||
|
||||
// GiteaIssue #4: Exception handling
|
||||
GameView gameStateView = cordaClient.gameProposalCreate(
|
||||
gpSender,
|
||||
gpReceiver,
|
||||
gpReceiverColor,
|
||||
gpRequest.board(),
|
||||
gpRequest.message());
|
||||
// GiteaIssue #4: Exception handling
|
||||
GameView gameStateView = cordaClient.gameProposalCreate(
|
||||
gpSender,
|
||||
gpReceiver,
|
||||
gpReceiverColor,
|
||||
gpRequest.board(),
|
||||
gpRequest.message());
|
||||
|
||||
URI locationOfNewGameProposal = ucb
|
||||
.path("api/gameproposal/{id}")
|
||||
.buildAndExpand(gameStateView.uuid())
|
||||
.toUri();
|
||||
URI locationOfNewGameProposal = ucb
|
||||
.path("api/gameproposal/{id}")
|
||||
.buildAndExpand(gameStateView.uuid())
|
||||
.toUri();
|
||||
|
||||
return ResponseEntity
|
||||
.created(locationOfNewGameProposal)
|
||||
.body(gameStateView);
|
||||
return ResponseEntity
|
||||
.created(locationOfNewGameProposal)
|
||||
.body(gameStateView);
|
||||
} catch (RspFailureException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{uuid}/cancel")
|
||||
public ResponseEntity<GameView> cancel(
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid
|
||||
) {
|
||||
final GameView canceledGameView = cordaClient.gameProposalCancel(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid
|
||||
);
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid) {
|
||||
try {
|
||||
final GameView canceledGameView = cordaClient.gameProposalCancel(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid);
|
||||
|
||||
return ResponseEntity
|
||||
.ok(canceledGameView);
|
||||
return ResponseEntity
|
||||
.ok(canceledGameView);
|
||||
} catch (RspFailureException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{uuid}/reject")
|
||||
public ResponseEntity<GameView> reject(
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid
|
||||
) {
|
||||
final GameView rejectedGameView = cordaClient.gameProposalReject(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid
|
||||
);
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid) {
|
||||
try {
|
||||
final GameView rejectedGameView = cordaClient.gameProposalReject(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid);
|
||||
|
||||
return ResponseEntity
|
||||
.ok(rejectedGameView);
|
||||
return ResponseEntity
|
||||
.ok(rejectedGameView);
|
||||
} catch (RspFailureException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@PutMapping("/{uuid}/accept")
|
||||
public ResponseEntity<GameView> accept(
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid
|
||||
) {
|
||||
final GameView acceptedGameView = cordaClient.gameProposalAccept(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid
|
||||
);
|
||||
@AuthenticationPrincipal User issuer,
|
||||
@PathVariable UUID uuid) {
|
||||
try {
|
||||
final GameView acceptedGameView = cordaClient.gameProposalAccept(
|
||||
issuer.getHoldingIdentity(),
|
||||
uuid);
|
||||
|
||||
return ResponseEntity
|
||||
.ok(acceptedGameView);
|
||||
return ResponseEntity
|
||||
.ok(acceptedGameView);
|
||||
} catch (RspFailureException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -3,13 +3,17 @@ package djmil.cordacheckers.api;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.server.ResponseStatusException;
|
||||
|
||||
import djmil.cordacheckers.cordaclient.CordaClient;
|
||||
import djmil.cordacheckers.cordaclient.dao.Rank;
|
||||
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspFailureException;
|
||||
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
||||
|
||||
|
||||
@ -25,10 +29,14 @@ public class LeaderboardController {
|
||||
|
||||
@GetMapping
|
||||
public ResponseEntity<Map<String, Rank>> getLeaderboard() {
|
||||
final var hiCustodian = holdingIdentityResolver.getCustodian();
|
||||
final Map<String, Rank> leaderboard = cordaClient.fetchRanking(hiCustodian);
|
||||
try {
|
||||
final var hiCustodian = holdingIdentityResolver.getCustodian();
|
||||
final Map<String, Rank> leaderboard = cordaClient.fetchRanking(hiCustodian);
|
||||
|
||||
return ResponseEntity.ok(leaderboard);
|
||||
return ResponseEntity.ok(leaderboard);
|
||||
} catch (RspFailureException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -28,6 +28,7 @@ import djmil.cordacheckers.cordaclient.dao.flow.RequestBody;
|
||||
import djmil.cordacheckers.cordaclient.dao.flow.ResponseBody;
|
||||
import djmil.cordacheckers.cordaclient.dao.flow.arguments.Req;
|
||||
import djmil.cordacheckers.cordaclient.dao.flow.arguments.Rsp;
|
||||
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspFailureException;
|
||||
import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameBoardMove;
|
||||
import djmil.cordacheckers.cordaclient.dao.flow.arguments.ReqGameProposalCreate;
|
||||
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspGameState;
|
||||
@ -67,7 +68,7 @@ public class CordaClient {
|
||||
}
|
||||
|
||||
// use custodian holding identity to get ranking table of all players
|
||||
public Map<String, Rank> fetchRanking(HoldingIdentity holdingIdentity) {
|
||||
public Map<String, Rank> fetchRanking(HoldingIdentity holdingIdentity) throws RspFailureException {
|
||||
final RequestBody requestBody = new RequestBody(
|
||||
"ranking-" +UUID.randomUUID(),
|
||||
"djmil.cordacheckers.gameresult.RankingFlow",
|
||||
@ -81,7 +82,7 @@ public class CordaClient {
|
||||
* @param holdingIdentity
|
||||
* @return list of unconsumed (active) GameStateViews
|
||||
*/
|
||||
public List<GameView> gameStateList(HoldingIdentity holdingIdentity) {
|
||||
public List<GameView> gameStateList(HoldingIdentity holdingIdentity) throws RspFailureException {
|
||||
final RequestBody requestBody = new RequestBody(
|
||||
"gs.list-" + UUID.randomUUID(),
|
||||
"djmil.cordacheckers.gamestate.ListFlow",
|
||||
@ -91,7 +92,7 @@ public class CordaClient {
|
||||
.getResponce(requestBody);
|
||||
}
|
||||
|
||||
public GameView gameStateGet(HoldingIdentity holdingIdentity, UUID gameUuid) {
|
||||
public GameView gameStateGet(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
|
||||
final RequestBody requestBody = new RequestBody(
|
||||
"gs.get-" + UUID.randomUUID(),
|
||||
"djmil.cordacheckers.gamestate.GetFlow",
|
||||
@ -102,13 +103,13 @@ public class CordaClient {
|
||||
}
|
||||
|
||||
public GameView gameProposalCreate(HoldingIdentity issuer, HoldingIdentity acquier, Stone.Color acquierColor,
|
||||
String message) {
|
||||
String message) throws RspFailureException {
|
||||
|
||||
return gameProposalCreate(issuer, acquier, acquierColor, GameView.defaultGameBoard, message);
|
||||
}
|
||||
|
||||
public GameView gameProposalCreate(HoldingIdentity issuer, HoldingIdentity acquier, Stone.Color acquierColor,
|
||||
Map<Integer, Stone> board, String message) {
|
||||
Map<Integer, Stone> board, String message) throws RspFailureException {
|
||||
final RequestBody requestBody = new RequestBody(
|
||||
"gp.create-" + UUID.randomUUID(),
|
||||
"djmil.cordacheckers.gameproposal.CreateFlow",
|
||||
@ -122,7 +123,7 @@ public class CordaClient {
|
||||
.getResponce(requestBody);
|
||||
}
|
||||
|
||||
public GameView gameProposalReject(HoldingIdentity holdingIdentity, UUID gameUuid) {
|
||||
public GameView gameProposalReject(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
|
||||
final RequestBody requestBody = new RequestBody(
|
||||
"gp.reject-" +UUID.randomUUID(),
|
||||
"djmil.cordacheckers.gameproposal.RejectFlow",
|
||||
@ -132,7 +133,7 @@ public class CordaClient {
|
||||
.getResponce(requestBody);
|
||||
}
|
||||
|
||||
public GameView gameProposalCancel(HoldingIdentity holdingIdentity, UUID gameUuid) {
|
||||
public GameView gameProposalCancel(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
|
||||
final RequestBody requestBody = new RequestBody(
|
||||
"gp.cancel-" +UUID.randomUUID(),
|
||||
"djmil.cordacheckers.gameproposal.CancelFlow",
|
||||
@ -142,7 +143,7 @@ public class CordaClient {
|
||||
.getResponce(requestBody);
|
||||
}
|
||||
|
||||
public GameView gameProposalAccept(HoldingIdentity holdingIdentity, UUID gameUuid) {
|
||||
public GameView gameProposalAccept(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
|
||||
final RequestBody requestBody = new RequestBody(
|
||||
"gp.accept-" +UUID.randomUUID(),
|
||||
"djmil.cordacheckers.gameproposal.AcceptFlow",
|
||||
@ -152,7 +153,7 @@ public class CordaClient {
|
||||
.getResponce(requestBody);
|
||||
}
|
||||
|
||||
public GameView gameBoardSurrender(HoldingIdentity holdingIdentity, UUID gameUuid) {
|
||||
public GameView gameBoardSurrender(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
|
||||
final RequestBody requestBody = new RequestBody(
|
||||
"gb.surrender-" +UUID.randomUUID(),
|
||||
"djmil.cordacheckers.gameboard.SurrenderFlow",
|
||||
@ -163,7 +164,7 @@ public class CordaClient {
|
||||
}
|
||||
|
||||
public GameView gameBoardMove(HoldingIdentity holdingIdentity, UUID gameUuid, List<Integer> move,
|
||||
String message) {
|
||||
String message) throws RspFailureException {
|
||||
final RequestBody requestBody = new RequestBody(
|
||||
"gb.move-" +UUID.randomUUID(),
|
||||
"djmil.cordacheckers.gameboard.MoveFlow",
|
||||
@ -174,7 +175,7 @@ public class CordaClient {
|
||||
.getResponce(requestBody);
|
||||
}
|
||||
|
||||
public GameView gameDrawRequest(HoldingIdentity holdingIdentity, UUID gameUuid) {
|
||||
public GameView gameDrawRequest(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
|
||||
final RequestBody requestBody = new RequestBody(
|
||||
"gd.request-" +UUID.randomUUID(),
|
||||
"djmil.cordacheckers.gameboard.DrawRequestFlow",
|
||||
@ -184,7 +185,7 @@ public class CordaClient {
|
||||
.getResponce(requestBody);
|
||||
}
|
||||
|
||||
public GameView gameDrawAccept(HoldingIdentity holdingIdentity, UUID gameUuid) {
|
||||
public GameView gameDrawAccept(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
|
||||
final RequestBody requestBody = new RequestBody(
|
||||
"gd.accept-" +UUID.randomUUID(),
|
||||
"djmil.cordacheckers.gameboard.DrawAcceptFlow",
|
||||
@ -194,7 +195,7 @@ public class CordaClient {
|
||||
.getResponce(requestBody);
|
||||
}
|
||||
|
||||
public GameView gameDrawReject(HoldingIdentity holdingIdentity, UUID gameUuid) {
|
||||
public GameView gameDrawReject(HoldingIdentity holdingIdentity, UUID gameUuid) throws RspFailureException {
|
||||
final RequestBody requestBody = new RequestBody(
|
||||
"gd.reject-" +UUID.randomUUID(),
|
||||
"djmil.cordacheckers.gameboard.DrawRejectFlow",
|
||||
|
@ -7,7 +7,7 @@ public interface Rsp <T> {
|
||||
public T successStatus();
|
||||
public String failureStatus();
|
||||
|
||||
public default T getResponce(RequestBody requestBody) {
|
||||
public default T getResponce(RequestBody requestBody) throws RspFailureException {
|
||||
if (failureStatus() == null) {
|
||||
final var responce = successStatus();
|
||||
final String gameUuid = (responce instanceof GameView)
|
||||
@ -15,12 +15,11 @@ public interface Rsp <T> {
|
||||
: "";
|
||||
|
||||
System.out.println(requestBody.clientRequestId() +" [OK] " +gameUuid);
|
||||
|
||||
return responce;
|
||||
}
|
||||
|
||||
System.err.println(requestBody.clientRequestId() +" has failed: " +failureStatus());
|
||||
throw new RuntimeException(failureStatus());
|
||||
throw new RspFailureException(failureStatus());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package djmil.cordacheckers.cordaclient.dao.flow.arguments;
|
||||
|
||||
public class RspFailureException extends Exception {
|
||||
public RspFailureException(String what) {
|
||||
super(what);
|
||||
}
|
||||
}
|
@ -13,6 +13,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import djmil.cordacheckers.cordaclient.dao.GameView;
|
||||
import djmil.cordacheckers.cordaclient.dao.GameView.Status;
|
||||
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspFailureException;
|
||||
import djmil.cordacheckers.cordaclient.dao.Stone;
|
||||
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
||||
|
||||
@ -44,7 +45,7 @@ public class GameBoardTests {
|
||||
);
|
||||
|
||||
@Test
|
||||
void testSurrender() {
|
||||
void testSurrender() throws RspFailureException {
|
||||
final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName);
|
||||
final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName);
|
||||
|
||||
@ -81,7 +82,7 @@ public class GameBoardTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testMove() {
|
||||
void testMove() throws RspFailureException {
|
||||
final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName);
|
||||
final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName);
|
||||
|
||||
@ -193,7 +194,7 @@ public class GameBoardTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVictory_NoStones() {
|
||||
void testVictory_NoStones() throws RspFailureException {
|
||||
final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName);
|
||||
final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName);
|
||||
|
||||
@ -217,7 +218,7 @@ public class GameBoardTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVictory_StonesBlocked() {
|
||||
void testVictory_StonesBlocked() throws RspFailureException {
|
||||
final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName);
|
||||
final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName);
|
||||
|
||||
@ -241,7 +242,7 @@ public class GameBoardTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDrawRequest() {
|
||||
void testDrawRequest() throws RspFailureException {
|
||||
final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName);
|
||||
final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName);
|
||||
|
||||
@ -275,7 +276,7 @@ public class GameBoardTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDrawAccept() {
|
||||
void testDrawAccept() throws RspFailureException {
|
||||
final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName);
|
||||
final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName);
|
||||
|
||||
@ -311,7 +312,7 @@ public class GameBoardTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDrawReject() {
|
||||
void testDrawReject() throws RspFailureException {
|
||||
final var hiWhite = holdingIdentityResolver.getByUsername(whitePlayerName);
|
||||
final var hiBlack = holdingIdentityResolver.getByUsername(blackPlayerName);
|
||||
|
||||
|
@ -10,6 +10,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import djmil.cordacheckers.cordaclient.dao.GameView;
|
||||
import djmil.cordacheckers.cordaclient.dao.GameView.Status;
|
||||
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspFailureException;
|
||||
import djmil.cordacheckers.cordaclient.dao.Stone;
|
||||
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
||||
|
||||
@ -26,7 +27,7 @@ public class GameProposalTests {
|
||||
final Stone.Color acquierColor = Stone.Color.WHITE;
|
||||
|
||||
@Test
|
||||
void testCreate() {
|
||||
void testCreate() throws RspFailureException {
|
||||
final var hiIssuer = holdingIdentityResolver.getByUsername(issuer);
|
||||
final var hiAcquier = holdingIdentityResolver.getByUsername(acquier);
|
||||
final String message = "GameProposal CREATE test";
|
||||
@ -68,7 +69,7 @@ public class GameProposalTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testReject() {
|
||||
void testReject() throws RspFailureException {
|
||||
final var hiIssuer = holdingIdentityResolver.getByUsername(issuer);
|
||||
final var hiAcquier = holdingIdentityResolver.getByUsername(acquier);
|
||||
|
||||
@ -97,7 +98,7 @@ public class GameProposalTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCancel() {
|
||||
void testCancel() throws RspFailureException {
|
||||
final var hiIssuer = holdingIdentityResolver.getByUsername(issuer);
|
||||
final var hiAcquier = holdingIdentityResolver.getByUsername(acquier);
|
||||
|
||||
@ -126,7 +127,7 @@ public class GameProposalTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAccept() {
|
||||
void testAccept() throws RspFailureException {
|
||||
final var hiIssuer = holdingIdentityResolver.getByUsername(issuer);
|
||||
final var hiAcquier = holdingIdentityResolver.getByUsername(acquier);
|
||||
|
||||
|
@ -12,6 +12,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import djmil.cordacheckers.cordaclient.dao.GameView;
|
||||
import djmil.cordacheckers.cordaclient.dao.Stone.Color;
|
||||
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspFailureException;
|
||||
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
||||
|
||||
@SpringBootTest
|
||||
@ -26,7 +27,7 @@ public class GameStateTests {
|
||||
final String player2 = "bobik";
|
||||
|
||||
@Test
|
||||
void testList() {
|
||||
void testList() throws RspFailureException {
|
||||
final var hiPlayer1 = holdingIdentityResolver.getByUsername(player1);
|
||||
final var hiPlayer2 = holdingIdentityResolver.getByUsername(player2);
|
||||
|
||||
@ -46,7 +47,7 @@ public class GameStateTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGet() {
|
||||
void testGet() throws RspFailureException {
|
||||
final var hiPlayer1 = holdingIdentityResolver.getByUsername(player1);
|
||||
final var hiPlayer2 = holdingIdentityResolver.getByUsername(player2);
|
||||
|
||||
|
@ -15,6 +15,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import djmil.cordacheckers.cordaclient.dao.GameView;
|
||||
import djmil.cordacheckers.cordaclient.dao.Rank;
|
||||
import djmil.cordacheckers.cordaclient.dao.Stone;
|
||||
import djmil.cordacheckers.cordaclient.dao.flow.arguments.RspFailureException;
|
||||
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
||||
|
||||
@SpringBootTest
|
||||
@ -39,7 +40,7 @@ public class RankingTests {
|
||||
);
|
||||
|
||||
@Test
|
||||
void testSurrender() throws InvalidNameException {
|
||||
void testSurrender() throws InvalidNameException, RspFailureException {
|
||||
final var hiCustodian = holdingIdentityResolver.getCustodian();
|
||||
assertThat(hiCustodian).isNotNull();
|
||||
|
||||
@ -68,7 +69,7 @@ public class RankingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testVictory() throws InvalidNameException {
|
||||
void testVictory() throws InvalidNameException, RspFailureException {
|
||||
final var hiCustodian = holdingIdentityResolver.getCustodian();
|
||||
assertThat(hiCustodian).isNotNull();
|
||||
|
||||
@ -97,7 +98,7 @@ public class RankingTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDraw() throws InvalidNameException {
|
||||
void testDraw() throws InvalidNameException, RspFailureException {
|
||||
final var hiCustodian = holdingIdentityResolver.getCustodian();
|
||||
assertThat(hiCustodian).isNotNull();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user