public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "paths/{path}")] HttpRequest req,
            string path)
        {
            _loggerHelper.LogMethodEnter(_logger);

            var correlationId = _httpRequestHelper.GetOrCreateDssCorrelationId(req);

            if (string.IsNullOrWhiteSpace(path))
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.UnableToLocatePathInQueryString);
                return(new BadRequestResult());
            }

            _loggerHelper.LogInformationMessage(_logger, correlationId, $"Attempting to get path {path}");
            var pathModel = await _pathService.Get(path);

            if (pathModel == null)
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.PathDoesNotExist);
                return(new NoContentResult());
            }

            _loggerHelper.LogMethodExit(_logger);

            return(new OkObjectResult(pathModel));
        }
        public async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = "paths")] HttpRequest req)
        {
            _loggerHelper.LogMethodEnter(_logger);

            var correlationId = _httpRequestHelper.GetOrCreateDssCorrelationId(req);

            var body = await req.GetBodyAsync <PathModel>();

            if (body == null || body.Value == null)
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.PayloadMalformed);
                return(new BadRequestResult());
            }

            if (!body.IsValid)
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, string.Concat(Message.ValidationFailed, " ", body.ValidationResults));
                return(new BadRequestObjectResult(body.ValidationResults));
            }

            try
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, "Attempting to register path");
                var registeredPath = await _pathService.Register(body.Value);

                _loggerHelper.LogMethodExit(_logger);
                return(new CreatedResult(registeredPath.Path, registeredPath));
            }
            catch (Exception ex)
            {
                _loggerHelper.LogException(_logger, correlationId, ex);
                return(new UnprocessableEntityObjectResult(ex));
            }
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", Route = "paths")] HttpRequest req)
        {
            _loggerHelper.LogMethodEnter(_logger);

            var correlationId = _httpRequestHelper.GetOrCreateDssCorrelationId(req);

            _loggerHelper.LogInformationMessage(_logger, correlationId, $"Attempting to get all paths");
            var result = await _pathService.GetAll();

            _loggerHelper.LogMethodExit(_logger);

            return(new OkObjectResult(result));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "put", Route = "paths/{path}")] HttpRequest req,
            string path)
        {
            _loggerHelper.LogMethodEnter(_logger);

            var correlationId = _httpRequestHelper.GetOrCreateDssCorrelationId(req);

            if (string.IsNullOrEmpty(path))
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.UnableToLocatePathInQueryString);
                return(new BadRequestResult());
            }

            var body = await req.GetBodyAsync <PathModel>();

            if (body == null || body.Value == null)
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.PayloadMalformed);
                return(new BadRequestResult());
            }

            if (!body.IsValid)
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.ValidationFailed);
                return(new BadRequestObjectResult(body.ValidationResults));
            }

            _loggerHelper.LogInformationMessage(_logger, correlationId, $"Attempting to get path for {path}");
            var currentPath = await _pathService.Get(path);

            if (currentPath == null)
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.PathDoesNotExist);
                return(new NoContentResult());
            }

            try
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, $"Attempting to get update path for {path}");
                await _pathService.Update(body.Value);

                _loggerHelper.LogMethodExit(_logger);
                return(new OkResult());
            }
            catch (Exception ex)
            {
                _loggerHelper.LogException(_logger, correlationId, ex);
                return(new UnprocessableEntityObjectResult(ex));
            }
        }
