mirror of
https://github.com/chylex/Minecraft-Phantom-Panel.git
synced 2024-11-21 23:42:45 +01:00
31 lines
1.0 KiB
C#
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);
|
|
}
|
|
}
|