1
0
mirror of https://github.com/chylex/Minecraft-Phantom-Panel.git synced 2024-10-17 03:42:50 +02:00
Minecraft-Phantom-Panel/Controller/Phantom.Controller.Database/Repositories/AuditLogRepository.cs
2023-12-05 14:27:55 +01:00

31 lines
1.0 KiB
C#

using System.Collections.Immutable;
using Microsoft.EntityFrameworkCore;
using Phantom.Common.Data.Web.AuditLog;
using Phantom.Utils.Collections;
namespace Phantom.Controller.Database.Repositories;
public sealed partial class AuditLogRepository {
private readonly ILazyDbContext db;
public AuditLogRepository(ILazyDbContext db) {
this.db = db;
}
public Task<ImmutableArray<AuditLogItem>> GetMostRecentItems(int count, CancellationToken cancellationToken) {
return db.Ctx
.AuditLog
.Include(static entity => entity.User)
.AsQueryable()
.OrderByDescending(static entity => entity.UtcTime)
.Take(count)
.AsAsyncEnumerable()
.Select(static entity => new AuditLogItem(entity.UtcTime, entity.UserGuid, entity.User?.Name, entity.EventType, entity.SubjectType, entity.SubjectId, entity.Data?.RootElement.ToString()))
.ToImmutableArrayAsync(cancellationToken);
}
public ItemWriter Writer(Guid? currentUserGuid) {
return new ItemWriter(db, currentUserGuid);
}
}