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 GenerateMatrixLots : BaseEndpoint> { private readonly IMatrixBLL _bll; public GenerateMatrixLots(IMatrixBLL bll) => _bll = bll; public override void Configure() { Get("/Matrix/GenerateMatrixLots"); AllowAnonymous(); Description(x => x .WithTags("Matrix") .WithSummary("Generate Matrix Lots") .WithDescription("Matrix-independent read-only preview: computes the Set View and FG View " + "serial breakdown that WOULD be generated for this allocation line, without writing " + "anything to the database. Caller passes AllotedAllocationId (e.g. from " + "GetSelectListAllocationWithItem) instead of MatrixId. SetsToGenerate controls how many " + "sets to preview (0 = all remaining ungenerated sets). Does not touch TMATRIX, " + "TMATRIXINPUT, or TMATRIXOUTPUT.")); } public record Params( [property: FromHeader] string Login, [property: QueryParam] int AllotedAllocationId, [property: QueryParam] int SetsToGenerate); 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.GenerateMatrixLotsAsync( req.AllotedAllocationId, req.SetsToGenerate, 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); } } }