using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.Inspection; using System.Text.Json; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.Inspection { public class GetInspectionResult : BaseEndpoint> { private readonly IInspectionBLL _bll; public GetInspectionResult(IInspectionBLL bll) => _bll = bll; public override void Configure() { Get("/Inspection/GetInspectionResult"); AllowAnonymous(); } public record GetInspectionResultParameters( [property: QueryParam] int InspectionDetailId, [property: FromHeader] string Login ); protected override async Task> ExecuteAsync( GetInspectionResultParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _bll.GetInspectionResultByDetail(req.InspectionDetailId, loginDTO, ct); using var doc = JsonDocument.Parse(result); var parsed = doc.RootElement.Clone(); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(parsed, CacheKeyLevel.CLIENT_LEVEL, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.CLIENT_LEVEL, loginDTO, ex.Message, 500); } } } }