feat: 添加单个代码片段展示页面的数据库查询和404处理

This commit is contained in:
ngc2207 2024-11-12 15:21:33 +08:00
parent 4e8792cc45
commit 60b57ded7f

View File

@ -1,3 +1,6 @@
import { db } from "@/db";
import { notFound } from "next/navigation";
interface SnippetShowPageProps { interface SnippetShowPageProps {
params: Promise<{ params: Promise<{
id: string; id: string;
@ -5,6 +8,16 @@ interface SnippetShowPageProps {
} }
export default async function SnippetShowPage(props: SnippetShowPageProps) { export default async function SnippetShowPage(props: SnippetShowPageProps) {
const { id } = await props.params; const params = await props.params;
return <div>Show a snippet: {id}</div>; const snippet = await db.snippet.findFirst({
where: {
id: parseInt(params.id),
},
});
if (!snippet) {
return notFound();
}
return <div>Show a snippet: {snippet.title}</div>;
} }