Skip to content

Commit bdbb1bb

Browse files
committed
feat: add admin maintenance controller
1 parent df4a7fb commit bdbb1bb

4 files changed

Lines changed: 53 additions & 4 deletions

File tree

ApplicationData/ApplicationData.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.1" />
2424
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
2525
<PackageReference Include="SnooBrowser" Version="3.2.0" />
26-
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
26+
<PackageReference Include="System.Linq.Async" Version="6.0.3" />
2727
</ItemGroup>
2828

2929
</Project>

BackgroundProcessor/BackgroundProcessor.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<PackageReference Include="Nito.AsyncEx" Version="5.1.2" />
2121
<PackageReference Include="SnooBrowser" Version="3.2.0" />
2222
<PackageReference Include="SnooBrowser.Extensions.DependencyInjection" Version="3.2.0" />
23-
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
23+
<PackageReference Include="System.Linq.Async" Version="6.0.3" />
2424
</ItemGroup>
2525

2626
<ItemGroup>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using FruityFoundation.DataAccess.Abstractions;
2+
using Microsoft.AspNetCore.Authorization;
3+
using Microsoft.AspNetCore.Mvc;
4+
using WebApi.Util;
5+
6+
namespace WebApi.Controllers.Admin;
7+
8+
/// <summary>
9+
/// Admin Maintenance Controller
10+
/// </summary>
11+
[Authorize(Roles = UserRoles.AdministratorRole)]
12+
[ApiExplorerSettings(IgnoreApi = true)]
13+
[ApiController]
14+
[Route("v1/admin/maintenance")]
15+
public class AdminMaintenanceController : Controller
16+
{
17+
private readonly IDbConnectionFactory _dbConnectionFactory;
18+
19+
/// <summary>
20+
/// C'tor
21+
/// </summary>
22+
/// <param name="dbConnectionFactory"></param>
23+
public AdminMaintenanceController(IDbConnectionFactory dbConnectionFactory)
24+
{
25+
_dbConnectionFactory = dbConnectionFactory;
26+
}
27+
28+
/// <summary>
29+
/// Remove all comments, queued items, and links related to the specified reddit post id.
30+
/// This is a hard purge; if a comment has already been posted to reddit, it will not be cleaned up.
31+
/// </summary>
32+
[HttpDelete]
33+
[Route("reddit-post/{redditPostId}/clear")]
34+
public async Task<IActionResult> ClearRedditPost(string redditPostId)
35+
{
36+
await using var db = _dbConnectionFactory.CreateConnection();
37+
38+
await db.Execute(
39+
"""
40+
BEGIN TRANSACTION;
41+
DELETE FROM reddit_comments WHERE reddit_post_id = @redditPostId;
42+
DELETE FROM link_queue WHERE reddit_post_id = @redditPostId;
43+
DELETE FROM links WHERE reddit_post_id = @redditPostId;
44+
COMMIT;
45+
""", new { redditPostId }, CancellationToken.None);
46+
47+
return Ok();
48+
}
49+
}

WebApi/WebApi.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2626
</PackageReference>
2727
<PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.0.0" />
28-
<PackageReference Include="Sentry.AspNetCore" Version="5.0.1" />
28+
<PackageReference Include="Sentry.AspNetCore" Version="5.12.0" />
2929
<PackageReference Include="SnooBrowser.Extensions.DependencyInjection" Version="3.2.0" />
3030
<PackageReference Include="Swashbuckle.AspNetCore" Version="7.2.0" />
3131
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="7.2.0" />
32-
<PackageReference Include="System.Linq.Async" Version="6.0.1" />
32+
<PackageReference Include="System.Linq.Async" Version="6.0.3" />
3333
<PackageReference Include="System.Runtime.Caching" Version="9.0.1" />
3434
</ItemGroup>
3535

0 commit comments

Comments
 (0)