mirror of
https://litchi.icu/ngc2207/judge4c-latest.git
synced 2025-07-13 09:34:36 +00:00
chore: update .gitignore and package.json
feat: add prisma and prisma client feat: add problem schema feat: add problem create page
This commit is contained in:
parent
b34901bc14
commit
68af6e813e
5
.gitignore
vendored
5
.gitignore
vendored
@ -43,4 +43,7 @@ next-env.d.ts
|
||||
bun.lockb
|
||||
|
||||
# cache
|
||||
cache
|
||||
cache
|
||||
|
||||
# prisma
|
||||
prisma/migrations
|
10
package.json
10
package.json
@ -9,6 +9,7 @@
|
||||
"lint": "next lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@prisma/client": "^5.21.1",
|
||||
"@radix-ui/react-avatar": "^1.1.1",
|
||||
"@radix-ui/react-collapsible": "^1.1.1",
|
||||
"@radix-ui/react-dialog": "^1.1.2",
|
||||
@ -27,13 +28,14 @@
|
||||
"tailwindcss-animate": "^1.0.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"typescript": "^5",
|
||||
"@types/node": "^20",
|
||||
"@types/react": "^18",
|
||||
"@types/react-dom": "^18",
|
||||
"postcss": "^8",
|
||||
"tailwindcss": "^3.4.1",
|
||||
"eslint": "^8",
|
||||
"eslint-config-next": "15.0.2"
|
||||
"eslint-config-next": "15.0.2",
|
||||
"postcss": "^8",
|
||||
"prisma": "^5.21.1",
|
||||
"tailwindcss": "^3.4.1",
|
||||
"typescript": "^5"
|
||||
}
|
||||
}
|
||||
|
15
prisma/schema.prisma
Normal file
15
prisma/schema.prisma
Normal file
@ -0,0 +1,15 @@
|
||||
generator client {
|
||||
provider = "prisma-client-js"
|
||||
}
|
||||
|
||||
datasource db {
|
||||
provider = "postgresql"
|
||||
url = env("DATABASE_URL")
|
||||
}
|
||||
|
||||
model Problem {
|
||||
id Int @id @default(autoincrement())
|
||||
title String
|
||||
difficulty String
|
||||
description String
|
||||
}
|
36
src/actions/index.ts
Normal file
36
src/actions/index.ts
Normal file
@ -0,0 +1,36 @@
|
||||
"use server";
|
||||
|
||||
import { redirect } from "next/navigation";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { db } from "@/db";
|
||||
|
||||
export async function createProblem(
|
||||
formState: { message: string },
|
||||
formData: FormData
|
||||
) {
|
||||
try {
|
||||
const title = formData.get("title") as string;
|
||||
const difficulty = formData.get("difficulty") as string;
|
||||
const description = formData.get("description") as string;
|
||||
|
||||
await db.problem.create({
|
||||
data: {
|
||||
title,
|
||||
difficulty,
|
||||
description,
|
||||
},
|
||||
});
|
||||
} catch (err: unknown) {
|
||||
if (err instanceof Error) {
|
||||
return {
|
||||
message: err.message,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
message: "Something went wrong...",
|
||||
};
|
||||
}
|
||||
}
|
||||
revalidatePath("/problemset");
|
||||
redirect("/problemset");
|
||||
}
|
3
src/app/problemset/new/page.tsx
Normal file
3
src/app/problemset/new/page.tsx
Normal file
@ -0,0 +1,3 @@
|
||||
export default function ProblemCreatePage() {
|
||||
return <div>Problem Create Page</div>;
|
||||
}
|
3
src/app/problemset/page.tsx
Normal file
3
src/app/problemset/page.tsx
Normal file
@ -0,0 +1,3 @@
|
||||
export default function ProblemsetPage() {
|
||||
return <div>Problemset Page</div>;
|
||||
}
|
3
src/db/index.ts
Normal file
3
src/db/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { PrismaClient } from "@prisma/client";
|
||||
|
||||
export const db = new PrismaClient();
|
Loading…
Reference in New Issue
Block a user