using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using SkillManagementBLL.SkillMatrixConfig; using static GB5Shared.GB5Constant.Constant; namespace SkillManagementSL.EndPoints.SkillMatrixConfig { public class GetSkillMatrixConfig : BaseEndpoint> { private readonly ISkillMatrixConfigBLL _bll; public GetSkillMatrixConfig(ISkillMatrixConfigBLL bll) { _bll = bll; } public override void Configure() { Get("/SkillMatrixConfig/GetSkillMatrixConfig"); AllowAnonymous(); } public record GetSkillMatrixConfigParameters( [property: FromHeader] string Login, [property: QueryParam] int ConfigId ); protected override string? GetCacheKey(GetSkillMatrixConfigParameters req, LoginDTO login) { try { return $"Skill:MatrixConfig:{login.ClientId}:{req.ConfigId}"; } catch (Exception) { throw; } } protected override async Task> ExecuteAsync( GetSkillMatrixConfigParameters req, LoginDTO login, CancellationToken ct) { try { var result = req.ConfigId == 0 ? await _bll.GetList(login, ct) : await _bll.GetById(req.ConfigId, login, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.CLIENT_LEVEL, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.CLIENT_LEVEL, login, ex.Message, 500); } } } }