feat: implement DELETE API endpoints for cache invalidation in libraries and series, updating ClientLibraryPage and ClientSeriesPage to utilize these endpoints

This commit is contained in:
Julien Froidefond
2025-10-17 10:28:56 +02:00
parent 42738412a8
commit c370b8372a
4 changed files with 93 additions and 5 deletions

View File

@@ -54,3 +54,40 @@ export async function GET(
}
}
export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ libraryId: string }> }
) {
try {
const libraryId: string = (await params).libraryId;
await LibraryService.invalidateLibrarySeriesCache(libraryId);
return NextResponse.json({ success: true });
} catch (error) {
console.error("API Library Cache Invalidation - Erreur:", error);
if (error instanceof AppError) {
return NextResponse.json(
{
error: {
code: error.code,
name: "Cache invalidation error",
message: getErrorMessage(error.code),
},
},
{ status: 500 }
);
}
return NextResponse.json(
{
error: {
code: ERROR_CODES.CACHE.DELETE_ERROR,
name: "Cache invalidation error",
message: getErrorMessage(ERROR_CODES.CACHE.DELETE_ERROR),
},
},
{ status: 500 }
);
}
}

View File

@@ -53,3 +53,43 @@ export async function GET(
}
}
export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ seriesId: string }> }
) {
try {
const seriesId: string = (await params).seriesId;
await Promise.all([
SeriesService.invalidateSeriesBooksCache(seriesId),
SeriesService.invalidateSeriesCache(seriesId)
]);
return NextResponse.json({ success: true });
} catch (error) {
console.error("API Series Cache Invalidation - Erreur:", error);
if (error instanceof AppError) {
return NextResponse.json(
{
error: {
code: error.code,
name: "Cache invalidation error",
message: getErrorMessage(error.code),
},
},
{ status: 500 }
);
}
return NextResponse.json(
{
error: {
code: ERROR_CODES.CACHE.DELETE_ERROR,
name: "Cache invalidation error",
message: getErrorMessage(ERROR_CODES.CACHE.DELETE_ERROR),
},
},
{ status: 500 }
);
}
}

View File

@@ -6,7 +6,6 @@ import { RefreshButton } from "@/components/library/RefreshButton";
import { ErrorMessage } from "@/components/ui/ErrorMessage";
import { useTranslate } from "@/hooks/useTranslate";
import { OptimizedSkeleton } from "@/components/skeletons/OptimizedSkeletons";
import { LibraryService } from "@/lib/services/library.service";
import type { LibraryResponse } from "@/types/library";
import type { KomgaSeries, KomgaLibrary } from "@/types/komga";
import type { UserPreferences } from "@/types/preferences";
@@ -77,7 +76,14 @@ export function ClientLibraryPage({
const handleRefresh = async (libraryId: string) => {
try {
await LibraryService.invalidateLibrarySeriesCache(libraryId);
// Invalidate cache via API
const cacheResponse = await fetch(`/api/komga/libraries/${libraryId}/series`, {
method: 'DELETE',
});
if (!cacheResponse.ok) {
throw new Error("Error invalidating cache");
}
// Recharger les données
const params = new URLSearchParams({

View File

@@ -3,7 +3,6 @@
import { useEffect, useState } from "react";
import { PaginatedBookGrid } from "@/components/series/PaginatedBookGrid";
import { SeriesHeader } from "@/components/series/SeriesHeader";
import { SeriesService } from "@/lib/services/series.service";
import { ErrorMessage } from "@/components/ui/ErrorMessage";
import { OptimizedSkeleton } from "@/components/skeletons/OptimizedSkeletons";
import type { LibraryResponse } from "@/types/library";
@@ -70,8 +69,14 @@ export function ClientSeriesPage({
const handleRefresh = async (seriesId: string) => {
try {
await SeriesService.invalidateSeriesBooksCache(seriesId);
await SeriesService.invalidateSeriesCache(seriesId);
// Invalidate cache via API
const cacheResponse = await fetch(`/api/komga/series/${seriesId}/books`, {
method: 'DELETE',
});
if (!cacheResponse.ok) {
throw new Error("Erreur lors de l'invalidation du cache");
}
// Recharger les données
const params = new URLSearchParams({