Модуль связей и Klipy

This commit is contained in:
Халимов Рустам
2026-03-27 01:22:20 +03:00
parent 7ef73b414c
commit b399649cfd
31 changed files with 603 additions and 472 deletions

View File

@@ -0,0 +1,39 @@
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Knot.Shared.Kernel;
using Knot.Shared.Kernel.Configuration;
using Knot.Modules.Stories.Application.Abstractions;
namespace Host.Application.Admin.Commands.TestKlipy;
public record TestKlipyConnectionCommand() : ICommand<bool>;
internal sealed class TestKlipyConnectionCommandHandler : ICommandHandler<TestKlipyConnectionCommand, bool>
{
private readonly ISettingsService _settingsService;
private readonly IKlipyClient _klipyClient;
public TestKlipyConnectionCommandHandler(ISettingsService settingsService, IKlipyClient klipyClient)
{
_settingsService = settingsService;
_klipyClient = klipyClient;
}
public async Task<Result<bool>> Handle(TestKlipyConnectionCommand request, CancellationToken ct)
{
var settings = await _settingsService.GetSettingsAsync(ct);
if (string.IsNullOrEmpty(settings.Klipy.ApiKey))
{
return Result.Failure<bool>(new Error("Klipy.KeyMissing", "API Key for Klipy is not configured."));
}
var isOk = await _klipyClient.TestConnectionAsync(settings.Klipy.ApiKey, ct);
if (!isOk)
{
return Result.Failure<bool>(new Error("Klipy.AuthFailed", "Klipy API test request failed. Verify your API key."));
}
return Result.Success(true);
}
}

View File

@@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Mvc;
using Host.Application.Admin.Commands.TestKlipy;
namespace Knot.Host.Presentation.Endpoints;
@@ -33,6 +34,12 @@ public sealed class AdminEndpoints : ICarterModule
return Results.Ok(result.Value);
});
group.MapPost("settings/test-klipy", async (ISender sender, CancellationToken ct) =>
{
var result = await sender.Send(new TestKlipyConnectionCommand(), ct);
return result.IsSuccess ? Results.Ok(new { success = true }) : Results.BadRequest(new { error = result.Error.Description });
});
group.MapGet("dashboard", async (ISender sender, CancellationToken ct) =>
{
var result = await sender.Send(new GetDashboardStatsQuery(), ct);