namespace Dpz.Core.Service.RepositoryServiceImpl;
public class BackupRecordService(
IRepository<BackupRecord> repository,
IMapper mapper,
ILogger<BackupRecordService> logger
) : IBackupRecordService
{
public async Task AddRecordAsync(VmBackupRecord? backupRecord)
{
if (backupRecord == null)
{
logger.LogWarning("backupRecord is null");
return;
}
var entity = mapper.Map<BackupRecord>(backupRecord);
if (entity == null)
{
logger.LogWarning("mapper backupRecord to entity fail");
return;
}
await repository.InsertAsync(entity);
}
public async Task<VmBackupRecord?> GetLastNewBackupRecordAsync(string database)
{
var entity = await repository.SearchFor(x => x.Database == database)
.OrderByDescending(x => x.Id)
.FirstOrDefaultAsync();
if (entity == null)
{
return null;
}
return mapper.Map<VmBackupRecord>(entity);
}
}