silverwolf-x's picture
download
raw
666 Bytes
import prisma from "@/lib/prisma";
import { NextResponse } from "next/server";
export async function GET(request: Request) {
const url = new URL(request.url);
const page = parseInt(url.searchParams.get("page") || "1");
const postsPerPage = 5;
const offset = (page - 1) * postsPerPage;
// Fetch paginated posts
const posts = await prisma.post.findMany({
skip: offset,
take: postsPerPage,
orderBy: { createdAt: "desc" },
include: { author: { select: { name: true } } },
});
const totalPosts = await prisma.post.count();
const totalPages = Math.ceil(totalPosts / postsPerPage);
return NextResponse.json({ posts, totalPages });
}

Xet Storage Details

Size:
666 Bytes
·
Xet hash:
cd4c5a42b5ff3bd403804cbc63f2f3069f7b4a402765a928b6b90828d4c8acd1

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.