diff --git a/app/restaurant/[slug]/page.tsx b/app/restaurant/[slug]/page.tsx index a024fd3..f984350 100644 --- a/app/restaurant/[slug]/page.tsx +++ b/app/restaurant/[slug]/page.tsx @@ -1,3 +1,4 @@ +import { PrismaClient } from "@prisma/client"; import Description from "./components/Description"; import Header from "./components/Header"; import Images from "./components/Images"; @@ -7,7 +8,42 @@ import RestaurantNavBar from "./components/RestaurantNavBar"; import Reviews from "./components/Reviews"; import Title from "./components/Title"; -export default function RestaurantDetails() { +interface Restaurant { + id: number; + name: string; + images: string[]; + description: string; + slug: string; +} +const prisma = new PrismaClient(); + +const fetchRestaurantBySlug = async (slug: string): Promise => { + const restaurant = await prisma.restaurant.findUnique({ + where: { + slug, + }, + select: { + id: true, + name: true, + images: true, + description: true, + slug: true, + }, + }); + + if (!restaurant) { + throw new Error() + } + + return restaurant; +}; + +export default async function RestaurantDetails({ + params, +}: { + params: { slug: string }; +}) { + const restaurant = await fetchRestaurantBySlug(params.slug); return ( <>