Skip to content

Commit 026b671

Browse files
committed
Fix paging in DeletedMessages/Infractions
Move RecordsPage to Modix.Models project
1 parent 36d37ac commit 026b671

File tree

9 files changed

+62
-49
lines changed

9 files changed

+62
-49
lines changed

src/Modix.Data/Models/RecordsPage.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Modix.Data/Repositories/DeletedMessageRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Modix.Data.Models;
1111
using Modix.Data.Models.Moderation;
1212
using Modix.Data.Utilities;
13+
using Modix.Models;
1314

1415
namespace Modix.Data.Repositories
1516
{

src/Modix.Data/Repositories/InfractionRepository.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Modix.Data.Models;
1010
using Modix.Data.Models.Moderation;
1111
using Modix.Data.Utilities;
12+
using Modix.Models;
1213
using Modix.Models.Moderation;
1314

1415
namespace Modix.Data.Repositories

src/Modix.Models/RecordsPage.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Modix.Models;
2+
3+
/// <summary>
4+
/// Describes paged subset of records, from a larger recordset.
5+
/// </summary>
6+
/// <typeparam name="T">The type of record contained in the page.</typeparam>
7+
public class RecordsPage<T>
8+
{
9+
/// <summary>
10+
/// The total number of records in the recordset.
11+
/// </summary>
12+
public long TotalRecordCount { get; set; }
13+
14+
/// <summary>
15+
/// The number of records in the recordset, after applying an optional set of filtering criteria.
16+
/// </summary>
17+
public long FilteredRecordCount { get; set; }
18+
19+
/// <summary>
20+
/// The current page of records, selected from the larger recordset.
21+
/// </summary>
22+
public IReadOnlyCollection<T> Records { get; set; } = null!;
23+
}

src/Modix.Services/Moderation/ModerationService.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#nullable enable
22
using System;
3-
using System.Linq;
43
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Threading;
56
using System.Threading.Tasks;
67
using Discord;
78
using Discord.Net;
8-
using Discord.WebSocket;
99
using Modix.Data.Models;
1010
using Modix.Data.Models.Core;
1111
using Modix.Data.Models.Moderation;
1212
using Modix.Data.Repositories;
13+
using Modix.Models;
14+
using Modix.Models.Core;
15+
using Modix.Models.Moderation;
1316
using Modix.Services.Core;
1417
using Modix.Services.Utilities;
1518
using Serilog;
16-
using System.Threading;
17-
using Modix.Models.Core;
18-
using Modix.Models.Moderation;
1919

2020
namespace Modix.Services.Moderation
2121
{

src/Modix.Web.Wasm/Components/Infractions/DeletedMessages.razor

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
@using Modix.Web.Shared.Models.DeletedMessages
1+
@using Modix.Models
2+
@using Modix.Web.Shared.Models.DeletedMessages
23
@using MudBlazor
34

45
<PageTitle>Modix - Deletions</PageTitle>
@@ -66,7 +67,7 @@
6667
</MudDialog>
6768

6869
<MudContainer MaxWidth="MaxWidth.False">
69-
<MudTable @ref="@TableRef" Bordered="true" ServerData="LoadDeletedMessages" SortLabel="Sort By">
70+
<MudTable @ref="@TableRef" Virtualize="true" Bordered="true" ServerData="LoadDeletedMessages" SortLabel="Sort By">
7071
<ToolBarContent>
7172
<MudButton Class="ml-1" Variant="Variant.Filled" OnClick="RefreshTable" StartIcon="@Icons.Material.Filled.Refresh" Color="MudBlazor.Color.Primary">Refresh</MudButton>
7273
</ToolBarContent>
@@ -176,12 +177,12 @@
176177

177178
response.EnsureSuccessStatusCode();
178179

179-
var result = await response.Content.ReadFromJsonAsync<DeletedMessageBatchInformation[]>();
180+
var result = await response.Content.ReadFromJsonAsync<RecordsPage<DeletedMessageBatchInformation>>();
180181

181182
return new TableData<DeletedMessageBatchInformation>
182183
{
183-
TotalItems = result.Length,
184-
Items = result
184+
TotalItems = (int)result.TotalRecordCount,
185+
Items = result.Records
185186
};
186187
}
187188

src/Modix.Web.Wasm/Components/Infractions/Infractions.razor

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@using Microsoft.AspNetCore.Components.Authorization
2+
@using Modix.Models
23
@using Modix.Models.Core
34
@using Modix.Web.Models;
45
@using Modix.Web.Shared.Models.Common
@@ -79,7 +80,6 @@
7980

8081
<MudContainer MaxWidth="MaxWidth.False">
8182

82-
8383
<div class="d-flex mb-1 gap-sm-4 align-sm-center">
8484
<div class="d-flex flex-sm-row flex-column align-start">
8585
<MudButton Class="ml-1 mb-1" Variant="Variant.Filled" OnClick="ToggleDialog" StartIcon="@Icons.Material.Filled.Create" Color="Color.Primary">Create</MudButton>
@@ -92,7 +92,7 @@
9292
</div>
9393
</div>
9494

95-
<MudTable @ref="@TableRef" SortLabel="Sort By" Bordered="true" ServerData="LoadInfractions">
95+
<MudTable Virtualize="true" @ref="@TableRef" SortLabel="Sort By" Bordered="true" ServerData="LoadInfractions">
9696
<HeaderContent>
9797
<MudTh Class="center-text vertical-top">
9898
<MudTableSortLabel T="InfractionData" SortBy="x => x.Id">Id</MudTableSortLabel>
@@ -416,13 +416,13 @@
416416
using var client = HttpClientFactory.CreateClient("api");
417417
using var response = await client.PutAsJsonAsync("api/infractions", new InfractionsQuery(_tableFilter, tableState));
418418
response.EnsureSuccessStatusCode();
419-
420-
var infractions = await response.Content.ReadFromJsonAsync<InfractionData[]>();
419+
420+
var infractions = await response.Content.ReadFromJsonAsync<RecordsPage<InfractionData>>();
421421

422422
return new TableData<InfractionData>
423423
{
424-
Items = infractions,
425-
TotalItems = infractions.Length
424+
Items = infractions.Records,
425+
TotalItems = (int)infractions.TotalRecordCount
426426
};
427427
}
428428

