using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.FastEndPoint; using GB5Shared.GOP.Qualifier; using Microsoft.Extensions.Logging; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.GOP.QualifierBulkRun { public class GetQualifierBulkRunHistory : BaseEndpoint> { private readonly IBulkQualifierRunBLL _Bll; private readonly ILogger _Logger; public GetQualifierBulkRunHistory(IBulkQualifierRunBLL bll, ILogger logger) { _Bll = bll; _Logger = logger; } public override void Configure() { Get("/GOP/GetQualifierBulkRunHistory"); AllowAnonymous(); } public record GetQualifierBulkRunHistoryParameters( [property: FromHeader] string Login, [property: QueryParam] string EntityCode, [property: QueryParam] int Page, [property: QueryParam] int PageSize ); // Run status is near-real-time and changes rapidly while a run is in flight — never // cache (matches IceImport's GetImportRunHistory's identical reasoning). protected override string? GetCacheKey(GetQualifierBulkRunHistoryParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( GetQualifierBulkRunHistoryParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _Bll.GetHistoryAsync(req.EntityCode, req.Page, req.PageSize, loginDTO, ct); return await GB5Shared.ResponseStandard.Response .CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { _Logger.LogError(ex, "GetQualifierBulkRunHistory failed for EntityCode {EntityCode}", req.EntityCode); return await GB5Shared.ResponseStandard.Response .CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }