using FastEndpoints; using FrameworkBLL.RoleVsDashboard; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.RoleVsDashboard { public class GetRoleVsDashboardForUpdateUserVsDashboard : BaseEndpoint> { private readonly IRoleVsDashboardBLL _RoleVsDashboardBLL; public GetRoleVsDashboardForUpdateUserVsDashboard(IRoleVsDashboardBLL RoleVsDashboardBLL) { _RoleVsDashboardBLL = RoleVsDashboardBLL; } public override void Configure() { Get("/RoleVsDashboard/GetForUpdateUserVsDashboard"); AllowAnonymous(); } public record GetRoleVsDashboardForUpdateUserVsDashboardParameters( [property: FromHeader] string Login, [property: QueryParam] int RoleId ); // "-for-update" suffix is load-bearing — GetRoleVsDashboard uses the same RoleId/ // ObjectTypeId/CacheKeyLevel, and BaseEndpoint's cache key has no route/endpoint-type // component of its own (see the GetDimensionsForDataset/GetMeasuresForDataset collision // fixed in commit c8f3c6e50) — without a distinguishing suffix this would collide with // both GetRoleVsDashboard and GetUserVsDashboardForDeleteUserVsDashboard. protected override string? GetCacheKey(GetRoleVsDashboardForUpdateUserVsDashboardParameters Parameters, LoginDTO LoginDTO) => KeyGenerator.KeyGeneration($"{Parameters.RoleId}-for-update", EntityConstant.OBJECTROLEVSDASHBOARD, CacheKeyLevel.USER_LEVEL, LoginDTO); protected override async Task> ExecuteAsync(GetRoleVsDashboardForUpdateUserVsDashboardParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _RoleVsDashboardBLL.GetRoleVsDashboardForUpdateUserVsDashboard(req.RoleId, LoginDTO!, ct); 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); } } } }