using FastEndpoints; using FrameworkBLL.RoleVsPortlet; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.RoleVsPortlet { public class GetRoleVsPortletWithRoleAndPage : BaseEndpoint> { private readonly IRoleVsPortletBLL _RoleVsPortletBLL; public GetRoleVsPortletWithRoleAndPage(IRoleVsPortletBLL IRoleVsPortletBLL) { _RoleVsPortletBLL = IRoleVsPortletBLL; } public override void Configure() { Get("/RoleVsPortlet/GetRoleVsPortletWithRoleAndPage"); AllowAnonymous(); } public record GetRoleVsPortletWithRoleAndPageParameters( [property: FromHeader] string Login, [property: QueryParam] int RoleId, [property: QueryParam] int PageId, [property: QueryParam] string SearchValue ); protected override string? GetCacheKey(GetRoleVsPortletWithRoleAndPageParameters Parameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(new { Parameters.SearchValue, Parameters.PageId, Parameters.RoleId }, EntityConstant.OBJECTROLEVSPORTLET, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetRoleVsPortletWithRoleAndPageParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _RoleVsPortletBLL.GetRoleVsPortletWithRoleAndPage(req.RoleId, req.PageId, req.SearchValue, LoginDTO!); 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); } } } }