using FastEndpoints; using FrameworkBLL.UserVsDashboard; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.UserVsDashboard { public class GetUserVsDashboard : BaseEndpoint> { private readonly IUserVsDashboardBLL _UserVsDashboardBLL; public GetUserVsDashboard(IUserVsDashboardBLL UserVsDashboardBLL) { _UserVsDashboardBLL = UserVsDashboardBLL; } public override void Configure() { Get("/UserVsDashboard/GetUserVsDashboard"); AllowAnonymous(); } public record GetUserVsDashboardParameters( [property: FromHeader] string Login, [property: QueryParam] int UserId ); protected override string? GetCacheKey(GetUserVsDashboardParameters Parameters, LoginDTO LoginDTO) => KeyGenerator.KeyGeneration(Parameters.UserId, EntityConstant.OBJECTUSERVSDASHBOARD, CacheKeyLevel.USER_LEVEL, LoginDTO); protected override async Task> ExecuteAsync(GetUserVsDashboardParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _UserVsDashboardBLL.GetUserVsDashboard(req.UserId, 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); } } } }