Ejemplo n.º 5
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "patch", Route = "paths/{path}/regions/{pageRegion}")]
            HttpRequest req,
            ILogger log,
            string path,
            int pageRegion,
            [Inject] ILoggerHelper loggerHelper,
            [Inject] IHttpRequestHelper httpRequestHelper,
            [Inject] IHttpResponseMessageHelper httpResponseMessageHelper,
            [Inject] IJsonHelper jsonHelper,
            [Inject] IRegionService regionService
            )
        {
            loggerHelper.LogMethodEnter(log);

            // validate the parameters are present
            var correlationId = httpRequestHelper.GetOrCreateDssCorrelationId(req);

            if (string.IsNullOrEmpty(path))
            {
                loggerHelper.LogInformationMessage(log, correlationId, $"Missing value in request for '{nameof(path)}'");
                return(httpResponseMessageHelper.BadRequest());
            }

            if (pageRegion == 0 || !Enum.IsDefined(typeof(PageRegions), pageRegion))
            {
                loggerHelper.LogInformationMessage(log, correlationId, $"Missing/invalid value in request for '{nameof(pageRegion)}'");
                return(httpResponseMessageHelper.BadRequest());
            }

            PageRegions pageRegionValue = (PageRegions)pageRegion;

            JsonPatchDocument <Region> regionPatch;

            try
            {
                regionPatch = await httpRequestHelper.GetResourceFromRequest <JsonPatchDocument <Region> >(req);

                if (regionPatch == null)
                {
                    loggerHelper.LogException(log, correlationId, "Request body is empty", null);
                    return(httpResponseMessageHelper.BadRequest());
                }
            }
            catch (Exception ex)
            {
                loggerHelper.LogException(log, correlationId, ex);
                return(httpResponseMessageHelper.BadRequest());
            }

            loggerHelper.LogInformationMessage(log, correlationId, $"Attempting to get Region {pageRegionValue} for Path {path}");

            var currentRegion = await regionService.GetAsync(path, pageRegionValue);

            if (currentRegion == null)
            {
                loggerHelper.LogInformationMessage(log, correlationId, $"Region does not exist for {pageRegionValue} for Path {path}");
                return(httpResponseMessageHelper.NoContent());
            }

            try
            {
                loggerHelper.LogInformationMessage(log, correlationId, $"Attempting to apply patch to {path} region {pageRegionValue}");
                regionPatch?.ApplyTo(currentRegion);
                var validationResults = currentRegion.Validate(new ValidationContext(currentRegion));

                if (validationResults.Any())
                {
                    loggerHelper.LogInformationMessage(log, correlationId, "Validation Failed");
                    return(httpResponseMessageHelper.UnprocessableEntity(validationResults.ToList()));
                }
            }
            catch (Exception ex)
            {
                loggerHelper.LogException(log, correlationId, ex);
                return(httpResponseMessageHelper.BadRequest());
            }

            try
            {
                loggerHelper.LogInformationMessage(log, correlationId, $"Attempting to update path {path}");
                var patchedRegion = await regionService.ReplaceAsync(currentRegion);

                loggerHelper.LogMethodExit(log);
                return(httpResponseMessageHelper.Ok(jsonHelper.SerializeObjectAndRenameIdProperty(patchedRegion, "id", nameof(Models.Region.DocumentId))));
            }
            catch (Exception ex)
            {
                loggerHelper.LogException(log, correlationId, ex);
                return(httpResponseMessageHelper.UnprocessableEntity(new JsonException(ex.Message, ex)));
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "patch", Route = "paths/{path}")] HttpRequest req,
            string path)
        {
            _loggerHelper.LogMethodEnter(_logger);

            var correlationId = _httpRequestHelper.GetOrCreateDssCorrelationId(req);

            if (string.IsNullOrWhiteSpace(path))
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.UnableToLocatePathInQueryString);
                return(new BadRequestResult());
            }

            JsonPatchDocument <PathModel> pathPatch = null;

            try
            {
                var requestBody = await req.ReadAsStringAsync();

                pathPatch = JsonConvert.DeserializeObject <JsonPatchDocument <PathModel> >(requestBody);
            }
            catch (Exception ex)
            {
                _loggerHelper.LogException(_logger, correlationId, ex);
                return(new BadRequestResult());
            }

            _loggerHelper.LogInformationMessage(_logger, correlationId, $"Attempting to get path {path}'");
            var currentPath = await _pathService.Get(path);

            if (currentPath == null)
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, Message.PathDoesNotExist);
                return(new NoContentResult());
            }

            try
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, $"Attempting to apply patch to {path}");
                pathPatch.ApplyTo(currentPath);
                var validationResults = currentPath.Validate(new ValidationContext(currentPath));

                if (validationResults.Any())
                {
                    _loggerHelper.LogInformationMessage(_logger, correlationId, Message.ValidationFailed);
                    return(new BadRequestObjectResult(validationResults));
                }
            }
            catch (Exception ex)
            {
                _loggerHelper.LogException(_logger, correlationId, ex);
                return(new BadRequestResult());
            }

            try
            {
                _loggerHelper.LogInformationMessage(_logger, correlationId, $"Attempting to update path {path}");
                await _pathService.Update(currentPath);

                _loggerHelper.LogMethodExit(_logger);
                return(new OkObjectResult(currentPath));
            }
            catch (Exception ex)
            {
                _loggerHelper.LogException(_logger, correlationId, ex);
                return(new UnprocessableEntityObjectResult(ex));
            }
        }