diff --git a/.gitignore b/.gitignore index d960b42..1ecc0ee 100644 --- a/.gitignore +++ b/.gitignore @@ -43,4 +43,7 @@ next-env.d.ts bun.lockb # cache -cache \ No newline at end of file +cache + +# prisma +prisma/migrations \ No newline at end of file diff --git a/package.json b/package.json index f19fb86..ef80c33 100644 --- a/package.json +++ b/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" } } diff --git a/prisma/schema.prisma b/prisma/schema.prisma new file mode 100644 index 0000000..aabe433 --- /dev/null +++ b/prisma/schema.prisma @@ -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 +} diff --git a/src/actions/index.ts b/src/actions/index.ts new file mode 100644 index 0000000..d3b6f85 --- /dev/null +++ b/src/actions/index.ts @@ -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"); +} diff --git a/src/app/problemset/new/page.tsx b/src/app/problemset/new/page.tsx new file mode 100644 index 0000000..91220f5 --- /dev/null +++ b/src/app/problemset/new/page.tsx @@ -0,0 +1,3 @@ +export default function ProblemCreatePage() { + return