Skip to content

Commit 10ce0cd

Browse files
count api
1 parent 266df83 commit 10ce0cd

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/app/api/papers/count/route.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { NextResponse, NextRequest } from "next/server";
2+
import { connectToDatabase } from "@/lib/mongoose";
3+
import Paper from "@/db/papers";
4+
5+
export const dynamic = "force-dynamic";
6+
7+
export async function GET() {
8+
try {
9+
await connectToDatabase();
10+
11+
12+
const count: number = await Paper.countDocuments();
13+
14+
return NextResponse.json(
15+
{ count },
16+
{ status: 200 }
17+
);
18+
} catch (error) {
19+
return NextResponse.json(
20+
{ message: "Failed to fetch papers", error },
21+
{ status: 500 }
22+
);
23+
}
24+
}

0 commit comments

Comments
 (0)