using API.MangaConnectors; using API.Schema.MangaContext; using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using static Microsoft.AspNetCore.Http.StatusCodes; namespace API.Controllers; [ApiVersion(2)] [ApiController] [Route("v{v:apiVersion}/[controller]")] public class MaintenanceController(MangaContext mangaContext) : Controller { /// /// Removes all not marked for Download on any /// /// /// Error during Database Operation [HttpPost("CleanupNoDownloadManga")] [ProducesResponseType(Status200OK)] [ProducesResponseType(Status500InternalServerError, "text/plain")] public async Task CleanupNoDownloadManga() { if (await mangaContext.Mangas .Include(m => m.MangaConnectorIds) .Where(m => !m.MangaConnectorIds.Any(id => id.UseForDownload)) .ToArrayAsync(HttpContext.RequestAborted) is not { } noDownloads) return StatusCode(Status500InternalServerError); mangaContext.Mangas.RemoveRange(noDownloads); if(await mangaContext.Sync(HttpContext.RequestAborted) is { success: false } result) return StatusCode(Status500InternalServerError, result.exceptionMessage); return Ok(); } }