fix: slug in routes

This commit is contained in:
Julien Froidefond
2025-03-02 15:06:04 +01:00
parent e60b48d549
commit 3e1f446e8b
10 changed files with 55 additions and 38 deletions

View File

@@ -7,11 +7,12 @@ import { AppError } from "@/utils/errors";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
export async function GET(request: NextRequest) { export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ bookId: string; pageNumber: string }> }
) {
try { try {
const params = request.nextUrl.searchParams; const { bookId: bookIdParam, pageNumber: pageNumberParam } = await params;
const pageNumberParam = params.get("pageNumber") || "0";
const bookIdParam = params.get("bookId") || "";
const pageNumber: number = parseInt(pageNumberParam); const pageNumber: number = parseInt(pageNumberParam);
if (isNaN(pageNumber) || pageNumber < 0) { if (isNaN(pageNumber) || pageNumber < 0) {

View File

@@ -5,11 +5,13 @@ import { ERROR_CODES } from "@/constants/errorCodes";
import { getErrorMessage } from "@/utils/errors"; import { getErrorMessage } from "@/utils/errors";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
export async function PATCH(request: NextRequest) { export async function PATCH(
request: NextRequest,
{ params }: { params: Promise<{ bookId: string }> }
) {
try { try {
const { page, completed } = await request.json(); const { page, completed } = await request.json();
const params = request.nextUrl.searchParams; const bookId: string = (await params).bookId;
const bookId: string = params.get("bookId") || "";
if (typeof page !== "number") { if (typeof page !== "number") {
return NextResponse.json( return NextResponse.json(
@@ -53,10 +55,12 @@ export async function PATCH(request: NextRequest) {
} }
} }
export async function DELETE(request: NextRequest) { export async function DELETE(
request: NextRequest,
{ params }: { params: Promise<{ bookId: string }> }
) {
try { try {
const params = request.nextUrl.searchParams; const bookId: string = (await params).bookId;
const bookId: string = params.get("bookId") || "";
await BookService.deleteReadProgress(bookId); await BookService.deleteReadProgress(bookId);
return NextResponse.json({ message: "🗑️ Progression supprimée avec succès" }); return NextResponse.json({ message: "🗑️ Progression supprimée avec succès" });

View File

@@ -6,10 +6,12 @@ import { AppError } from "@/utils/errors";
import type { KomgaBookWithPages } from "@/types/komga"; import type { KomgaBookWithPages } from "@/types/komga";
import type { NextRequest } from "next/server"; import type { NextRequest } from "next/server";
export async function GET(request: NextRequest) { export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ bookId: string }> }
) {
try { try {
const params = request.nextUrl.searchParams; const bookId: string = (await params).bookId;
const bookId: string = params.get("bookId") || "";
const data: KomgaBookWithPages = await BookService.getBook(bookId); const data: KomgaBookWithPages = await BookService.getBook(bookId);
return NextResponse.json(data); return NextResponse.json(data);

View File

@@ -7,11 +7,12 @@ import { SeriesService } from "@/lib/services/series.service";
import { revalidatePath } from "next/cache"; import { revalidatePath } from "next/cache";
import type { NextRequest } from "next/server"; import type { NextRequest } from "next/server";
export async function POST(request: NextRequest) { export async function POST(
request: NextRequest,
{ params }: { params: Promise<{ libraryId: string; seriesId: string }> }
) {
try { try {
const params = request.nextUrl.searchParams; const { libraryId, seriesId } = await params;
const libraryId: string = params.get("libraryId") || "";
const seriesId: string = params.get("seriesId") || "";
await HomeService.invalidateHomeCache(); await HomeService.invalidateHomeCache();
revalidatePath("/"); revalidatePath("/");

View File

@@ -7,11 +7,12 @@ import { getErrorMessage } from "@/utils/errors";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
export async function GET(request: NextRequest) { export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ bookId: string; pageNumber: string }> }
) {
try { try {
const params = request.nextUrl.searchParams; const { bookId, pageNumber } = await params;
const bookId: string = params.get("bookId") || "";
const pageNumber: string = params.get("pageNumber") || "";
const response = await BookService.getPage(bookId, parseInt(pageNumber)); const response = await BookService.getPage(bookId, parseInt(pageNumber));
return response; return response;

View File

@@ -7,11 +7,12 @@ import { getErrorMessage } from "@/utils/errors";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
export async function GET(request: NextRequest) { export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ bookId: string; pageNumber: string }> }
) {
try { try {
const params = request.nextUrl.searchParams; const { bookId, pageNumber: pageNumberParam } = await params;
const bookId: string = params.get("bookId") || "";
const pageNumberParam: string = params.get("pageNumber") || "";
const pageNumber: number = parseInt(pageNumberParam); const pageNumber: number = parseInt(pageNumberParam);
if (isNaN(pageNumber) || pageNumber < 0) { if (isNaN(pageNumber) || pageNumber < 0) {

View File

@@ -5,10 +5,12 @@ import { ERROR_CODES } from "@/constants/errorCodes";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { getErrorMessage } from "@/utils/errors"; import { getErrorMessage } from "@/utils/errors";
export async function GET(request: NextRequest) { export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ bookId: string }> }
) {
try { try {
const params = request.nextUrl.searchParams; const bookId: string = (await params).bookId;
const bookId: string = params.get("bookId") || "";
const response = await BookService.getCover(bookId); const response = await BookService.getCover(bookId);
return response; return response;

View File

@@ -7,10 +7,12 @@ import { getErrorMessage } from "@/utils/errors";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
export async function GET(request: NextRequest) { export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ seriesId: string }> }
) {
try { try {
const params = request.nextUrl.searchParams; const seriesId: string = (await params).seriesId;
const seriesId: string = params.get("seriesId") || "";
const response = await SeriesService.getCover(seriesId); const response = await SeriesService.getCover(seriesId);
return response; return response;

View File

@@ -5,11 +5,12 @@ import { ERROR_CODES } from "@/constants/errorCodes";
import { AppError } from "@/utils/errors"; import { AppError } from "@/utils/errors";
import { getErrorMessage } from "@/utils/errors"; import { getErrorMessage } from "@/utils/errors";
export async function GET(request: NextRequest) { export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ seriesId: string }> }
) {
try { try {
const params = request.nextUrl.searchParams; const seriesId: string = (await params).seriesId;
const seriesId: string = params.get("seriesId") || "";
const response = await SeriesService.getCover(seriesId); const response = await SeriesService.getCover(seriesId);
return response; return response;
} catch (error) { } catch (error) {

View File

@@ -7,10 +7,12 @@ import { getErrorMessage } from "@/utils/errors";
import type { NextRequest } from "next/server"; import type { NextRequest } from "next/server";
export const dynamic = "force-dynamic"; export const dynamic = "force-dynamic";
export async function GET(request: NextRequest) { export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ seriesId: string }> }
) {
try { try {
const params = request.nextUrl.searchParams; const seriesId: string = (await params).seriesId;
const seriesId: string = params.get("seriesId") || "";
const series: KomgaSeries = await SeriesService.getSeries(seriesId); const series: KomgaSeries = await SeriesService.getSeries(seriesId);
return NextResponse.json(series); return NextResponse.json(series);