mirror of
https://github.com/Sea-Haven-Industries/proposal-system.git
synced 2026-10-01 00:03:14 +00:00
Add JsonStringEnumConverter so string enum values (ServiceCategory, Priority, PricingMode, LineItemSource) deserialize correctly from frontend requests. Wrap AuditService detail strings in a JSON object to satisfy the Postgres jsonb column type. Relax global.json SDK version to match installed 8.0.1xx feature band.
39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using System.Text.Json;
|
|
using ProposalSystem.Application.Interfaces;
|
|
using ProposalSystem.Domain.Entities;
|
|
using ProposalSystem.Infrastructure.Data;
|
|
|
|
namespace ProposalSystem.Infrastructure.Services;
|
|
|
|
public class AuditService : IAuditService
|
|
{
|
|
private readonly ProposalDbContext _db;
|
|
private readonly ICurrentUserService _currentUser;
|
|
|
|
public AuditService(ProposalDbContext db, ICurrentUserService currentUser)
|
|
{
|
|
_db = db;
|
|
_currentUser = currentUser;
|
|
}
|
|
|
|
public async Task LogAsync(AuditAction action, Guid? proposalId, string? details = null, CancellationToken ct = default)
|
|
{
|
|
var jsonDetails = details != null
|
|
? JsonSerializer.Serialize(new { message = details })
|
|
: null;
|
|
|
|
var entry = new AuditLog
|
|
{
|
|
Id = Guid.NewGuid(),
|
|
ProposalId = proposalId,
|
|
UserId = _currentUser.UserId,
|
|
Action = action,
|
|
Details = jsonDetails,
|
|
Timestamp = DateTime.UtcNow,
|
|
IpAddress = _currentUser.IpAddress,
|
|
};
|
|
|
|
_db.AuditLogs.Add(entry);
|
|
await _db.SaveChangesAsync(ct);
|
|
}
|
|
}
|