using FastEndpoints; using FrameworkBLL.RoleVsMenu; using FrameworkDAL.DTO.RoleVsMenu; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.RoleVsMenu { public sealed class SaveRoleVsMenu : BaseEndpoint { private readonly IRoleVsMenuBLL _RoleVsMenuBLL; public SaveRoleVsMenu(IRoleVsMenuBLL RoleVsMenuBLL) { _RoleVsMenuBLL = RoleVsMenuBLL; } public override void Configure() { Post("/RoleVsMenu/SaveRoleVsMenu"); AllowAnonymous(); } public record SaveRoleVsMenuParameters( [property: QueryParam] int ModuleId, [property: QueryParam] int PageId, [property: FromBody] List RoleVsMenuDTO, [property: FromHeader] string Login ); protected override async Task> ExecuteAsync(SaveRoleVsMenuParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _RoleVsMenuBLL.Save(req.ModuleId, req.PageId, req.RoleVsMenuDTO, LoginDTO!); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(Result, CacheKeyLevel.NOT_REQUIRED, LoginDTO); } catch (Exception ex) { Logger.LogError(ex, "Error executing SaveRoleVsMenu"); return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, LoginDTO, ex.Message, 500); } } } }