ci / build-test (push) Canceled after 0s
SaaS-мониторинг Telegram: ядро (модули Cards/Kanban/Pipeline/Tenants/Settings/ Discovery, Api, Infrastructure), сервисы telegram/ai/ml/storage, фронт Vue, контракты и grpc-hosting, деплой-конфиги (dev/prod/observability/CI-раннер), Gitea Actions CI, документация (ТЗ, техдок, api-map, код-стайл, планы, бэклог). Текущее состояние: все этапы роадмапа 0–12 закрыты, сборка 5 sln 0/0, тесты 1340/130/52/38/9 зелёные.
74 lines
2.8 KiB
C#
74 lines
2.8 KiB
C#
using Deal.Api.Extensions;
|
|
using Deal.Api.Services;
|
|
using Deal.Modules.Tenants.Application.Models;
|
|
using Deal.Modules.Tenants.Application.Services;
|
|
|
|
namespace Deal.Api.Endpoints;
|
|
|
|
/// <summary>
|
|
/// Операторский эндпоинт чтения аудита
|
|
/// </summary>
|
|
public static class OperatorAuditEndpoints
|
|
{
|
|
private const string OperatorGroupPrefix = "/api/operator";
|
|
|
|
// Путь ленты аудита относительно группы.
|
|
private const string AuditPath = "/audit";
|
|
|
|
private const string OperatorOpenApiTag = "operator";
|
|
|
|
/// <summary>
|
|
/// Регистрирует группу /api/operator
|
|
/// </summary>
|
|
/// <param name="app">Построитель маршрутов приложения.</param>
|
|
/// <returns>Построитель маршрутов для цепочки вызовов.</returns>
|
|
public static IEndpointRouteBuilder MapOperatorAuditEndpoints(this IEndpointRouteBuilder app)
|
|
{
|
|
app.MapGroup(OperatorGroupPrefix).WithTags(OperatorOpenApiTag).MapGet(AuditPath, ListAsync);
|
|
return app;
|
|
}
|
|
|
|
private static async Task<IResult> ListAsync(
|
|
string? eventType,
|
|
string? actorType,
|
|
Guid? actorId,
|
|
Guid? tenantId,
|
|
DateTimeOffset? from,
|
|
DateTimeOffset? to,
|
|
int? limit,
|
|
int? offset,
|
|
HttpContext context,
|
|
AuditService auditService,
|
|
CancellationToken ct)
|
|
{
|
|
var operatorIdentity = context.GetCurrentOperator();
|
|
if (operatorIdentity is null)
|
|
{
|
|
return EndpointResults.Unauthorized(AuthHelpers.OperatorUnauthorizedDetail);
|
|
}
|
|
|
|
var filter = new AuditQueryDto(
|
|
eventType, actorType, tenantId, from, to, NormalizeLimit(limit), actorId, NormalizeOffset(offset));
|
|
IReadOnlyList<AuditRecordDto> items = await auditService.QueryAsync(filter, ct);
|
|
int total = await auditService.CountAsync(filter, ct);
|
|
return Results.Ok(new { items, total });
|
|
}
|
|
|
|
/// <summary>
|
|
/// Нормализует limit запроса
|
|
/// </summary>
|
|
/// <param name="limit">Запрошенный размер выборки (null — не задан).</param>
|
|
/// <returns>Значение для фильтра.</returns>
|
|
public static int NormalizeLimit(int? limit) =>
|
|
limit is null
|
|
? AuditService.DefaultQueryLimit
|
|
: Math.Max(1, Math.Min(AuditService.MaxQueryLimit, limit.Value));
|
|
|
|
/// <summary>
|
|
/// Нормализует offset запроса
|
|
/// </summary>
|
|
/// <param name="offset">Запрошенное смещение (null — не задано).</param>
|
|
/// <returns>Неотрицательное смещение.</returns>
|
|
public static int NormalizeOffset(int? offset) => Math.Max(0, offset ?? 0);
|
|
}
|