mirror of
https://litchi.icu/ngc2207/judge4c-db.git
synced 2025-05-18 09:56:33 +00:00
feat: add question management pages and integrate Prisma for data fetching
This commit is contained in:
parent
3e68af8f7a
commit
ac68921f87
@ -9,6 +9,7 @@
|
|||||||
"lint": "next lint"
|
"lint": "next lint"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@monaco-editor/react": "^4.6.0",
|
||||||
"@prisma/client": "^5.22.0",
|
"@prisma/client": "^5.22.0",
|
||||||
"class-variance-authority": "^0.7.0",
|
"class-variance-authority": "^0.7.0",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
|
30
src/app/questions/[id]/edit/page.tsx
Normal file
30
src/app/questions/[id]/edit/page.tsx
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
import { CodeLanguage, CodeTemplate } from "@prisma/client";
|
||||||
|
|
||||||
|
export default async function QuestionEditPage({
|
||||||
|
params,
|
||||||
|
}: {
|
||||||
|
params: Promise<{ id: string }>;
|
||||||
|
}) {
|
||||||
|
const questionId = (await params).id;
|
||||||
|
// 获取所有的 codeTemplate
|
||||||
|
const codeTemplates = await prisma.codeTemplate.findMany({
|
||||||
|
where: {
|
||||||
|
questionId: questionId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
// 使用对象映射来存储 CodeTemplate
|
||||||
|
const codeLanguageMap = codeTemplates.reduce((map, codeTemplate) => {
|
||||||
|
map[codeTemplate.language] = codeTemplate;
|
||||||
|
return map;
|
||||||
|
}, {} as Record<CodeLanguage, CodeTemplate>);
|
||||||
|
|
||||||
|
console.log(codeLanguageMap);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Edit Question {questionId}</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
12
src/app/questions/[id]/page.tsx
Normal file
12
src/app/questions/[id]/page.tsx
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
export default async function QuestionPage({
|
||||||
|
params,
|
||||||
|
}: {
|
||||||
|
params: Promise<{ id: string }>;
|
||||||
|
}) {
|
||||||
|
const slug = (await params).id;
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>Question {slug}</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
7
src/app/questions/new/page.tsx
Normal file
7
src/app/questions/new/page.tsx
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
export default function QuestionNewPage() {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>New Question</h1>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
33
src/app/questions/page.tsx
Normal file
33
src/app/questions/page.tsx
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import Link from "next/link";
|
||||||
|
import prisma from "@/lib/prisma";
|
||||||
|
|
||||||
|
export default async function HomePage() {
|
||||||
|
const questions = await prisma.question.findMany();
|
||||||
|
|
||||||
|
const renderedQuestions = questions.map((question) => {
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
key={question.id}
|
||||||
|
href={`/questions/${question.id}`}
|
||||||
|
className="flex justify-between items-center p-2 border rounded"
|
||||||
|
>
|
||||||
|
<div>{question.name}</div>
|
||||||
|
<div>{question.difficulty}</div>
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex justify-center">
|
||||||
|
<div className="container max-w-2xl flex flex-col justify-center">
|
||||||
|
<div className="flex m-2 justify-between items-center">
|
||||||
|
<h1 className="text-xl font-bold">Questions</h1>
|
||||||
|
<Link href="/questions/new" className="border p-2 rounded">
|
||||||
|
New
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col gap-2">{renderedQuestions}</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user