using FastEndpoints; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.InspectionParamSetOverride; using System.Text.Json; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.InspectionParamSetOverride { public class GetSelectListInspectionParamSetOverride : BaseEndpoint> { private readonly IInspectionParamSetOverrideBLL _bll; public GetSelectListInspectionParamSetOverride(IInspectionParamSetOverrideBLL bll) => _bll = bll; public override void Configure() { Post("/InspectionParamSetOverride/GetSelectListInspectionParamSetOverride"); AllowAnonymous(); } public record GetSelectListInspectionParamSetOverrideParameters( [property: FromHeader] string Login, [property: FromBody] CriteriaDTO CriteriaDTO, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult ); protected override async Task> ExecuteAsync( GetSelectListInspectionParamSetOverrideParameters req, LoginDTO loginDTO, CancellationToken ct) { // No server-side cache exists on this endpoint (CacheKeyLevel.NOT_REQUIRED, // no GetCacheKey override) — this is purely to stop the browser/HTTP client // from caching the response by URL, since it's a POST with query-string // params that some clients still cache. HttpContext.Response.Headers["Cache-Control"] = "no-store, no-cache, must-revalidate"; HttpContext.Response.Headers["Pragma"] = "no-cache"; try { var result = await _bll.GetPicklistInspectionParamSetOverride(req.FirstNumber, req.MaxResult, req.CriteriaDTO, loginDTO!, ct); using var doc = JsonDocument.Parse(result); var parsed = doc.RootElement.Clone(); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(parsed, CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }