public async Task <IActionResult> DeleteUser(Guid id) { await _userElasticRepository.Delete(id.ToString()); _logger.LogInformation("User has been successfully deleted."); return(NoContent()); }
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?? }