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