using FastEndpoints; using FrameworkBLL.MenuGroup; using FrameworkDAL.DTO.Version; using GB5Shared.DaprCache; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using IdentityModel.Client; using Newtonsoft.Json; using System.Threading; using System.Threading.Tasks; using static FrameworkSL.Endpoints.DocumentSet.GetDocumentSet; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.Menu { /// /// Endpoint to get menu for a user and module. /// public sealed class GetMenuForUserModule : BaseEndpoint { private readonly IMenuGroupBLL _menuGroupBLL; /// /// Constructor /// public GetMenuForUserModule(IMenuGroupBLL menuGroupBLL) { _menuGroupBLL = menuGroupBLL; } /// /// API Configure the endpoint route and options. /// public override void Configure() { Get("/Menu/GetMenuForUserModule"); AllowAnonymous(); } public record GetMenuForUserModuleParameters( [property: QueryParam] int UserId, [property: QueryParam] int ModuleId, [property: FromHeader] string Login ); //protected override string? GetCacheKey(GetMenuForUserModuleParameters req, LoginDTO LoginDTO) //{ // try // { // return KeyGenerator.KeyGeneration(new { req.UserId, req.ModuleId }, EntityConstant.OBJECTDOCUMENTSET, CacheKeyLevel.USER_LEVEL, LoginDTO); // } // catch (Exception) // { // throw; // } //} protected override async Task> ExecuteAsync(GetMenuForUserModuleParameters req, LoginDTO LoginDTO , CancellationToken ct) { try { var Result = await _menuGroupBLL.GetMenuTreeForUserModule(req.UserId, req.ModuleId, LoginDTO!, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(Result, CacheKeyLevel.NOT_REQUIRED, LoginDTO); } catch (Exception ex) { Logger.LogError(ex, "Error executing GetModuleList"); return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, ex.Message, 500); } } } }