feat StayExport - Added delete for StayExports.

This commit is contained in:
Daniel-Garmig committed 2026-09-06 22:24:25 +02:00
1 parent 6fe5a5e5a3
commit 4b72e3b3d3
6 files changed
+84 -11

No files matched your search

@@ -160,13 +160,26 @@ public class StayExportService(
return Result.Ok();
}
public Task<Result> DeleteExportedFileAsync(StayExportFileDTO item)
public async Task<Result> DeleteExportedFileAsync(StayExportFileDTO item)
{
throw new NotImplementedException();
//Try to delete existing file.
if (!string.IsNullOrEmpty(item.ExportedPath))
{
bool fileDeletedFromStore = await DeleteExportFileFromStoreAsync(item);
if (!fileDeletedFromStore)
{
return Result.Fail(ResultCode.FileStorageError);
}
}
//TODO:
// - Delete file from "Store" if exists.
// - Delete entry from DB.
//Delete entry from DB.
Result deleteResult = await stayExportEntityService.DeleteStayExportAsync(item);
if (!deleteResult.IsSuccess)
{
return Result.Fail(deleteResult.ResultCode);
}
return Result.Ok();
}
@@ -194,6 +207,31 @@ public class StayExportService(
throw new InvalidOperationException($"StayExportFile - Error getting stays using params: export type invalid: {exportParams.ExportType}");
}
private async Task<bool> DeleteExportFileFromStoreAsync(StayExportFileDTO item)
{
Debug.Assert(!string.IsNullOrEmpty(item.ExportedPath));
try
{
IStore store = GetExportStore();
bool objectExist = await store.ObjectExists(item.ExportedPath);
if (!objectExist)
{
logger.LogWarning("StayExportService - File for item {id} not found in store! Skip delete!", item.Id);
return true;
}
await store.DeleteObject(item.ExportedPath);
logger.LogInformation("StayExportService - File for item {id} deleted from path {path}", item.Id, item.ExportedPath);
return true;
}
catch (Exception ex)
{
logger.LogError(ex, "StayExportService - Error deleting export file of item {id}", item.Id);
return false;
}
}
private IStore GetExportStore()
{
string? storageConnString = config.ExportStorageConnectionString;