using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using SkillManagementBLL.Skill; using static GB5Shared.GB5Constant.Constant; namespace SkillManagementSL.EndPoints.Skill { public class GetSkill : BaseEndpoint> { private readonly ISkillBLL _bll; public GetSkill(ISkillBLL bll) { _bll = bll; } public override void Configure() { Get("/Skill/GetSkill"); AllowAnonymous(); } public record GetSkillParameters( [property: FromHeader] string Login, [property: QueryParam] int SkillId ); protected override string? GetCacheKey(GetSkillParameters req, LoginDTO login) { try { return $"Skill:Skill:{login.ClientId}:{req.SkillId}"; } catch (Exception) { throw; } } protected override async Task> ExecuteAsync( GetSkillParameters req, LoginDTO login, CancellationToken ct) { try { // Only Get By Id var result = await _bll.GetById(req.SkillId, 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); } } } }