SpringBoot: Create GameProposal
This commit is contained in:
parent
beadaba27e
commit
abc31d4c03
@ -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) {
|
||||
|
@ -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) {
|
||||
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
|
||||
}
|
@ -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<Void> 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,
|
||||
|
Loading…
Reference in New Issue
Block a user