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