src/Modix.Web/Controllers/DeletedMessagesController.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
using Microsoft.AspNetCore.Mvc;
66
using Modix.Data.Models;
77
using Modix.Data.Models.Moderation;
8+
using Modix.Models;
89
using Modix.Models.Core;
910
using Modix.Services.Moderation;
1011
using Modix.Services.Utilities;
1112
using Modix.Web.Shared.Models.DeletedMessages;
12-
using MudBlazor;
1313

1414
namespace Modix.Web.Controllers;
1515

@@ -27,7 +27,7 @@ public DeletedMessagesController(IModerationService moderationService, DiscordSo
2727
}
2828

2929
[HttpPut]
30-
public async Task<DeletedMessageBatchInformation[]> GetDeletedMessagesBatchAsync(DeletedMessagesQuery deletedMessagesQuery)
30+
public async Task<RecordsPage<DeletedMessageBatchInformation>> GetDeletedMessagesBatchAsync(DeletedMessagesQuery deletedMessagesQuery)
3131
{
3232
var tableState = deletedMessagesQuery.TableState;
3333
var tableFilter = deletedMessagesQuery.Filter;
@@ -60,10 +60,9 @@ public async Task<DeletedMessageBatchInformation[]> GetDeletedMessagesBatchAsync
6060
PageSize = tableState.PageSize,
6161
};
6262

63-
6463
var deletedMessages = await _moderationService.SearchDeletedMessagesAsync(searchCriteria, [sortingCriteria], pagingCriteria);
6564

66-
return deletedMessages.Records
65+
var deletedMessagesBatchInformation = deletedMessages.Records
6766
.Select(x => new DeletedMessageBatchInformation(
6867
x.Channel.Name,
6968
x.Author.GetFullUsername(),
@@ -73,6 +72,13 @@ public async Task<DeletedMessageBatchInformation[]> GetDeletedMessagesBatchAsync
7372
x.Reason,
7473
x.BatchId))
7574
.ToArray();
75+
76+
return new RecordsPage<DeletedMessageBatchInformation>
77+
{
78+
FilteredRecordCount = deletedMessagesBatchInformation.Length,
79+
Records = deletedMessagesBatchInformation,
80+
TotalRecordCount = deletedMessages.TotalRecordCount
81+
};
7682
}
7783

7884
[HttpGet("{batchId}")]

src/Modix.Web/Controllers/InfractionsController.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
using Microsoft.AspNetCore.Mvc;
44
using Modix.Data.Models;
55
using Modix.Data.Models.Moderation;
6+
using Modix.Models;
67
using Modix.Models.Core;
78
using Modix.Services.Moderation;
89
using Modix.Web.Shared.Models.Infractions;
9-
using MudBlazor;
1010

1111
namespace Modix.Web.Controllers;
1212

@@ -25,7 +25,7 @@ public InfractionsController(IModerationService moderationService, DiscordSocket
2525

2626
[HttpPut]
2727
[Authorize(Roles = nameof(AuthorizationClaim.ModerationRead))]
28-
public async Task<InfractionData[]> GetInfractionsAsync(InfractionsQuery infractionsQuery)
28+
public async Task<RecordsPage<InfractionData>> GetInfractionsAsync(InfractionsQuery infractionsQuery)
2929
{
3030
var tableState = infractionsQuery.TableState;
3131
var tableFilter = infractionsQuery.Filter;
@@ -67,7 +67,7 @@ public async Task<InfractionData[]> GetInfractionsAsync(InfractionsQuery infract
6767
outranksValues[subjectId] = await _moderationService.DoesModeratorOutrankUserAsync(guildId, SocketUser.Id, subjectId);
6868
}
6969

70-
return infractions.Records
70+
var infractionData = infractions.Records
7171
.Select(x => new InfractionData(
7272
x.Id,
7373
x.GuildId,
@@ -90,6 +90,13 @@ x.DeleteAction is null
9090
&& outranksValues[x.Subject.Id]
9191
))
9292
.ToArray();
93+
94+
return new RecordsPage<InfractionData>
95+
{
96+
FilteredRecordCount = infractions.Records.Count,
97+
Records = infractionData,
98+
TotalRecordCount = infractions.TotalRecordCount,
99+
};
93100
}
94101

95102
[Authorize(Roles = nameof(AuthorizationClaim.ModerationRescind))]

0 commit comments

Comments
 (0)