Files
Hy2026/backend/Infrastructure/Persistence/AuditLogService.cs
T
Rafał Tyński fa1199539b feat(backend): add communication, tester, admin and middleman modules
Implement step 17 modules: threads/messages, notifications with automation (submission.created, idea.created, grant_call.opened), innovation test feedback, admin panel (submissions, verify, metrics, grant call status), Middleman adaptation and partnerships. Split multi-type files into one type per file and replace object-valued dictionaries with string-valued maps in data contracts (migrations 0006/0007).
2026-10-04 03:49:45 +02:00

48 lines
1.3 KiB
C#

using SurrealDb.Net;
using TarninaHub.Application.Abstractions;
namespace TarninaHub.Infrastructure.Persistence;
public sealed class AuditLogService : IAuditLogService
{
private readonly ISurrealDbClient _client;
public AuditLogService(ISurrealDbClient client)
{
_client = client;
}
public async Task RecordAsync(
string? actorId,
string action,
string target,
IReadOnlyDictionary<string, string?> context,
CancellationToken cancellationToken)
{
var (actorTable, actorIdPart) = actorId is null
? ("user", (string?)null)
: SurrealRecordId.Split(actorId);
var actorExpression = actorId is null
? "NONE"
: "type::record($actorTable, $actorId)";
var parameters = new Dictionary<string, object?>
{
["action"] = action,
["target"] = target,
["context"] = context,
["actorTable"] = actorTable,
["actorId"] = actorIdPart,
};
var response = await _client.RawQuery(
$"CREATE audit_log SET actor = {actorExpression}, action = $action, " +
"target = $target, context = $context, at = time::now();",
parameters,
cancellationToken);
response.EnsureAllOks();
}
}