diff --git a/app/actions.ts b/app/actions.ts
new file mode 100644
index 0000000..af32f63
--- /dev/null
+++ b/app/actions.ts
@@ -0,0 +1,18 @@
+"use server";
+
+import { cookies } from "next/headers";
+
+export async function setPlanCookie(plan: string) {
+ //@ts-ignore
+ (await cookies()).set("plan", plan);
+}
+
+export async function getPlanCookie() {
+ const cookieStore = await cookies();
+ //@ts-ignore
+ const plan = await cookieStore.get("plan");
+
+ const out = plan ? plan.value : undefined;
+
+ return out;
+}
diff --git a/app/api/course/route.ts b/app/api/course/route.ts
deleted file mode 100644
index f041c7c..0000000
--- a/app/api/course/route.ts
+++ /dev/null
@@ -1,32 +0,0 @@
-// api/test.ts
-
-import { NextResponse, NextRequest } from "next/server";
-
-import prisma from "@/lib/prisma";
-
-export async function GET(request: NextRequest) {
- const courses = await prisma.course.findMany({
- include: {
- sectionAttributes: true,
- facultyMeet: {
- include: {
- meetingTimes: true,
- },
- },
- instructor: true,
- },
- orderBy: {
- courseTitle: "asc",
- },
- });
-
- return NextResponse.json(courses, { status: 200 });
-}
-
-// To handle a POST request to /api
-/*
-export async function POST(request: NextRequest) {
-
- return NextResponse.json(output, { status: 200 });
-}
-*/
diff --git a/app/api/createplan/route.ts b/app/api/createplan/route.ts
new file mode 100644
index 0000000..b8708f3
--- /dev/null
+++ b/app/api/createplan/route.ts
@@ -0,0 +1,78 @@
+// api/test.ts
+import { NextResponse, NextRequest } from "next/server";
+import prisma from "@/lib/prisma";
+import { getServerSession } from "next-auth/next";
+import { auth } from "@/lib/auth";
+
+export async function POST(request: NextRequest) {
+ const data = await request.json();
+ const session = await auth();
+
+ //@ts-ignore
+ const user = await prisma.user.findUnique({
+ where: {
+ //@ts-ignore
+ uuid: session?.user?.id,
+ },
+ });
+
+ const plan = await prisma.coursePlan.create({
+ data: {
+ //@ts-ignore
+ name: data.planName,
+ year: "F2024",
+ User: {
+ connect: {
+ id: user?.id,
+ },
+ },
+ },
+ });
+
+ return NextResponse.json(plan, { status: 200 });
+}
+
+export async function GET(request: NextRequest) {
+ const session = await auth();
+ const user = await prisma.user.findUnique({
+ where: {
+ //@ts-ignore
+ uuid: session?.user?.id,
+ },
+ });
+ const courses = await prisma.coursePlan.findMany({
+ where: {
+ User: {
+ //@ts-ignore
+ id: user.id,
+ },
+ },
+ include: {
+ courses: true,
+ },
+ });
+ //console.log(plans);
+ return NextResponse.json(courses, { status: 200 });
+}
+
+export async function DELETE(request: NextRequest) {
+ const data = await request.json();
+
+ //@ts-ignore
+ const plan = await prisma.coursePlan.delete({
+ where: {
+ //@ts-ignore
+ id: parseInt(data.planId),
+ },
+ });
+
+ return NextResponse.json(plan, { status: 200 });
+}
+
+// To handle a POST request to /api
+/*
+export async function POST(request: NextRequest) {
+
+ return NextResponse.json(output, { status: 200 });
+}
+*/
diff --git a/app/api/getcourseplans/route.ts b/app/api/getcourseplans/route.ts
new file mode 100644
index 0000000..663d62f
--- /dev/null
+++ b/app/api/getcourseplans/route.ts
@@ -0,0 +1,31 @@
+import { NextResponse, NextRequest } from "next/server";
+import prisma from "@/lib/prisma";
+import { auth } from "@/lib/auth";
+
+export async function GET(request: NextRequest) {
+ const session = await auth();
+ const user = await prisma.user.findUnique({
+ where: {
+ //@ts-ignore
+ uuid: session?.user?.id,
+ },
+ });
+ let courses: any;
+ if (user) {
+ courses = await prisma.coursePlan.findMany({
+ where: {
+ User: {
+ //@ts-ignore
+ id: user.id,
+ },
+ },
+ include: {
+ courses: true,
+ },
+ });
+ } else {
+ courses = null;
+ }
+ //console.log(plans);
+ return NextResponse.json(courses, { status: 200 });
+}
diff --git a/app/api/getplancourses/route.ts b/app/api/getplancourses/route.ts
new file mode 100644
index 0000000..684e5de
--- /dev/null
+++ b/app/api/getplancourses/route.ts
@@ -0,0 +1,27 @@
+// api/test.ts
+import { NextResponse, NextRequest } from "next/server";
+import prisma from "@/lib/prisma";
+import { getServerSession } from "next-auth/next";
+import { auth } from "@/lib/auth";
+import { getPlanCookie } from "@/app/actions";
+
+export async function GET(request: NextRequest) {
+ let planCookie: any = await getPlanCookie();
+ const session = await auth();
+
+ let courses = await prisma.coursePlan.findMany({
+ where: {
+ AND: {
+ User: {
+ //@ts-ignore
+ uuid: session?.user.id,
+ },
+ id: parseInt(planCookie),
+ },
+ },
+ include: {
+ courses: true,
+ },
+ });
+ return NextResponse.json(courses, { status: 200 });
+}
diff --git a/app/api/updatePlan/route.ts b/app/api/updatePlan/route.ts
new file mode 100644
index 0000000..4daa4c9
--- /dev/null
+++ b/app/api/updatePlan/route.ts
@@ -0,0 +1,77 @@
+// api/test.ts
+import { NextResponse, NextRequest } from "next/server";
+import prisma from "@/lib/prisma";
+import { getServerSession } from "next-auth/next";
+import { auth } from "@/lib/auth";
+import { getPlanCookie } from "@/app/actions";
+
+export async function POST(request: NextRequest) {
+ const course = await request.json();
+ const planId = await getPlanCookie();
+
+ if (planId) {
+ let plan: any;
+
+ if (planId) {
+ plan = await prisma.coursePlan.update({
+ where: {
+ id: parseInt(planId),
+ },
+ data: {
+ courses: {
+ connect: {
+ id: course.course.id,
+ },
+ },
+ },
+ });
+ }
+ }
+
+ return NextResponse.json(planId, { status: 200 });
+}
+
+export async function GET(request: NextRequest) {
+ const session = await auth();
+ const user = await prisma.user.findUnique({
+ where: {
+ //@ts-ignore
+ uuid: session?.user?.id,
+ },
+ });
+ const courses = await prisma.coursePlan.findMany({
+ where: {
+ User: {
+ //@ts-ignore
+ id: user.id,
+ },
+ },
+ include: {
+ courses: true,
+ },
+ });
+ console.log(courses);
+ return NextResponse.json(courses, { status: 200 });
+}
+
+export async function DELETE(request: NextRequest) {
+ const data = await request.json();
+
+ //@ts-ignore
+ const plan = await prisma.coursePlan.delete({
+ where: {
+ //@ts-ignore
+ id: parseInt(data.planId),
+ },
+ });
+
+ return NextResponse.json(plan, { status: 200 });
+}
+
+// To handle a POST request to /api
+/*
+export async function POST(request: NextRequest) {
+
+ return NextResponse.json(output, { status: 200 });
+}
+*/
diff --git a/app/api/user/route.ts b/app/api/user/route.ts
new file mode 100644
index 0000000..97f400a
--- /dev/null
+++ b/app/api/user/route.ts
@@ -0,0 +1,50 @@
+// api/test.ts
+import { NextResponse, NextRequest } from "next/server";
+import prisma from "@/lib/prisma";
+
+export async function POST(request: NextRequest) {
+ const data = await request.json();
+ //@ts-ignore
+ const session = data?.session;
+
+ const user = await prisma.user.upsert({
+ where: {
+ //@ts-ignore
+ uuid: session?.user?.id,
+ },
+ update: {
+ //@ts-ignore
+ uuid: session?.user?.id,
+ email: session?.user?.email,
+ name: session?.user?.name,
+ },
+ create: {
+ //@ts-ignore
+ uuid: session?.user?.id,
+ email: session?.user?.email,
+ name: session?.user?.name,
+ },
+ });
+
+ return NextResponse.json(user, { status: 200 });
+}
+
+export async function GET(request: NextRequest) {
+ /*
+ const session = data.session;
+ const user = await prisma.user.findUnique({
+ where: {
+ //@ts-ignore
+ id: session?.user?.id,
+ },
+ });
+*/
+ return NextResponse.json("HI", { status: 200 });
+}
+// To handle a POST request to /api
+/*
+export async function POST(request: NextRequest) {
+
+ return NextResponse.json(output, { status: 200 });
+}
+*/
diff --git a/app/blog/layout.tsx b/app/blog/layout.tsx
deleted file mode 100644
index 911d0bc..0000000
--- a/app/blog/layout.tsx
+++ /dev/null
@@ -1,13 +0,0 @@
-export default function BlogLayout({
- children,
-}: {
- children: React.ReactNode;
-}) {
- return (
-