public async Task <ApiResponseWrapper <WebhookResponse> > NotifyAsync(WebhookParameters webhookParameters)
 {
     try
     {
         return(webhookParameters.EntityType switch
         {
             WebhookConstants.TradingWebhook => await Notification(webhookParameters),
             _ => new ApiResponseWrapper <WebhookResponse>
             {
                 Status = ApiConstants.FailedResult,
                 Message = $"Unknown webhook entity type ({webhookParameters.EntityType})",
                 Data = new WebhookResponse
                 {
                     Entity = webhookParameters.Entity,
                     Webhook = webhookParameters.Webhook
                 }
             }
         });
     }
Example #2
0
        public async Task <IActionResult> Notification([FromHeader] string apiJwtToken, [FromHeader] string subscriberId, [FromBody] WebhookRequest webhookRequest)
        {
            try
            {
                var webhookParameters = new WebhookParameters
                {
                    ApiJwtToken    = apiJwtToken,
                    Webhook        = webhookRequest.Webhook,
                    Entity         = webhookRequest.Entity,
                    EntityType     = webhookRequest.EntityType,
                    SubscriberId   = subscriberId,
                    Body           = webhookRequest.Body,
                    RequestHeaders = Request.Headers.ToDictionary(k => k.Key, v => v)
                };

                var webhookResponse = await notificationService.NotifyAsync(webhookParameters);

                return(webhookResponse.Status == ApiConstants.SuccessResult
                    ? Ok(webhookResponse)
                    : BadRequest(webhookResponse));
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "{Message}", ex.Message);
                return(BadRequest(new ApiResponseWrapper <WebhookResponse>
                {
                    Message = ex.Message,
                    Status = ApiConstants.FailedResult,
                    StatusCode = (int?)HttpStatusCode.BadRequest,
                    Data = new WebhookResponse
                    {
                        Webhook = webhookRequest.Webhook
                    }
                }));
            }
        }