using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using TMSBLL.EvaluationPlan; using TMSDAL.DTO.Evaluation.TMSDAL.DTO.EvaluationPlan; using static GB5Shared.GB5Constant.Constant; namespace TMSSL.EndPoints.EvaluationPlan { public class SaveEvaluationPlan : BaseEndpoint> { private readonly IEvaluationPlanBLL _EvaluationBLL; public SaveEvaluationPlan(IEvaluationPlanBLL evaluationBLL) { _EvaluationBLL = evaluationBLL; } public override void Configure() { Post("/EvaluationPlan/SaveEvaluationPlan"); AllowAnonymous(); } public record SaveEvaluationPlanParameters( [property: FromBody] EvaluationPlanDTO EvaluationPlan, [property: FromHeader] string Login ); protected override string? GetCacheKey(SaveEvaluationPlanParameters req, LoginDTO loginDTO) { if (req.EvaluationPlan.EvaluationPlanId <= 0) return null; return KeyGenerator.KeyGeneration(req.EvaluationPlan.EvaluationPlanId, EntityConstant.OBJECTEVALUATIONPLAN, CacheKeyLevel.CLIENT_LEVEL, loginDTO); } protected override bool ShouldInvalidateCache(SaveEvaluationPlanParameters req, LoginDTO loginDTO) => true; protected override async Task> ExecuteAsync(SaveEvaluationPlanParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _EvaluationBLL.SaveEvaluationPlan(req.EvaluationPlan, 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); } } } }