using FastEndpoints; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using QMSBLL.Matrix; using static GB5Shared.GB5Constant.Constant; namespace QMSSL.EndPoints.Matrix; public class GetSelectableSerials : BaseEndpoint> { private readonly IMatrixBLL _bll; public GetSelectableSerials(IMatrixBLL bll) => _bll = bll; public override void Configure() { Post("/Matrix/GetSelectableSerials"); AllowAnonymous(); Description(x => x .WithTags("Matrix") .WithSummary("Get Selectable Serials") .WithDescription("Backs the \"Select Serial\" button on one FG item row. Caller sends a " + "CriteriaDTO with an ItemId field (required — which FG item's pool to fetch) and an " + "optional SerialNumber field (partial/contains text search over the picklist's LotNumbers, " + "e.g. searching \"0006\" narrows to matching entries). Returns ONE ready-to-render picklist " + "combining every previously-skipped/available number (Source=\"Available\", e.g. leftover " + "1 and 5 from an earlier 1-2-3-4-5 run where 2,3,4 were used) with the fresh never-issued " + "range (Source=\"Fresh\") — sorted, labeled, with the exact RequiredQty the user must " + "select. Pass the picked RunningNumbers back in SaveSetSerialGenration's SelectedSerials " + "to persist the choice.")); } public record Params( [property: FromHeader] string Login, [property: FromBody] CriteriaDTO CriteriaDTO); protected override string? GetCacheKey(Params req, LoginDTO login) => null; protected override async Task> ExecuteAsync( Params req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.GetSelectableSerialsAsync(req.CriteriaDTO, login, ct); return await GB5Shared.ResponseStandard.Response .CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 500); } } }