public virtual IActionResult CreateProposal([FromRoute][Required] string subscriptionId, [FromRoute][Required] string proposalId, [FromBody] Proposal demandProposal) { var clientContext = this.HttpContext.Items["ClientContext"] as GolemClientMockAPI.Entities.ClientContext; var subscription = this.SubscriptionRepository.GetDemandSubscription(subscriptionId); if (subscription == null) { return(StatusCode(404)); // Not Found } if (clientContext.NodeId != subscription.Demand.NodeId) { return(StatusCode(401)); // Unauthorized } var demandEntity = new GolemClientMockAPI.Entities.Demand() { NodeId = clientContext.NodeId, Constraints = demandProposal.Constraints, Properties = demandProposal.Properties as Dictionary <string, string> }; try { var demandProposalEntity = this.MarketProcessor.CreateDemandProposal(subscriptionId, proposalId, demandEntity); return(new ObjectResult(demandProposalEntity.Id)); } catch (Exception exc) { return(StatusCode(404)); // Not Found } }
public virtual IActionResult CreateProposalDemand([FromBody] Proposal demandProposal, [FromRoute][Required] string subscriptionId, [FromRoute][Required] string proposalId) { var clientContext = this.HttpContext.Items["ClientContext"] as GolemClientMockAPI.Entities.ClientContext; var subscription = this.SubscriptionRepository.GetDemandSubscription(subscriptionId); if (subscription == null) { return(StatusCode(404, new ErrorMessage() { })); // Not Found } if (clientContext.NodeId != subscription.Demand.NodeId) { return(StatusCode(401, new ErrorMessage() { })); // Unauthorized } var demandEntity = new GolemClientMockAPI.Entities.Demand() { NodeId = clientContext.NodeId, Constraints = demandProposal.Constraints, Properties = PropertyMappers.MapFromJsonString(demandProposal.Properties?.ToString()) }; try { var demandProposalEntity = this.MarketProcessor.CreateDemandProposal(subscriptionId, proposalId, demandEntity); this._logger.LogWithProperties(LogLevel.Information, clientContext?.NodeId, "Requestor", subscription?.Id, $"CreateProposalDemand (Offer Proposal Id: {proposalId}, created Demand Proposal Id: {demandProposalEntity.Id})"); return(StatusCode(201, demandProposalEntity.Id)); } catch (Exception exc) { return(StatusCode(404, new ErrorMessage() { Message = $"creating demand proposal: {proposalId}, {demandEntity} error: {exc.Message}" })); // Not Found } }