using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using SkillManagementBLL.RoleSkillRequirement; using SkillManagementDAL.DTO.RoleSkillRequirement; using static GB5Shared.GB5Constant.Constant; namespace SkillManagementSL.EndPoints.RoleSkillRequirement { public class SaveRoleSkillRequirement : BaseEndpoint> { private readonly IRoleSkillRequirementBLL _bll; public SaveRoleSkillRequirement(IRoleSkillRequirementBLL bll) { _bll = bll; } public override void Configure() { Post("/RoleSkillRequirement/SaveRoleSkillRequirement"); AllowAnonymous(); } public record SaveRoleSkillRequirementBody(int RoleId, string? RoleCode, string? RoleName, List Requirements); public record SaveRoleSkillRequirementParameters( [property: FromHeader] string Login, [property: FromBody] SaveRoleSkillRequirementBody Body ); protected override string? GetCacheKey(SaveRoleSkillRequirementParameters req, LoginDTO login) => $"Skill:RoleReq:{login.ClientId}:{req.Body.RoleId}"; protected override bool ShouldInvalidateCache(SaveRoleSkillRequirementParameters req, LoginDTO login) => true; protected override async Task> ExecuteAsync( SaveRoleSkillRequirementParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.Save(req.Body.Requirements, req.Body.RoleId, req.Body.RoleCode, req.Body.RoleName, login, ct); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 500); } } } }