public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = null)]
            [RequestBodyType(typeof(GetNewRequestActionsRequest), "get new request actions")] GetNewRequestActionsRequest req,
            CancellationToken cancellationToken)
        {
            try
            {
                if (req.IsValid(out var validationResults))
                {
                    GetNewRequestActionsResponse response = await _mediator.Send(req, cancellationToken);

                    return(new OkObjectResult(ResponseWrapper <GetNewRequestActionsResponse, GroupServiceErrorCode> .CreateSuccessfulResponse(response)));
                }
                else
                {
                    return(new ObjectResult(ResponseWrapper <GetNewRequestActionsResponse, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.ValidationError, validationResults))
                    {
                        StatusCode = 422
                    });
                }
            }
            catch (Exception ex)
            {
                _logger.LogErrorAndNotifyNewRelic($"Unhandled error in GetNewRequestActions", ex);
                return(new ObjectResult(ResponseWrapper <GetNewRequestActionsResponse, GroupServiceErrorCode> .CreateUnsuccessfulResponse(GroupServiceErrorCode.InternalServerError, "Internal Error"))
                {
                    StatusCode = StatusCodes.Status500InternalServerError
                });
            }
        }
Ejemplo n.º 2
0
        public async Task <GetNewRequestActionsResponse> GetNewRequestActions(GetNewRequestActionsRequest request, CancellationToken cancellationToken)
        {
            string path = $"api/GetNewRequestActions";

            using (HttpResponseMessage response = await _httpClientWrapper.GetAsync(HttpClientConfigName.GroupService, path, request, cancellationToken).ConfigureAwait(false))
            {
                response.EnsureSuccessStatusCode();
                string content = await response.Content.ReadAsStringAsync();

                var jsonResponse = JsonConvert.DeserializeObject <ResponseWrapper <GetNewRequestActionsResponse, GroupServiceErrorCode> >(content);
                if (jsonResponse.IsSuccessful)
                {
                    return(jsonResponse.Content);
                }
            }
            throw new Exception("Unable to get new request actions");
        }