using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using MMBLL.Inspection; using MMDAL.DTO.Inspection; using System.Text.Json; using static GB5Shared.GB5Constant.Constant; namespace MMSL.EndPoints.Inspection { public class GetInspectionList : BaseEndpoint> { private readonly IInspectionBLL _bll; public GetInspectionList(IInspectionBLL bll) => _bll = bll; public override void Configure() { Get("/Inspection/GetInspectionList"); AllowAnonymous(); } public record GetInspectionListParameters( [property: QueryParam] int OUId, [property: QueryParam] int PeriodId, [property: QueryParam] int? InspectionTypeId, [property: QueryParam] DateTime? FromDate, [property: QueryParam] DateTime? ToDate, [property: QueryParam] int Page, [property: QueryParam] int PageSize, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetInspectionListParameters req, LoginDTO loginDTO) => null; protected override async Task> ExecuteAsync( GetInspectionListParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var request = new InspectionListRequestDTO { OUId = req.OUId, PeriodId = req.PeriodId, InspectionTypeId = req.InspectionTypeId, FromDate = req.FromDate, ToDate = req.ToDate, Page = req.Page > 0 ? req.Page : 1, PageSize = req.PageSize > 0 ? req.PageSize : 20 }; var result = await _bll.GetInspectionList(request, 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); } } } }