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