/// <summary> /// Delete Historic Records for Specified Airline, Reporting Period, ReportType (GCP SchemaId) and Year /// </summary> /// <param name="iaocCode">Airline Code</param> /// <param name="reportPeriod">Report Period - Annual, Q1, Q2</param> /// <param name="schemaId">GCP SchemaId e.g. raw-income-statement</param> /// <param name="year">Report Year</param> /// <returns>Command Response</returns> public async Task <CommandResponse> DeleteHistoricRecordsAsync(string iaocCode, ReportPeriod reportPeriod, string schemaId, int year) { CommandResponse response = new CommandResponse { Information = $"Deleting Historic Reports for:{iaocCode} period:{reportPeriod} type:{schemaId} year:{year}", Success = true }; try { var deleteList = _reportDataService.GetReportDocumentsForDeletions(iaocCode, reportPeriod, schemaId, year); if (deleteList != null) { var token = _clientTokenHandler.GetValidToken(); foreach (Guid documentId in deleteList) { // DELETE Document from GCP var gcpDeletionResponse = await _documentDeletionProcessor.DeleteDocumentAsync(schemaId, documentId.ToString(), token, CancellationToken.None); if (gcpDeletionResponse == true) { // Delete Report in Document Service Database var documentAPIResponse = _reportDataService.DeleteReport(documentId.ToString()); if (documentAPIResponse != null && !documentAPIResponse.Success) { response.Success = false; } } else { response.Success = false; _logger.LogWarning($"FAILED to DELETE Document from GCP for:{iaocCode} period:{reportPeriod} type:{schemaId} year:{year}"); } } if (!response.Success) { _logger.LogWarning($"FAILED to DELETE ALL Historic Documents for :{iaocCode} period:{reportPeriod} type:{schemaId} year:{year}"); } } } catch (Exception ex) { _logger.LogError(ex.Message); response.FaultMessage = ex.Message; response.Success = false; } return(response); }
public void Delete(string schemaId, string documentId) { documentId = documentId.ToLowerInvariant(); // Get GCP Auth0 Token var clientToken = _clientTokenHandler.GetValidToken(); // DELETE Document from GCP var gcpDeletionResponse = _documentDeletionProcessor.DeleteDocumentAsync(schemaId, documentId, clientToken, CancellationToken.None).GetAwaiter().GetResult(); if (gcpDeletionResponse == true) { // Delete Report in Database var response = _reportDataService.DeleteReport(documentId); if (response.Success) { _logger.LogInformation($"Successfully Deleted Document with Id:{documentId}"); } } }