diff --git a/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java b/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java index 7b6e0e0..016df80 100644 --- a/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java +++ b/backend/src/main/java/djmil/cordacheckers/cordaclient/CordaClient.java @@ -22,6 +22,7 @@ import djmil.cordacheckers.cordaclient.dao.VirtualNode; import djmil.cordacheckers.cordaclient.dao.VirtualNodeList; import djmil.cordacheckers.cordaclient.dao.flow.RequestBody; import djmil.cordacheckers.cordaclient.dao.flow.ResponseBody; +import djmil.cordacheckers.cordaclient.dao.flow.arguments.CreateGameProposal; import djmil.cordacheckers.cordaclient.dao.flow.arguments.Empty; @Service @@ -63,23 +64,40 @@ public class CordaClient { "list-" + UUID.randomUUID(), "djmil.cordacheckers.gameproposal.ListFlow", new Empty() - ); + ); final String gameProposalsJsonString = cordaFlowExecute( holdingIdentity, requestBody - ); + ); return gameProposalsJsonString; } - public String sendGameProposal( + public String createGameProposal( HoldingIdentity sender, HoldingIdentity receiver, Color receiverColor, String message ) { - return ""; + final CreateGameProposal createGameProposal = new CreateGameProposal( + receiver.x500Name(), + receiverColor, + message + ); + + final RequestBody requestBody = new RequestBody( + "create-" + UUID.randomUUID(), + "djmil.cordacheckers.gameproposal.CreateFlow", + createGameProposal + ); + + final String createdGameProposalUuid = cordaFlowExecute( + sender, + requestBody + ); + + return createdGameProposalUuid; } private String cordaFlowExecute(HoldingIdentity holdingIdentity, RequestBody requestBody) { diff --git a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/CreateGameProposal.java b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/CreateGameProposal.java index 9856d33..42796f2 100644 --- a/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/CreateGameProposal.java +++ b/backend/src/main/java/djmil/cordacheckers/cordaclient/dao/flow/arguments/CreateGameProposal.java @@ -1,5 +1,7 @@ package djmil.cordacheckers.cordaclient.dao.flow.arguments; -public record CreateGameProposal(String opponentName, String opponentColor, String additionalMessage) { +import djmil.cordacheckers.cordaclient.dao.Color; + +public record CreateGameProposal(String opponentName, Color opponentColor, String message) { } diff --git a/backend/src/main/java/djmil/cordacheckers/gameproposal/GameProposal.java b/backend/src/main/java/djmil/cordacheckers/gameproposal/GameProposal.java deleted file mode 100644 index 00aac21..0000000 --- a/backend/src/main/java/djmil/cordacheckers/gameproposal/GameProposal.java +++ /dev/null @@ -1,12 +0,0 @@ -package djmil.cordacheckers.gameproposal; - -import djmil.cordacheckers.cordaclient.dao.Color; - -public record GameProposal( - String sender, - String recipient, - Color recipientColor, - String message) -{ - -} diff --git a/backend/src/main/java/djmil/cordacheckers/gameproposal/GameProposalController.java b/backend/src/main/java/djmil/cordacheckers/gameproposal/GameProposalController.java index 46d584d..26bb254 100644 --- a/backend/src/main/java/djmil/cordacheckers/gameproposal/GameProposalController.java +++ b/backend/src/main/java/djmil/cordacheckers/gameproposal/GameProposalController.java @@ -1,7 +1,6 @@ package djmil.cordacheckers.gameproposal; import java.net.URI; -import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; @@ -12,7 +11,9 @@ import org.springframework.web.util.UriComponentsBuilder; import djmil.cordacheckers.cordaclient.CordaClient; import djmil.cordacheckers.cordaclient.dao.HoldingIdentity; +import djmil.cordacheckers.cordaclient.dao.flow.arguments.CreateGameProposal; import djmil.cordacheckers.cordaclient.dao.Color; +import djmil.cordacheckers.cordaclient.dao.GameProposal; import djmil.cordacheckers.user.HoldingIdentityResolver; import djmil.cordacheckers.user.User; @@ -49,17 +50,15 @@ public class GameProposalController { @PostMapping() public ResponseEntity createGameProposal( @AuthenticationPrincipal User sender, - @RequestBody GameProposal gpRequest, + @RequestBody CreateGameProposal gpRequest, UriComponentsBuilder ucb ) { - - //sender.get final HoldingIdentity gpSender = sender.getHoldingIdentity(); // TODO: throw execption with custom type - final HoldingIdentity gpReceiver = holdingIdentityResolver.getByUsername(gpRequest.recipient()); - final Color gpReceiverColor = gpRequest.recipientColor(); + final HoldingIdentity gpReceiver = holdingIdentityResolver.getByUsername(gpRequest.opponentName()); + final Color gpReceiverColor = gpRequest.opponentColor(); - String newGameProposalUuid = cordaClient.sendGameProposal( + String newGameProposalUuid = cordaClient.createGameProposal( gpSender, gpReceiver, gpReceiverColor,