using AMPBLL.OpenApiIngestion; using AmpDAL.DTO.OpenApiIngestion; using FastEndpoints; using GB5Shared.DTO.Framework.Login; using GB5Shared.DTO.Framework.ResponseStandard; using GB5Shared.FastEndPoint; using static GB5Shared.GB5Constant.Constant; namespace AmpSL.Endpoints.OpenApiIngestion; public class IngestOpenApiSpec : BaseEndpoint> { private readonly IOpenApiIngestionBLL _bll; public IngestOpenApiSpec(IOpenApiIngestionBLL bll) => _bll = bll; public override void Configure() { Post("/OpenApiIngestion/IngestOpenApiSpec"); AllowAnonymous(); } public class Request { [FromHeader] public string Login { get; set; } = string.Empty; public int ApiId { get; set; } public int ApiVersionId { get; set; } public int ApiInterfaceId { get; set; } // Frontend sends the OpenAPI spec file encoded as Base64 public string Base64Content { get; set; } = string.Empty; } protected override string? GetCacheKey(Request req, LoginDTO login) => null; protected override async Task> ExecuteAsync( Request req, LoginDTO login, CancellationToken ct) { try { var dto = new OpenApiIngestionRequestDTO { ApiId = req.ApiId, ApiVersionId = req.ApiVersionId, ApiInterfaceId = req.ApiInterfaceId, Base64Content = req.Base64Content }; var result = await _bll.IngestAsync(dto, login, ct); return await GB5Shared.ResponseStandard.Response .CreateSuccessResponse(result, CacheKeyLevel.NOT_REQUIRED, login); } catch (Exception ex) { return await GB5Shared.ResponseStandard.Response .CreateExceptionError( ex, CacheKeyLevel.NOT_REQUIRED, login, ex.Message, 500); } } }