/// <summary> /// DeleteFlightAsync /// </summary> /// <param name="flightNumber"></param> public async Task <IgcFlightDto> DeleteFlightAsync(int flightNumber) { var filename = _netcoupeService.GetIgcFileNameById(flightNumber); IgcFlightDto flightDto = null; try { flightDto = await _storageService.DeleteFileAsync(filename); flightDto.Id = flightNumber; } catch (FileNotFoundException e) { throw new CoreApiException(HttpStatusCode.NotFound, e.Message); } return(flightDto); }
/// <summary> /// DeleteFlightAsync /// </summary> /// <param name="flightNumber"></param> /// <param name="dryRun"></param> public async Task <IgcFlightDto> DeleteFlightAsync(int flightNumber, bool dryRun = false) { IgcFlightDto flightDto = null; if (!dryRun) { var filename = _netcoupeService.GetIgcFileNameById(flightNumber); try { flightDto = await _storageService.DeleteFileAsync(filename); flightDto.Id = flightNumber; } catch (FileNotFoundException e) { throw new CoreApiException(HttpStatusCode.NotFound, e.Message); } } // --- Dry Run : used for testing purposese else { var filename = "Dry Run: " + flightNumber; if (flightNumber % 2 == 0) { flightDto = new IgcFlightDto() { Name = filename, Status = FlightStatus.DELETED }; } else { var message = $"[DeleteFlightAsync] - DryRun - Could not find file in GCP bucket: {filename}"; _logger.LogDebug(message); throw new CoreApiException(HttpStatusCode.NotFound, message); } } return(flightDto); }
/// <summary> /// DeleteFileAsync /// </summary> /// <param name="filename"></param> public async Task <IgcFlightDto> DeleteFileAsync(string filename) { var enumerable = _storageClient.ListObjects(_configuration.StorageBucketName); var list = enumerable.ToList(); var fileFullPath = list.SingleOrDefault(o => o.Name.ToLower().Contains(filename.ToLower())); if (fileFullPath == null) { var message = $"Could not find file in GCP bucket: {filename}"; _logger.LogError(message); throw new FileNotFoundException(message); } await _storageClient.DeleteObjectAsync(_configuration.StorageBucketName, fileFullPath.Name); var flightDto = new IgcFlightDto() { Name = fileFullPath.Name, Status = FlightStatus.DELETED }; return(flightDto); }