public async Task <APIResponse> Get(string name) { _logger.LogInformation($"get request for id {name} recieved"); var id = CollectionDefinition.BuildId(name); var response = await _collectionRepository.GetById(id).ConfigureAwait(false); response.Data.ExampleJsonObject = JsonSerializer.Deserialize <object>(response.Data.ExampleJsonObjectString); if (response.Ok) { _logger.LogInformation($"fetched collection {response.Id}"); return(new APIResponse { Request = Request.ToRequestString(), Ok = true, Result = "found", Data = response.Data }); } _logger.LogInformation($"unable to fetch collection( for {id}"); return(APIResponse.NotOk(Request.ToRequestString(), "unable to fetch data from elasticsearch", HttpStatusCode.NotFound, response.Id)); }
private async Task <CollectionDefinition> GetCollection(string collectionName) { var id = CollectionDefinition.BuildId(collectionName); var response = await _collectionRepository.GetById(id).ConfigureAwait(false); if (response.Ok) { return(response.Data); } return(null); }
public async Task <APIResponse> Delete(string name) { var id = CollectionDefinition.BuildId(name); _logger.LogInformation($"delete request recieved for id {id}"); var collectionResponse = await _collectionRepository.GetById(id); if (!collectionResponse.Ok) { return(APIResponse.NotOk(Request.ToRequestString(), $"unable to delete data from elasticsearch, collection {name} not found", HttpStatusCode.NotFound)); } await _collectionRepository.GetElasticBand().GetClient().DeleteAsync(collectionResponse.Data.Index); _logger.LogInformation($"deleted index {collectionResponse.Data.Index}"); var deleteResponse = await _collectionRepository.Delete(id).ConfigureAwait(false); if (deleteResponse.Ok) { _logger.LogInformation($"deleted collection {name}"); return(new APIResponse { Request = Request.ToRequestString(), Ok = true, Result = "deleted", Data = deleteResponse.Id }); } _logger.LogInformation($"unable to delete collection with id {name} {deleteResponse.StatusCode}"); return(APIResponse.NotOk(Request.ToRequestString(), "unable to delete data from elasticsearch", HttpStatusCode.NotFound, deleteResponse.Id)); // TODO could do with logging helper which creates a trace id and logs request and response data automatically? // or stores up messages and appends them all as one log per request?? }