Модуль связей и Klipy
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user