mirror of
https://litchi.icu/ngc2207/judge4c-demo.git
synced 2025-05-18 12:56:34 +00:00
feat: 添加单个代码片段展示页面的数据库查询和404处理
This commit is contained in:
parent
4e8792cc45
commit
60b57ded7f
@ -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>;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user