using FastEndpoints; using GB5Shared.DTO.Framework.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.InspectionParamSetOverride; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.InspectionParamSetOverride { public class GetInspectionParamSetOverrideDetailByCriteria : BaseEndpoint> { private readonly IInspectionParamSetOverrideBLL _bll; public GetInspectionParamSetOverrideDetailByCriteria(IInspectionParamSetOverrideBLL bll) { _bll = bll; } public override void Configure() { Post("/InspectionParamSetOverride/GetInspectionParamSetOverrideDetailByCriteria"); AllowAnonymous(); } public record GetInspectionParamSetOverrideDetailByCriteriaRequest( [property: FromHeader] string Login, [property: QueryParam] int FirstNumber, [property: QueryParam] int MaxResult, [property: FromBody] CriteriaDTO CriteriaDTO ); protected override async Task> ExecuteAsync( GetInspectionParamSetOverrideDetailByCriteriaRequest req, LoginDTO loginDTO, CancellationToken ct) { try { if (req.CriteriaDTO?.SectionCriteriaList == null || req.CriteriaDTO.SectionCriteriaList.Count == 0) return await GB5Shared.ResponseStandard.Response.CreateExceptionError( new ArgumentException("CriteriaDTO must contain at least one SectionCriteriaList entry."), CacheKeyLevel.NOT_REQUIRED, loginDTO, "Please provide valid criteria (e.g. PartyId) to fetch inspection parameter set override parameter details.", 400); var result = await _bll.GetInspectionParamSetOverrideDetailByCriteria( req.FirstNumber, req.MaxResult, req.CriteriaDTO, loginDTO!, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse( result, CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (ArgumentException ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 400); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }