using FastEndpoints; using FrameworkBLL.ECMRights; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.ECMRights { public class GetECMRights : BaseEndpoint< GetECMRights.GetECMRightsParameters, object> { private readonly IECMRightsBLL _iecmRightsBLL; public GetECMRights(IECMRightsBLL iecmRightsBLL) { _iecmRightsBLL = iecmRightsBLL; } public override void Configure() { Get("/ECMRights/GetECMRights"); AllowAnonymous(); } public record GetECMRightsParameters( [property: QueryParam] int ECMRightsId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetECMRightsParameters GetECMRightsParameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(GetECMRightsParameters.ECMRightsId!, EntityConstant.ECMRIGHTS, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetECMRightsParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _iecmRightsBLL.GetECMRights(parameters.ECMRightsId, loginDTO!); return await GB5Shared.ResponseStandard.Response.CreateSuccessResponse(result, CacheKeyLevel.USER_LEVEL, loginDTO); } catch (Exception ex) { Console.WriteLine("Error: " + ex.ToString()); return await GB5Shared.ResponseStandard.Response.CreateExceptionError( ex, CacheKeyLevel.USER_LEVEL, loginDTO,$"{ex.Message}\n{ex.InnerException?.Message}", 500 ); } } } }