using FastEndpoints; using FrameworkBLL.Taxonomy; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.Taxonomy.Course { public class GetCourse : BaseEndpoint> { private readonly ICourseBLL _CourseBLL; public GetCourse(ICourseBLL courseBLL) { _CourseBLL = courseBLL; } public override void Configure() { Get("/TaxonomyCourse/GetCourse"); AllowAnonymous(); } public record GetCourseParameters( [property: QueryParam] int CourseId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetCourseParameters req, LoginDTO loginDTO) => KeyGenerator.KeyGeneration(req.CourseId, EntityConstant.OBJECTCOURSE, CacheKeyLevel.CLIENT_LEVEL, loginDTO); protected override async Task> ExecuteAsync(GetCourseParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _CourseBLL.GetCourse(req.CourseId, loginDTO!); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.CLIENT_LEVEL, loginDTO); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response.CreateExceptionError(ex, CacheKeyLevel.CLIENT_LEVEL, loginDTO, ex.Message, 500); } } } }