using FastEndpoints; using FrameworkBLL.Port; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace FrameworkSL.Endpoints.Port { public class GetPort : BaseEndpoint { private readonly IPortBLL _portBLL; public GetPort(IPortBLL portBLL) { _portBLL = portBLL; } public override void Configure() { Get("/Port/GetPort"); AllowAnonymous(); } public record GetPortParameters( [property: QueryParam] int PortId, [property: FromHeader] string Login ); protected override string? GetCacheKey(GetPortParameters GetPortParameters, LoginDTO LoginDTO) { try { return KeyGenerator.KeyGeneration(GetPortParameters.PortId!, EntityConstant.OBJECTPORT, CacheKeyLevel.USER_LEVEL, LoginDTO); } catch (Exception) { throw; } } protected override async Task> ExecuteAsync(GetPortParameters parameters, LoginDTO loginDTO, CancellationToken ct) { try { var result = await _portBLL.GetPort(parameters.PortId, 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); } } } }