Example #1
0
        public async Task <IActionResult> RunAsync(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "{category:alpha}")] HttpRequest httpRequest,
            ILogger logger,
            string category)
        {
            if (httpRequest is null)
            {
                throw new ArgumentNullException(nameof(httpRequest));
            }

            if (logger is null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            logger.LogInformation($"{FunctionName} started processing a request.");

            var requestType = _resolver.GetTypeByCategory(category);

            if (requestType == null)
            {
                return(new NotFoundResult());
            }

            var hubRequests = await _rehydrator.RehydrateCollectionAsync(httpRequest.Body, requestType).ConfigureAwait(false);

            if (hubRequests == null)
            {
                return(new BadRequestObjectResult("Invalid request message."));
            }

            // TODO: Downcasting to CustomHubResponse should not occur.
            // In fact, CustomHubResponse should not exist at all; either IHubResponse or HubResponse should define/implement ValidationResults
            var response = await _bulkMediator.DispatchAsync(hubRequests).ConfigureAwait(false) as CustomHubResponse;

            return(new OkObjectResult(response?.ValidationResults)
            {
                StatusCode = StatusCodes.Status202Accepted,
            });
        }
Example #2
0
 private async Task <IEnumerable <IHubMessage>?> RehydrateHubRequestsFromFile()
 {
     await using var inputRequestStream = File.OpenRead("Assets/ChangeSupplierRequestArray.json");
     return(await _hubRehydrator.RehydrateCollectionAsync(inputRequestStream, typeof(ChangeOfSupplierMessage))
            .ConfigureAwait(false));
 }