SHA256
- Created new service: IStayExportService" for common export operations. - Updated older services to be "IStayExportFormatProvider". This services will only implement the export format. - Renamed "IStayExportServiceFactory" to "IStayExportFormatProviderFactory" as this factory now is used to get the format providers for the given format.
27 lines
836 B
C#
27 lines
836 B
C#
using System.Text.Json;
|
|
using Somnia.GuestLog.Enums.Models;
|
|
using Somnia.GuestLog.Models.DTOs;
|
|
|
|
namespace Somnia.GuestLog.Services.StayExport;
|
|
|
|
public class StayExportProviderJson : IStayExportFormatProvider
|
|
{
|
|
private const string fileExtension = "json";
|
|
|
|
public StayExportFormat GetFormat() => StayExportFormat.GuestLogJson;
|
|
public string GetFilename(DateTime exportTime)
|
|
=> $"{Enum.GetName(GetFormat())}_{exportTime.ToFileTimeUtc()}.{fileExtension}";
|
|
|
|
|
|
public async Task<StayExportFileResult> ExportDataAsync(IEnumerable<StayEntryDTO> stayList, Stream dataStream)
|
|
{
|
|
if (!stayList.Any())
|
|
{
|
|
return StayExportFileResult.NoData;
|
|
}
|
|
|
|
// Convert to JSON.
|
|
await JsonSerializer.SerializeAsync(dataStream, stayList);
|
|
return StayExportFileResult.OK;
|
|
}
|
|
} |