38 lines
863 B
TypeScript
38 lines
863 B
TypeScript
import { prisma } from "@/lib/db";
|
|
import { NextRequest } from "next/server";
|
|
|
|
export async function GET() {
|
|
const manga = await prisma.manga.findMany({
|
|
orderBy: { updatedAt: "desc" },
|
|
include: {
|
|
_count: { select: { chapters: true } },
|
|
},
|
|
});
|
|
return Response.json(manga);
|
|
}
|
|
|
|
export async function POST(request: NextRequest) {
|
|
const body = await request.json();
|
|
|
|
const { title, description, coverUrl, slug, status } = body;
|
|
|
|
if (!title || !description || !coverUrl || !slug) {
|
|
return Response.json(
|
|
{ error: "Missing required fields: title, description, coverUrl, slug" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const manga = await prisma.manga.create({
|
|
data: {
|
|
title,
|
|
description,
|
|
coverUrl,
|
|
slug,
|
|
status: status || "PUBLISHED",
|
|
},
|
|
});
|
|
|
|
return Response.json(manga, { status: 201 });
|
|
}
|