refactor: migrate paginated library and series flows to server-first

This commit is contained in:
2026-02-28 12:08:20 +01:00
parent 612a70ffbe
commit e5497b4f58
7 changed files with 10 additions and 192 deletions

View File

@@ -1,57 +0,0 @@
import { NextResponse } from "next/server";
import { LibraryService } from "@/lib/services/library.service";
import { ERROR_CODES } from "@/constants/errorCodes";
import { AppError } from "@/utils/errors";
import { getErrorMessage } from "@/utils/errors";
import type { NextRequest } from "next/server";
import logger from "@/lib/logger";
// Cache handled in service via fetchFromApi options
const DEFAULT_PAGE_SIZE = 20;
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ libraryId: string }> }
) {
try {
const libraryId: string = (await params).libraryId;
const searchParams = request.nextUrl.searchParams;
const page = parseInt(searchParams.get("page") || "0");
const size = parseInt(searchParams.get("size") || String(DEFAULT_PAGE_SIZE));
const unreadOnly = searchParams.get("unread") === "true";
const search = searchParams.get("search") || undefined;
const [series, library] = await Promise.all([
LibraryService.getLibrarySeries(libraryId, page, size, unreadOnly, search),
LibraryService.getLibrary(libraryId),
]);
return NextResponse.json({ series, library });
} catch (error) {
logger.error({ err: error }, "API Library Series - Erreur:");
if (error instanceof AppError) {
return NextResponse.json(
{
error: {
code: error.code,
name: "Library series fetch error",
message: getErrorMessage(error.code),
},
},
{ status: 500 }
);
}
return NextResponse.json(
{
error: {
code: ERROR_CODES.SERIES.FETCH_ERROR,
name: "Library series fetch error",
message: getErrorMessage(ERROR_CODES.SERIES.FETCH_ERROR),
},
},
{ status: 500 }
);
}
}

View File

@@ -1,56 +0,0 @@
import { NextResponse } from "next/server";
import { SeriesService } from "@/lib/services/series.service";
import { ERROR_CODES } from "@/constants/errorCodes";
import { AppError } from "@/utils/errors";
import { getErrorMessage } from "@/utils/errors";
import type { NextRequest } from "next/server";
import logger from "@/lib/logger";
// Cache handled in service via fetchFromApi options
const DEFAULT_PAGE_SIZE = 20;
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ seriesId: string }> }
) {
try {
const seriesId: string = (await params).seriesId;
const searchParams = request.nextUrl.searchParams;
const page = parseInt(searchParams.get("page") || "0");
const size = parseInt(searchParams.get("size") || String(DEFAULT_PAGE_SIZE));
const unreadOnly = searchParams.get("unread") === "true";
const [books, series] = await Promise.all([
SeriesService.getSeriesBooks(seriesId, page, size, unreadOnly),
SeriesService.getSeries(seriesId),
]);
return NextResponse.json({ books, series });
} catch (error) {
logger.error({ err: error }, "API Series Books - Erreur:");
if (error instanceof AppError) {
return NextResponse.json(
{
error: {
code: error.code,
name: "Series books fetch error",
message: getErrorMessage(error.code),
},
},
{ status: 500 }
);
}
return NextResponse.json(
{
error: {
code: ERROR_CODES.BOOK.PAGES_FETCH_ERROR,
name: "Series books fetch error",
message: getErrorMessage(ERROR_CODES.BOOK.PAGES_FETCH_ERROR),
},
},
{ status: 500 }
);
}
}