using FastEndpoints; using FrameworkBLL.Criteria; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.EntityCriteria { public class GetEntityCriteria : BaseEndpoint> { private readonly IEntityCriteriaBLL _EntityCriteriaBLL; public GetEntityCriteria(IEntityCriteriaBLL EntityCriteriaBLL) { _EntityCriteriaBLL = EntityCriteriaBLL; } public override void Configure() { Get("/EntityCriteria/GetEntityCriteria"); AllowAnonymous(); } public record GetEntityCriteriaParameters( [property: FromHeader] string Login, [property: QueryParam] string EntityType ); protected override string? GetCacheKey(GetEntityCriteriaParameters Parameters, LoginDTO LoginDTO) => KeyGenerator.KeyGeneration(Parameters.EntityType, EntityConstant.OBJECTENTITYCRITERIA, CacheKeyLevel.CLIENT_LEVEL, LoginDTO); protected override async Task> ExecuteAsync(GetEntityCriteriaParameters req, LoginDTO LoginDTO, CancellationToken ct) { try { var Result = await _EntityCriteriaBLL.GetEntityCriteria(req.EntityType, LoginDTO!, ct); 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); } } } }