Exemplo n.º 1
0
        public async Task <APIResponse> Post(string name, string exampleIdPattern, [FromBody] ExpandoObject exampleJsonObject)
        {
            _logger.LogInformation($"post request recieved");

            var collectionDefinition = new CollectionDefinition
            {
                Name                    = name.ToLower(),
                ExampleIdPattern        = exampleIdPattern,
                ExampleJsonObjectString = JsonSerializer.Serialize <object>(exampleJsonObject, new JsonSerializerOptions {
                    WriteIndented = true
                })
            };

            var response = await _collectionRepository.Index(collectionDefinition.Id, collectionDefinition).ConfigureAwait(false);

            if (response.Ok)
            {
                _logger.LogInformation($"posted collection {response.Result} {response.Id}");
                return(new APIResponse
                {
                    Request = Request.ToRequestString(),
                    Ok = true,
                    Result = response.Result,
                    StatusCode = response.StatusCode,
                    Data = response.Id
                });
            }

            _logger.LogInformation($"unable to post collection to elasticsearch {response.StatusCode}");
            return(APIResponse.NotOk(Request.ToRequestString(), "unable to post data to elasticsearch", HttpStatusCode.BadRequest, response.Id));
        }