using FastEndpoints; 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 GetMatrixAllocationPreview : BaseEndpoint> { private readonly IMatrixBLL _bll; public GetMatrixAllocationPreview(IMatrixBLL bll) => _bll = bll; public override void Configure() { Get("/Matrix/GetMatrixAllocationPreview"); AllowAnonymous(); Description(x => x .WithTags("Matrix") .WithSummary("Get Matrix Allocation Preview") .WithDescription("Matrix-independent dashboard: customer/SO/sets-ordered-generated-remaining summary plus the Product Composition & Next Serial Numbers table. Caller passes AllotedAllocationId only. Sourced entirely from TPENDINGALLOCATION/TALLOCATION/MALLOCATION/MPARTY/MITEM (summary) and MBOM/TLOT/TLOTDETAIL (composition) — never touches TMATRIX, TMATRIXINPUT, or TMATRIXOUTPUT.")); } public record Params( [property: FromHeader] string Login, [property: QueryParam] int AllotedAllocationId); 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.GetMatrixAllocationPreviewAsync(req.AllotedAllocationId, login, ct); if (result is null) return await GB5Shared.ResponseStandard.Response .CreateExceptionError( new InvalidOperationException("No matrix found for this allocation."), CacheKeyLevel.NOT_REQUIRED, login, "No matrix found for this allocation.", 404); 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); } } } }