mirror of
https://github.com/C9Glax/tranga.git
synced 2025-10-11 05:09:49 +02:00
Use ExecuteDelete instead of ffetching data and then removing the entries
This commit is contained in:
@@ -135,11 +135,9 @@ public class FileLibraryController(MangaContext context) : Controller
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public async Task<Results<Ok, NotFound<string>, InternalServerError<string>>> DeleteLocalLibrary (string FileLibraryId)
|
||||
{
|
||||
if(await context.FileLibraries.FirstOrDefaultAsync(l => l.Key == FileLibraryId, HttpContext.RequestAborted) is not { } library)
|
||||
if(await context.FileLibraries.Where(l => l.Key == FileLibraryId).ExecuteDeleteAsync(HttpContext.RequestAborted) < 1)
|
||||
return TypedResults.NotFound(nameof(FileLibraryId));
|
||||
|
||||
context.FileLibraries.Remove(library);
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Ok();
|
||||
|
@@ -90,11 +90,9 @@ public class LibraryConnectorController(LibraryContext context) : Controller
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public async Task<Results<Ok, NotFound<string>, InternalServerError<string>>> DeleteConnector (string LibraryConnectorId)
|
||||
{
|
||||
if (await context.LibraryConnectors.FirstOrDefaultAsync(l => l.Key == LibraryConnectorId) is not { } connector)
|
||||
if (await context.LibraryConnectors.Where(l => l.Key == LibraryConnectorId).ExecuteDeleteAsync(HttpContext.RequestAborted) < 1)
|
||||
return TypedResults.NotFound(nameof(LibraryConnectorId));
|
||||
|
||||
context.LibraryConnectors.Remove(connector);
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Ok();
|
||||
|
@@ -24,13 +24,10 @@ public class MaintenanceController(MangaContext mangaContext) : Controller
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public async Task<Results<Ok, InternalServerError<string>>> CleanupNoDownloadManga()
|
||||
{
|
||||
if (await mangaContext.Mangas
|
||||
.Include(m => m.MangaConnectorIds)
|
||||
.Where(m => !m.MangaConnectorIds.Any(id => id.UseForDownload))
|
||||
.ToArrayAsync(HttpContext.RequestAborted) is not { } noDownloads)
|
||||
return TypedResults.InternalServerError("Could not fetch Manga");
|
||||
|
||||
mangaContext.Mangas.RemoveRange(noDownloads);
|
||||
await mangaContext.Mangas
|
||||
.Include(m => m.MangaConnectorIds)
|
||||
.Where(m => !m.MangaConnectorIds.Any(id => id.UseForDownload))
|
||||
.ExecuteDeleteAsync(HttpContext.RequestAborted);
|
||||
|
||||
if(await mangaContext.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
|
@@ -149,11 +149,9 @@ public class MangaController(MangaContext context) : Controller
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public async Task<Results<Ok, NotFound<string>, InternalServerError<string>>> DeleteManga (string MangaId)
|
||||
{
|
||||
if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga)
|
||||
if(await context.Mangas.Where(m => m.Key == MangaId).ExecuteDeleteAsync(HttpContext.RequestAborted) < 1)
|
||||
return TypedResults.NotFound(nameof(MangaId));
|
||||
|
||||
context.Mangas.Remove(manga);
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Ok();
|
||||
|
@@ -112,15 +112,13 @@ public class MetadataFetcherController(MangaContext context) : Controller
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public async Task<Results<Ok, BadRequest, NotFound<string>, InternalServerError<string>, StatusCodeHttpResult>> UnlinkMangaMetadata (string MangaId, string MetadataFetcherName)
|
||||
{
|
||||
if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } _)
|
||||
if (! await context.Mangas.AnyAsync(m => m.Key == MangaId, HttpContext.RequestAborted))
|
||||
return TypedResults.NotFound(nameof(MangaId));
|
||||
if(Tranga.MetadataFetchers.FirstOrDefault(f => f.Name == MetadataFetcherName) is null)
|
||||
if(Tranga.MetadataFetchers.All(f => f.Name != MetadataFetcherName))
|
||||
return TypedResults.BadRequest();
|
||||
if (context.MetadataEntries.FirstOrDefault(e =>
|
||||
e.MangaId == MangaId && e.MetadataFetcherName == MetadataFetcherName) is not { } entry)
|
||||
if (await context.MetadataEntries.Where(e => e.MangaId == MangaId && e.MetadataFetcherName == MetadataFetcherName)
|
||||
.ExecuteDeleteAsync(HttpContext.RequestAborted) < 1)
|
||||
return TypedResults.StatusCode(Status412PreconditionFailed);
|
||||
|
||||
context.Remove(entry);
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
|
@@ -163,11 +163,9 @@ public class NotificationConnectorController(NotificationsContext context) : Con
|
||||
[ProducesResponseType<string>(Status500InternalServerError, "text/plain")]
|
||||
public async Task<Results<Ok, NotFound<string>, InternalServerError<string>>> DeleteConnector (string Name)
|
||||
{
|
||||
if (await context.NotificationConnectors.FirstOrDefaultAsync(c => c.Name == Name, HttpContext.RequestAborted) is not { } connector)
|
||||
if (await context.NotificationConnectors.Where(c => c.Name == Name).ExecuteDeleteAsync(HttpContext.RequestAborted) < 1)
|
||||
return TypedResults.NotFound(nameof(Name));
|
||||
|
||||
context.NotificationConnectors.Remove(connector);
|
||||
|
||||
if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result)
|
||||
return TypedResults.InternalServerError(result.exceptionMessage);
|
||||
return TypedResults.Ok();
|
||||
|
Reference in New Issue
Block a user