using FastEndpoints; using FrameworkBLL.PortLet; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.PortLet { public class GetPortletListWithCriteria : BaseEndpoint> { private readonly IPortletBLL _PortletBLL; public GetPortletListWithCriteria(IPortletBLL IPortletBLL) { _PortletBLL = IPortletBLL; } public override void Configure() { Get("/Portlet/GetPortletListWithCriteria"); AllowAnonymous(); } public record GetPortletListWithCriteriaParameters( [property: FromHeader] string Login, [property: QueryParam] int UserId, [property: QueryParam] int PageId, [property: QueryParam] int? DashboardId ); protected override string? GetCacheKey(GetPortletListWithCriteriaParameters Parameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(new { Parameters.PageId, Parameters.UserId, DashboardId = Parameters.DashboardId ?? -1 }, EntityConstant.OBJECTPORTLET, CacheKeyLevel.ROLE_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetPortletListWithCriteriaParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { // DashboardId omitted -> -1 sentinel: tier 4 (dashboard-level filter) is skipped // entirely, reproducing pre-Phase-3 behavior for any caller not yet passing it // (e.g. reportviewer's View=4 usage). var Result = await _PortletBLL.GetPortletListWithCriteria(req.UserId, req.PageId, LoginDTO!, req.DashboardId ?? -1); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(Result, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.USER_LEVEL, LoginDTO, ex.Message, 500); } } } }