33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
using Carter;
|
|
using MediatR;
|
|
using Knot.Shared.Kernel.Constants;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Routing;
|
|
using System;
|
|
|
|
namespace Host.Endpoints;
|
|
|
|
/// <summary>
|
|
/// Регистрация эндпоинтов федерации.
|
|
/// </summary>
|
|
public sealed class FederationEndpoints : ICarterModule
|
|
{
|
|
public void AddRoutes(IEndpointRouteBuilder app)
|
|
{
|
|
var group = app.MapGroup(Routes.ApiFederation);
|
|
|
|
group.MapPost("/handshake", async ([FromBody] Host.Application.Federation.Commands.HandshakeRequest request, ISender sender, CancellationToken ct) =>
|
|
{
|
|
var result = await sender.Send(new Host.Application.Federation.Commands.HandshakeFederationCommand(request), ct);
|
|
if (result.IsSuccess) return Results.Ok(result.Value);
|
|
|
|
if (result.Error.Code == "Unauthorized") return Results.Forbid();
|
|
if (result.Error.Code == Knot.Shared.Kernel.Constants.Errors.DisabledByAdmin) return Results.StatusCode(503);
|
|
|
|
return Results.BadRequest(new { error = result.Error.Description });
|
|
});
|
|
}
|
|
}
|