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.VirtualNodeList;
|
||||||
import djmil.cordacheckers.cordaclient.dao.flow.RequestBody;
|
import djmil.cordacheckers.cordaclient.dao.flow.RequestBody;
|
||||||
import djmil.cordacheckers.cordaclient.dao.flow.ResponseBody;
|
import djmil.cordacheckers.cordaclient.dao.flow.ResponseBody;
|
||||||
|
import djmil.cordacheckers.cordaclient.dao.flow.arguments.CreateGameProposal;
|
||||||
import djmil.cordacheckers.cordaclient.dao.flow.arguments.Empty;
|
import djmil.cordacheckers.cordaclient.dao.flow.arguments.Empty;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@ -73,13 +74,30 @@ public class CordaClient {
|
|||||||
return gameProposalsJsonString;
|
return gameProposalsJsonString;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String sendGameProposal(
|
public String createGameProposal(
|
||||||
HoldingIdentity sender,
|
HoldingIdentity sender,
|
||||||
HoldingIdentity receiver,
|
HoldingIdentity receiver,
|
||||||
Color receiverColor,
|
Color receiverColor,
|
||||||
String message
|
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) {
|
private String cordaFlowExecute(HoldingIdentity holdingIdentity, RequestBody requestBody) {
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package djmil.cordacheckers.cordaclient.dao.flow.arguments;
|
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;
|
package djmil.cordacheckers.gameproposal;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
@ -12,7 +11,9 @@ import org.springframework.web.util.UriComponentsBuilder;
|
|||||||
|
|
||||||
import djmil.cordacheckers.cordaclient.CordaClient;
|
import djmil.cordacheckers.cordaclient.CordaClient;
|
||||||
import djmil.cordacheckers.cordaclient.dao.HoldingIdentity;
|
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.Color;
|
||||||
|
import djmil.cordacheckers.cordaclient.dao.GameProposal;
|
||||||
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
import djmil.cordacheckers.user.HoldingIdentityResolver;
|
||||||
import djmil.cordacheckers.user.User;
|
import djmil.cordacheckers.user.User;
|
||||||
|
|
||||||
@ -49,17 +50,15 @@ public class GameProposalController {
|
|||||||
@PostMapping()
|
@PostMapping()
|
||||||
public ResponseEntity<Void> createGameProposal(
|
public ResponseEntity<Void> createGameProposal(
|
||||||
@AuthenticationPrincipal User sender,
|
@AuthenticationPrincipal User sender,
|
||||||
@RequestBody GameProposal gpRequest,
|
@RequestBody CreateGameProposal gpRequest,
|
||||||
UriComponentsBuilder ucb
|
UriComponentsBuilder ucb
|
||||||
) {
|
) {
|
||||||
|
|
||||||
//sender.get
|
|
||||||
final HoldingIdentity gpSender = sender.getHoldingIdentity();
|
final HoldingIdentity gpSender = sender.getHoldingIdentity();
|
||||||
// TODO: throw execption with custom type
|
// TODO: throw execption with custom type
|
||||||
final HoldingIdentity gpReceiver = holdingIdentityResolver.getByUsername(gpRequest.recipient());
|
final HoldingIdentity gpReceiver = holdingIdentityResolver.getByUsername(gpRequest.opponentName());
|
||||||
final Color gpReceiverColor = gpRequest.recipientColor();
|
final Color gpReceiverColor = gpRequest.opponentColor();
|
||||||
|
|
||||||
String newGameProposalUuid = cordaClient.sendGameProposal(
|
String newGameProposalUuid = cordaClient.createGameProposal(
|
||||||
gpSender,
|
gpSender,
|
||||||
gpReceiver,
|
gpReceiver,
|
||||||
gpReceiverColor,
|
gpReceiverColor,
|
||||||
|
Loading…
Reference in New Issue
Block a user