using FastEndpoints;
using GB5Shared.DTO.Framework.Login;
using GB5Shared.DTO.Framework.ResponseStandard;
using GB5Shared.FastEndPoint;
using TCMSBLL.Interfaces;
using static GB5Shared.GB5Constant.Constant;
namespace TCMSSL.EndPoints.Defect;
///
/// GET /TCMS/Defect/GetDefectPatternList
/// Returns the curated root-cause pattern library (TTCMSDEFECTPATTERN).
/// Used to populate the pattern dropdown when doing RCA on a defect and
/// to drive the CAPA gap report cross-module heatmap.
///
public class GetDefectPatternList : BaseEndpoint>
{
private readonly ITCMSDefectBLL _Bll;
public GetDefectPatternList(ITCMSDefectBLL bll) => _Bll = bll;
public override void Configure()
{
Get("/TCMS/Defect/GetDefectPatternList");
AllowAnonymous();
}
public record Params(
[property: FromHeader] string Login
);
protected override string? GetCacheKey(Params req, LoginDTO loginDTO)
=> KeyGenerator.KeyGeneration("all", EntityConstant.OBJECTTCMSDEFECT, CacheKeyLevel.CLIENT_LEVEL, loginDTO);
protected override async Task> ExecuteAsync(
Params req, LoginDTO loginDTO, CancellationToken ct)
{
var result = await _Bll.GetDefectPatternListAsync(loginDTO, ct);
return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(
result, CacheKeyLevel.CLIENT_LEVEL, loginDTO);
}
}