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