using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using SkillManagementBLL.SkillProductMap; using SkillManagementDAL.DTO.SkillProductMap; using static GB5Shared.GB5Constant.Constant; namespace SkillManagementSL.EndPoints.SkillProductMap { public class SaveSkillProductMap : BaseEndpoint> { private readonly ISkillProductMapBLL _bll; public SaveSkillProductMap(ISkillProductMapBLL bll) { _bll = bll; } public override void Configure() { Post("/SkillProductMap/SaveSkillProductMap"); AllowAnonymous(); } public record SaveSkillProductMapBody(int SkillId, List Maps); public record SaveSkillProductMapParameters( [property: FromHeader] string Login, [property: FromBody] SaveSkillProductMapBody Body ); protected override string? GetCacheKey(SaveSkillProductMapParameters req, LoginDTO login) => $"Skill:ProductMap:{login.ClientId}:{req.Body.SkillId}"; protected override bool ShouldInvalidateCache(SaveSkillProductMapParameters req, LoginDTO login) => true; protected override async Task> ExecuteAsync( SaveSkillProductMapParameters req, LoginDTO login, CancellationToken ct) { try { var result = await _bll.Save(req.Body.Maps, req.Body.SkillId, 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); } } } }