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.Subject { public class GetSubject : BaseEndpoint> { private readonly ISubjectBLL _SubjectBLL; public GetSubject(ISubjectBLL subjectBLL) { _SubjectBLL = subjectBLL; } public override void Configure() { Get("/TaxonomySubject/GetSubject"); AllowAnonymous(); } public record GetSubjectParameters( [property: QueryParam] int SubjectId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetSubjectParameters req, LoginDTO loginDTO) => KeyGenerator.KeyGeneration(req.SubjectId, EntityConstant.OBJECTSUBJECT, CacheKeyLevel.CLIENT_LEVEL, loginDTO); protected override async Task> ExecuteAsync(GetSubjectParameters req, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _SubjectBLL.GetSubject(req.SubjectId, 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); } } } }