feat: return reports in audit log entries
This commit is contained in:
parent
53006ea313
commit
dc9c11ec52
5 changed files with 61 additions and 5 deletions
|
@ -43,7 +43,9 @@ public class AuditLogController(DatabaseContext db, ModerationRendererService mo
|
|||
_ => limit,
|
||||
};
|
||||
|
||||
IQueryable<AuditLogEntry> query = db.AuditLog.OrderByDescending(e => e.Id);
|
||||
IQueryable<AuditLogEntry> query = db
|
||||
.AuditLog.Include(e => e.Report)
|
||||
.OrderByDescending(e => e.Id);
|
||||
|
||||
if (before != null)
|
||||
query = query.Where(e => e.Id < before.Value);
|
||||
|
|
|
@ -41,12 +41,23 @@ public record AuditLogResponse(
|
|||
AuditLogEntity? TargetUser,
|
||||
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
AuditLogEntity? TargetMember,
|
||||
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] Snowflake? ReportId,
|
||||
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] PartialReport? Report,
|
||||
AuditLogEntryType Type,
|
||||
string? Reason,
|
||||
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)] string[]? ClearedFields
|
||||
);
|
||||
|
||||
public record PartialReport(
|
||||
Snowflake Id,
|
||||
Snowflake ReporterId,
|
||||
Snowflake TargetUserId,
|
||||
[property: JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
|
||||
Snowflake? TargetMemberId,
|
||||
ReportReason Reason,
|
||||
string? Context,
|
||||
ReportTargetType TargetType
|
||||
);
|
||||
|
||||
public record NotificationResponse(
|
||||
Snowflake Id,
|
||||
NotificationType Type,
|
||||
|
|
|
@ -46,12 +46,26 @@ public class ModerationRendererService(
|
|||
|
||||
public AuditLogResponse RenderAuditLogEntry(AuditLogEntry entry)
|
||||
{
|
||||
PartialReport? report = null;
|
||||
if (entry.Report != null)
|
||||
{
|
||||
report = new PartialReport(
|
||||
entry.Report.Id,
|
||||
entry.Report.ReporterId,
|
||||
entry.Report.TargetUserId,
|
||||
entry.Report.TargetMemberId,
|
||||
entry.Report.Reason,
|
||||
entry.Report.Context,
|
||||
entry.Report.TargetType
|
||||
);
|
||||
}
|
||||
|
||||
return new AuditLogResponse(
|
||||
Id: entry.Id,
|
||||
Moderator: ToEntity(entry.ModeratorId, entry.ModeratorUsername)!,
|
||||
TargetUser: ToEntity(entry.TargetUserId, entry.TargetUsername),
|
||||
TargetMember: ToEntity(entry.TargetMemberId, entry.TargetMemberName),
|
||||
ReportId: entry.ReportId,
|
||||
Report: report,
|
||||
Type: entry.Type,
|
||||
Reason: entry.Reason,
|
||||
ClearedFields: entry.ClearedFields
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue