121 lines
4.7 KiB
C#
121 lines
4.7 KiB
C#
using Microsoft.AspNetCore.Mvc;
|
|
using StellaOps.Integrations.Contracts;
|
|
using StellaOps.Integrations.Core;
|
|
|
|
namespace StellaOps.Integrations.WebService;
|
|
|
|
/// <summary>
|
|
/// Minimal API endpoints for the Integration Catalog.
|
|
/// </summary>
|
|
public static class IntegrationEndpoints
|
|
{
|
|
public static void MapIntegrationEndpoints(this WebApplication app)
|
|
{
|
|
var group = app.MapGroup("/api/v1/integrations")
|
|
.WithTags("Integrations")
|
|
.WithOpenApi();
|
|
|
|
// List integrations
|
|
group.MapGet("/", async (
|
|
[FromServices] IntegrationService service,
|
|
[FromQuery] IntegrationType? type,
|
|
[FromQuery] IntegrationProvider? provider,
|
|
[FromQuery] IntegrationStatus? status,
|
|
[FromQuery] string? search,
|
|
[FromQuery] int page = 1,
|
|
[FromQuery] int pageSize = 20,
|
|
[FromQuery] string sortBy = "name",
|
|
[FromQuery] bool sortDescending = false,
|
|
CancellationToken cancellationToken = default) =>
|
|
{
|
|
var query = new ListIntegrationsQuery(type, provider, status, search, null, page, pageSize, sortBy, sortDescending);
|
|
var result = await service.ListAsync(query, null, cancellationToken);
|
|
return Results.Ok(result);
|
|
})
|
|
.WithName("ListIntegrations")
|
|
.WithDescription("Lists integrations with optional filtering and pagination.");
|
|
|
|
// Get integration by ID
|
|
group.MapGet("/{id:guid}", async (
|
|
[FromServices] IntegrationService service,
|
|
Guid id,
|
|
CancellationToken cancellationToken) =>
|
|
{
|
|
var result = await service.GetByIdAsync(id, cancellationToken);
|
|
return result is null ? Results.NotFound() : Results.Ok(result);
|
|
})
|
|
.WithName("GetIntegration")
|
|
.WithDescription("Gets an integration by ID.");
|
|
|
|
// Create integration
|
|
group.MapPost("/", async (
|
|
[FromServices] IntegrationService service,
|
|
[FromBody] CreateIntegrationRequest request,
|
|
CancellationToken cancellationToken) =>
|
|
{
|
|
var result = await service.CreateAsync(request, null, null, cancellationToken);
|
|
return Results.Created($"/api/v1/integrations/{result.Id}", result);
|
|
})
|
|
.WithName("CreateIntegration")
|
|
.WithDescription("Creates a new integration.");
|
|
|
|
// Update integration
|
|
group.MapPut("/{id:guid}", async (
|
|
[FromServices] IntegrationService service,
|
|
Guid id,
|
|
[FromBody] UpdateIntegrationRequest request,
|
|
CancellationToken cancellationToken) =>
|
|
{
|
|
var result = await service.UpdateAsync(id, request, null, cancellationToken);
|
|
return result is null ? Results.NotFound() : Results.Ok(result);
|
|
})
|
|
.WithName("UpdateIntegration")
|
|
.WithDescription("Updates an existing integration.");
|
|
|
|
// Delete integration
|
|
group.MapDelete("/{id:guid}", async (
|
|
[FromServices] IntegrationService service,
|
|
Guid id,
|
|
CancellationToken cancellationToken) =>
|
|
{
|
|
var result = await service.DeleteAsync(id, null, cancellationToken);
|
|
return result ? Results.NoContent() : Results.NotFound();
|
|
})
|
|
.WithName("DeleteIntegration")
|
|
.WithDescription("Soft-deletes an integration.");
|
|
|
|
// Test connection
|
|
group.MapPost("/{id:guid}/test", async (
|
|
[FromServices] IntegrationService service,
|
|
Guid id,
|
|
CancellationToken cancellationToken) =>
|
|
{
|
|
var result = await service.TestConnectionAsync(id, null, cancellationToken);
|
|
return result is null ? Results.NotFound() : Results.Ok(result);
|
|
})
|
|
.WithName("TestIntegrationConnection")
|
|
.WithDescription("Tests connectivity and authentication for an integration.");
|
|
|
|
// Health check
|
|
group.MapGet("/{id:guid}/health", async (
|
|
[FromServices] IntegrationService service,
|
|
Guid id,
|
|
CancellationToken cancellationToken) =>
|
|
{
|
|
var result = await service.CheckHealthAsync(id, cancellationToken);
|
|
return result is null ? Results.NotFound() : Results.Ok(result);
|
|
})
|
|
.WithName("CheckIntegrationHealth")
|
|
.WithDescription("Performs a health check on an integration.");
|
|
|
|
// Get supported providers
|
|
group.MapGet("/providers", ([FromServices] IntegrationService service) =>
|
|
{
|
|
var result = service.GetSupportedProviders();
|
|
return Results.Ok(result);
|
|
})
|
|
.WithName("GetSupportedProviders")
|
|
.WithDescription("Gets a list of supported integration providers.");
|
|
}
|
|
}
|