diff --git a/src/app/api/product/route.ts b/src/app/api/product/route.ts index d061941..11c965c 100644 --- a/src/app/api/product/route.ts +++ b/src/app/api/product/route.ts @@ -5,16 +5,6 @@ export const dynamic = "force-dynamic"; export async function POST(request: Request) { try { - // const body = await request.json(); - - // const { name, brand } = body; - // if (!name || !brand) { - // return NextResponse.json( - // { error: "Missing required fields" }, - // { status: 400 }, - // ); - // } - const products = [ { name: "ZenBook 14", brand: "ASUS" }, { name: "Swift 3", brand: "Acer" }, @@ -40,3 +30,18 @@ export async function POST(request: Request) { ); } } + +export async function GET() { + try { + const count = await prisma.product.count(); + + return NextResponse.json({ count }, { status: 200 }); + } catch (error) { + console.error("GET /product/count error:", error); + + return NextResponse.json( + { message: "Internal server error" }, + { status: 500 }, + ); + } +} diff --git a/src/components/dashboards/Header.tsx b/src/components/dashboards/Header.tsx index 272cb2a..75f9663 100644 --- a/src/components/dashboards/Header.tsx +++ b/src/components/dashboards/Header.tsx @@ -20,7 +20,8 @@ import Link from "next/link"; import { useHeader } from "@/src/hooks/useHeader"; export function Header() { - const { open, setOpen, session, mounted } = useHeader(); + const { open, setOpen, session, mounted, productCount, loadingProductCount } = + useHeader(); if (!mounted) return null; return ( @@ -45,7 +46,7 @@ export function Header() {