Пример #1
0
        public async Task <IActionResult> PostAlert([FromBody] PostAlertModel alert)
        {
            var createAlertCommand = new CreateAlertCommand(alert.Id, alert.AdresLine1, alert.AdresLine2, alert.ZipCode, alert.LoginName);

            _commandBus.Send(createAlertCommand);
            return(Created(new Uri($"{BaseUrl.Current}/api/v1.0/confirmations/{alert.Id}"), alert.Id));
        }
Пример #2
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req,
            ILogger log, CancellationToken cancellationToken)
        {
            try
            {
                var qs = req.Query;

                if (!qs.ContainsKey("apiKey"))
                {
                    return(new BadRequestErrorMessageResult("Missing query param: apiKey"));
                }

                var  apiKey       = qs["apiKey"];
                bool isAuthorized = apiKey == Environment.GetEnvironmentVariable("NcziApiKey");

                if (!isAuthorized)
                {
                    log.LogWarning("Unauthorized call.");
                    return(new UnauthorizedResult());
                }

                string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
                var    data        = JsonConvert.DeserializeObject <CreateAlertRequest>(requestBody);

                var command = new CreateAlertCommand(data.CovidPass, data.Content, data.WithPushNotification, data.PushSubject, data.PushBody);
                await mediator.Send(command, cancellationToken);

                return(new OkResult());
            }
            catch (DomainException ex)
            {
                var errors = validation.ProcessErrors(ex);
                return(new BadRequestObjectResult(errors));
            }
        }
Пример #3
0
 public Task <Response <Alert> > CreateAlert(CreateAlertCommand command)
 {
     return(_context.CreateAlert(command));
 }