|
| 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 | +} |
0 commit comments