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:
ngc2207 2024-11-03 00:33:02 +08:00
parent b34901bc14
commit 68af6e813e
7 changed files with 70 additions and 5 deletions

5
.gitignore vendored
View File

@ -43,4 +43,7 @@ next-env.d.ts
bun.lockb bun.lockb
# cache # cache
cache cache
# prisma
prisma/migrations

View File

@ -9,6 +9,7 @@
"lint": "next lint" "lint": "next lint"
}, },
"dependencies": { "dependencies": {
"@prisma/client": "^5.21.1",
"@radix-ui/react-avatar": "^1.1.1", "@radix-ui/react-avatar": "^1.1.1",
"@radix-ui/react-collapsible": "^1.1.1", "@radix-ui/react-collapsible": "^1.1.1",
"@radix-ui/react-dialog": "^1.1.2", "@radix-ui/react-dialog": "^1.1.2",
@ -27,13 +28,14 @@
"tailwindcss-animate": "^1.0.7" "tailwindcss-animate": "^1.0.7"
}, },
"devDependencies": { "devDependencies": {
"typescript": "^5",
"@types/node": "^20", "@types/node": "^20",
"@types/react": "^18", "@types/react": "^18",
"@types/react-dom": "^18", "@types/react-dom": "^18",
"postcss": "^8",
"tailwindcss": "^3.4.1",
"eslint": "^8", "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
View 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
View 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");
}

View File

@ -0,0 +1,3 @@
export default function ProblemCreatePage() {
return <div>Problem Create Page</div>;
}

View File

@ -0,0 +1,3 @@
export default function ProblemsetPage() {
return <div>Problemset Page</div>;
}

3
src/db/index.ts Normal file
View File

@ -0,0 +1,3 @@
import { PrismaClient } from "@prisma/client";
export const db = new PrismaClient();