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