using FrameworkDAL.DTO.DataSync; using FrameworkDAL.Query.DataSync; using GB5Shared.DTO.Framework.Login; using GB5Shared.QueryExecutor; using GB5Shared.Resource.Response; using Newtonsoft.Json; namespace FrameworkDAL.CustomCode.DataSync { public class DataSyncRunLogDAL : IDataSyncRunLogDAL { private readonly IQueryExecutor _queryExecutor; public DataSyncRunLogDAL(IQueryExecutor queryExecutor) { _queryExecutor = queryExecutor; } public async Task GetSyncRunLog(int runId, LoginDTO login, CancellationToken ct) { try { var result = await _queryExecutor.QuerySingleAsync( login, SyncRunLogQB.GET_SYNCRUNLOG, new { RunId = runId }, cancellationToken: ct).ConfigureAwait(false); return JsonConvert.SerializeObject(result); } catch (Exception ex) { throw new Exception($"Failed to retrieve SyncRunLog: {ex.Message}", ex); } } public async Task GetSyncRunLogList(int syncJobId, int offset, int pageSize, LoginDTO login, CancellationToken ct) { try { var param = new { SyncJobId = syncJobId, Offset = offset, PageSize = pageSize }; var list = await _queryExecutor.QueryAsync( login, SyncRunLogQB.GET_SYNCRUNLOG_LIST, param, cancellationToken: ct).ConfigureAwait(false); return JsonConvert.SerializeObject(list); } catch (Exception ex) { throw new Exception($"Failed to retrieve SyncRunLog list: {ex.Message}", ex); } } public async Task SaveSyncRunLog(SyncRunLogDTO dto, LoginDTO login, CancellationToken ct) { try { await _queryExecutor.ExecuteAsync( login, SyncRunLogQB.SAVE_SYNCRUNLOG, dto, cancellationToken: ct).ConfigureAwait(false); return dto.RunId; } catch (Exception ex) { throw new Exception($"{ErrorResponse.SaveErrorMessage}: {ex.Message}", ex); } } public async Task UpdateSyncRunLogComplete(SyncRunLogDTO dto, LoginDTO login, CancellationToken ct) { try { await _queryExecutor.ExecuteAsync( login, SyncRunLogQB.UPDATE_SYNCRUNLOG_COMPLETE, dto, cancellationToken: ct) .ConfigureAwait(false); } catch (Exception ex) { throw new Exception($"Failed to update SyncRunLog completion for RunId {dto.RunId}: {ex.Message}", ex); } } } }