57 lines
2.1 KiB
C#
57 lines
2.1 KiB
C#
using UtopiaCanteenSystem.Services.Logging;
|
|
|
|
namespace UtopiaCanteenSystem.Services;
|
|
|
|
public class OfflineCacheSyncService : IOfflineCacheSyncService
|
|
{
|
|
private readonly IEmployeeRfidTagSyncService _employeeRfidTagSync;
|
|
private readonly IMealMenuCacheSyncService _mealMenuCacheSync;
|
|
|
|
public OfflineCacheSyncService(
|
|
IEmployeeRfidTagSyncService employeeRfidTagSync,
|
|
IMealMenuCacheSyncService mealMenuCacheSync)
|
|
{
|
|
_employeeRfidTagSync = employeeRfidTagSync;
|
|
_mealMenuCacheSync = mealMenuCacheSync;
|
|
}
|
|
|
|
public async Task<OfflineCacheSyncResult> SyncEmployeeAndMenuCacheAsync(CancellationToken cancellationToken = default)
|
|
{
|
|
FileLogger.Info("CacheSync", "Full offline cache sync started (employee RFID + meal/menu).");
|
|
|
|
var employeeResult = await _employeeRfidTagSync.SyncAllAsync(cancellationToken).ConfigureAwait(false);
|
|
if (!employeeResult.Success)
|
|
{
|
|
FileLogger.Error("CacheSync", $"Full cache sync failed at employee RFID step. Error={employeeResult.ErrorMessage}");
|
|
return new OfflineCacheSyncResult
|
|
{
|
|
Success = false,
|
|
ErrorMessage = employeeResult.ErrorMessage ?? "Employee RFID cache sync failed.",
|
|
EmployeeSync = employeeResult
|
|
};
|
|
}
|
|
|
|
var mealMenuResult = await _mealMenuCacheSync.SyncAllAsync(cancellationToken).ConfigureAwait(false);
|
|
if (!mealMenuResult.Success)
|
|
{
|
|
FileLogger.Error("CacheSync", $"Full cache sync failed at meal/menu step. Error={mealMenuResult.ErrorMessage}");
|
|
return new OfflineCacheSyncResult
|
|
{
|
|
Success = false,
|
|
ErrorMessage = mealMenuResult.ErrorMessage ?? "Meal/menu cache sync failed.",
|
|
EmployeeSync = employeeResult,
|
|
MealMenuSync = mealMenuResult
|
|
};
|
|
}
|
|
|
|
FileLogger.Info("CacheSync", "Full offline cache sync completed successfully.");
|
|
|
|
return new OfflineCacheSyncResult
|
|
{
|
|
Success = true,
|
|
EmployeeSync = employeeResult,
|
|
MealMenuSync = mealMenuResult
|
|
};
|
|
}
|
|
}
|