using FrameworkBLL.ProgramClass; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.EndPoints.ProgramClass { public class GetProgramClass : BaseEndpoint { private readonly IProgramClassBLL _ProgramClassBLL; public GetProgramClass(IProgramClassBLL IProgramClassBLL) { _ProgramClassBLL = IProgramClassBLL; } public override void Configure() { Get("/ProgramClass/GetProgramClass"); AllowAnonymous(); } public record GetProgramClassParameters( [property: QueryParam] int ProgramClassId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetProgramClassParameters req, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(req.ProgramClassId!, EntityConstant.OBJECTPROGRAMCLASS, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetProgramClassParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var result = await _ProgramClassBLL.GetProgramClass(req.ProgramClassId, 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); } } } }