using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using TMSBLL.Competency; using TMSDAL.DTO.Competency; using static GB5Shared.GB5Constant.Constant; namespace TMSSL.EndPoints.Competency { public class SaveCompetency : BaseEndpoint> { private readonly ICompetencyBLL _CompetencyBLL; public SaveCompetency(ICompetencyBLL competencyBLL) { _CompetencyBLL = competencyBLL; } public override void Configure() { Post("/Competency/SaveCompetency"); AllowAnonymous(); } public record SaveCompetencyParameters( [property: FromBody] CompetencyDTO CompetencyDTO, [property: FromHeader] string Login ); protected override string? GetCacheKey(SaveCompetencyParameters req, LoginDTO loginDTO) { if (req.CompetencyDTO.CompetencyId <= 0) return null; return KeyGenerator.KeyGeneration(req.CompetencyDTO.CompetencyId, EntityConstant.OBJECTCOMPETENCY, CacheKeyLevel.CLIENT_LEVEL, loginDTO); } protected override bool ShouldInvalidateCache(SaveCompetencyParameters req, LoginDTO loginDTO) => true; protected override async Task> ExecuteAsync(SaveCompetencyParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _CompetencyBLL.SaveCompetency(req.CompetencyDTO, loginDTO); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.NOT_REQUIRED, loginDTO, ex.Message, 500); } } } }