using FrameworkBLL.Program; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.EndPoints.Program { public class GetProgram : BaseEndpoint { private readonly IProgramBLL _ProgramBLL; public GetProgram(IProgramBLL IProgramBLL) { _ProgramBLL = IProgramBLL; } public override void Configure() { Get("/Program/GetProgram"); AllowAnonymous(); } public record GetProgramParameters( [property: QueryParam] int ProgramId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetProgramParameters req, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(req.ProgramId!, EntityConstant.OBJECTPROGRAM, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetProgramParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _ProgramBLL.GetProgram(req.ProgramId, LoginDTO!); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.USER_LEVEL, LoginDTO, ex.Message, 500); } } } }