From 67cf9c5d290fdf61e4bce1b9ae25676e0c6e9486 Mon Sep 17 00:00:00 2001 From: Damian <37555910+DCRepublic@users.noreply.github.com> Date: Sun, 10 Nov 2024 20:07:13 -0500 Subject: [PATCH 1/2] Finish ratings, lint code, add basic splash page --- .eslintrc.json | 13 +- .prettierrc | 6 + app/api/auth/[...nextauth]/route.ts | 1 + app/api/createplan/route.ts | 3 +- app/api/getCourses/route.ts | 15 - app/api/getProfClasses/route.ts | 24 + app/api/getProfs/route.ts | 9 + app/api/getcourseplans/route.ts | 3 + app/api/getplancourses/route.ts | 9 +- app/api/submitReview/route.ts | 39 ++ app/api/updatePlan/route.ts | 4 +- app/api/user/route.ts | 1 + app/calendar/page.tsx | 25 +- app/error.tsx | 2 +- app/layout.tsx | 10 +- app/login/layout.tsx | 13 + app/login/page.tsx | 20 +- app/page.tsx | 25 +- app/rating/layout.tsx | 4 +- app/rating/page.tsx | 427 ++++++++++++++++-- components/Calendar.tsx | 20 +- components/CourseCard.tsx | 209 ++++----- components/CreatePlan.tsx | 48 +- components/FullCourseList.tsx | 17 +- components/PlanCard.tsx | 3 +- components/PlanCardList.tsx | 5 +- components/Search.tsx | 44 +- components/navbar.tsx | 67 ++- components/theme-switch.tsx | 5 +- config/site.ts | 32 +- lib/auth.ts | 3 + package-lock.json | 179 +++++--- package.json | 14 +- .../20241110205804_fix_prof/migration.sql | 11 + .../20241110210423_fix_prof2/migration.sql | 8 + .../20241111004015_fix_rating/migration.sql | 16 + prisma/schema.prisma | 24 +- 37 files changed, 968 insertions(+), 390 deletions(-) create mode 100644 .prettierrc delete mode 100644 app/api/getCourses/route.ts create mode 100644 app/api/getProfClasses/route.ts create mode 100644 app/api/getProfs/route.ts create mode 100644 app/api/submitReview/route.ts create mode 100644 app/login/layout.tsx create mode 100644 prisma/migrations/20241110205804_fix_prof/migration.sql create mode 100644 prisma/migrations/20241110210423_fix_prof2/migration.sql create mode 100644 prisma/migrations/20241111004015_fix_rating/migration.sql diff --git a/.eslintrc.json b/.eslintrc.json index d3067d4..0b48bc4 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -11,7 +11,14 @@ "plugin:react-hooks/recommended", "plugin:jsx-a11y/recommended" ], - "plugins": ["react", "unused-imports", "import", "@typescript-eslint", "jsx-a11y", "prettier"], + "plugins": [ + "react", + "unused-imports", + "import", + "@typescript-eslint", + "jsx-a11y", + "prettier" + ], "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaFeatures": { @@ -80,8 +87,8 @@ ], "padding-line-between-statements": [ "warn", - {"blankLine": "always", "prev": "*", "next": "return"}, - {"blankLine": "always", "prev": ["const", "let", "var"], "next": "*"}, + { "blankLine": "always", "prev": "*", "next": "return" }, + { "blankLine": "always", "prev": ["const", "let", "var"], "next": "*" }, { "blankLine": "any", "prev": ["const", "let", "var"], diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..d85a09c --- /dev/null +++ b/.prettierrc @@ -0,0 +1,6 @@ +{ + "endOfLint": "lf", + "printWidhth": 80, + "tabWidth": 2, + "trailingComma": "es5" +} diff --git a/app/api/auth/[...nextauth]/route.ts b/app/api/auth/[...nextauth]/route.ts index 4de5853..830090d 100644 --- a/app/api/auth/[...nextauth]/route.ts +++ b/app/api/auth/[...nextauth]/route.ts @@ -1,5 +1,6 @@ export const dynamic = "force-dynamic"; // defaults to auto import NextAuth from "next-auth"; + import { config } from "../../../../lib/auth"; const handler = NextAuth(config); diff --git a/app/api/createplan/route.ts b/app/api/createplan/route.ts index 5d60712..589ec6e 100644 --- a/app/api/createplan/route.ts +++ b/app/api/createplan/route.ts @@ -1,7 +1,7 @@ // 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) { @@ -51,6 +51,7 @@ export async function GET(request: NextRequest) { courses: true, }, }); + //console.log(plans); return NextResponse.json(courses, { status: 200 }); } diff --git a/app/api/getCourses/route.ts b/app/api/getCourses/route.ts deleted file mode 100644 index b4c5cfb..0000000 --- a/app/api/getCourses/route.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { NextResponse, NextRequest } from "next/server"; -import prisma from "../../../lib/prisma"; -import { auth } from "../../../lib/auth"; - -export async function GET(request: NextRequest) { - const courses = await prisma.course.findMany({ - select: { - id: true, - courseTitle: true, - }, - where: { year: "S2025" }, - }); - //console.log(plans); - return NextResponse.json(courses, { status: 200 }); -} diff --git a/app/api/getProfClasses/route.ts b/app/api/getProfClasses/route.ts new file mode 100644 index 0000000..3db68cb --- /dev/null +++ b/app/api/getProfClasses/route.ts @@ -0,0 +1,24 @@ +import { Faculty } from "./../../../node_modules/.prisma/client/index.d"; +import { NextResponse, NextRequest } from "next/server"; + +import prisma from "../../../lib/prisma"; + +export async function GET(request: NextRequest) { + const { searchParams } = await new URL(request.url); + const profID = parseInt((await searchParams.get("prof")) || "1"); + + const courses = await prisma.course.findMany({ + include: { + instructor: true, + }, + where: { + instructor: { + id: profID, + }, + }, + }); + + //console.log(plans); + console.log(courses); + return NextResponse.json(courses, { status: 200 }); +} diff --git a/app/api/getProfs/route.ts b/app/api/getProfs/route.ts new file mode 100644 index 0000000..2bba2d5 --- /dev/null +++ b/app/api/getProfs/route.ts @@ -0,0 +1,9 @@ +import { NextResponse, NextRequest } from "next/server"; + +import prisma from "../../../lib/prisma"; + +export async function GET(request: NextRequest) { + const profs = await prisma.faculty.findMany({}); + + return NextResponse.json(profs, { status: 200 }); +} diff --git a/app/api/getcourseplans/route.ts b/app/api/getcourseplans/route.ts index e948931..ec57edc 100644 --- a/app/api/getcourseplans/route.ts +++ b/app/api/getcourseplans/route.ts @@ -1,4 +1,5 @@ import { NextResponse, NextRequest } from "next/server"; + import prisma from "../../../lib/prisma"; import { auth } from "../../../lib/auth"; @@ -11,6 +12,7 @@ export async function GET(request: NextRequest) { }, }); let courses: any; + if (user) { courses = await prisma.coursePlan.findMany({ where: { @@ -26,6 +28,7 @@ export async function GET(request: NextRequest) { } 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 index bb2876c..f454ccb 100644 --- a/app/api/getplancourses/route.ts +++ b/app/api/getplancourses/route.ts @@ -1,15 +1,15 @@ // 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 planCookie: any = await getPlanCookie(); const session = await auth(); - let courses = await prisma.coursePlan.findMany({ + const courses = await prisma.coursePlan.findMany({ where: { AND: { User: { @@ -23,6 +23,7 @@ export async function GET(request: NextRequest) { courses: true, }, }); + return NextResponse.json(courses, { status: 200 }); } @@ -33,7 +34,7 @@ export async function POST(request: NextRequest) { const plan = data.plan; const session = await auth(); - let courses = await prisma.coursePlan.update({ + const courses = await prisma.coursePlan.update({ where: { id: parseInt(plan), }, diff --git a/app/api/submitReview/route.ts b/app/api/submitReview/route.ts new file mode 100644 index 0000000..caedabd --- /dev/null +++ b/app/api/submitReview/route.ts @@ -0,0 +1,39 @@ +import { NextResponse, NextRequest } from "next/server"; + +import prisma from "../../../lib/prisma"; +import { auth } from "../../../lib/auth"; + +export async function POST(request: NextRequest) { + const data = await request.json(); + const facultyID = parseInt(await data.facultyID); + const courseID = parseInt(await data.courseID); + + const session = await auth(); + + //@ts-ignore + const user = await prisma.user.findUnique({ + where: { + //@ts-ignore + uuid: session?.user?.id, + }, + }); + if (user?.id) { + const newReview = await prisma.rating.create({ + data: { + userId: user?.id, + courseID: courseID, + facultyID: facultyID, + overallRating: data.overallRating, + difficulty: data.difficulty, + takeAgain: data.takeAgain, + forCredit: data.forCredit, + grade: data.grade, + review: data.review, + }, + }); + return NextResponse.json(newReview, { status: 200 }); + } + + //console.log(plans); + return NextResponse.json("Submission Failed, no user", { status: 500 }); +} diff --git a/app/api/updatePlan/route.ts b/app/api/updatePlan/route.ts index 215ecec..c5177e6 100644 --- a/app/api/updatePlan/route.ts +++ b/app/api/updatePlan/route.ts @@ -1,7 +1,7 @@ // 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"; @@ -50,7 +50,9 @@ export async function GET(request: NextRequest) { courses: true, }, }); + console.log(courses); + return NextResponse.json(courses, { status: 200 }); } diff --git a/app/api/user/route.ts b/app/api/user/route.ts index 9977879..5842a7d 100644 --- a/app/api/user/route.ts +++ b/app/api/user/route.ts @@ -1,5 +1,6 @@ // api/test.ts import { NextResponse, NextRequest } from "next/server"; + import prisma from "../../../lib/prisma"; export async function POST(request: NextRequest) { diff --git a/app/calendar/page.tsx b/app/calendar/page.tsx index 2697e13..c31e87c 100644 --- a/app/calendar/page.tsx +++ b/app/calendar/page.tsx @@ -1,22 +1,19 @@ -import { title } from "../../components/primitives"; -import FullCalendar from "@fullcalendar/react"; -import timeGridPlugin from "@fullcalendar/timegrid"; // a plugin! +// a plugin! + import CreatePlan from "../../components/CreatePlan"; -import moment from "moment"; import Calendar from "../../components/Calendar"; import prisma from "../../lib/prisma"; -import { auth } from "../../lib/auth"; import { getPlanCookie } from "../actions"; -import { BorderColor } from "@mui/icons-material"; import { generateColorFromName } from "../../components/primitives"; export default async function CalendarPage() { async function getEvents() { - let output: any = []; - let planCookie: any = await getPlanCookie(); + const output: any = []; + const planCookie: any = await getPlanCookie(); let courses; + if (planCookie) { - let plan = await prisma.coursePlan.findUnique({ + const plan = await prisma.coursePlan.findUnique({ where: { id: parseInt(planCookie), }, @@ -30,10 +27,10 @@ export default async function CalendarPage() { if (courses) { for (let i = 0; i < courses.length; i++) { - let color = generateColorFromName(courses[i].subject); + const color = generateColorFromName(courses[i].subject); - let num: string = courses[i].courseReferenceNumber; - let meetingTimes = await prisma.meetingTime.findFirst({ + const num: string = courses[i].courseReferenceNumber; + const meetingTimes = await prisma.meetingTime.findFirst({ where: { courseReferenceNumber: num, }, @@ -99,10 +96,12 @@ export default async function CalendarPage() { maxstart?.endTime.slice(0, 2) + ":" + maxstart?.beginTime.slice(2), };*/ console.log(maxstart); + return maxstart; } - let events = await getEvents(); + const events = await getEvents(); + //let times = await getUniqueStartEndTimes(); return (
diff --git a/app/error.tsx b/app/error.tsx index 9ed5104..60c7801 100644 --- a/app/error.tsx +++ b/app/error.tsx @@ -11,7 +11,7 @@ export default function Error({ }) { useEffect(() => { // Log the error to an error reporting service - /* eslint-disable no-console */ + console.error(error); }, [error]); diff --git a/app/layout.tsx b/app/layout.tsx index 9a5676d..5f90469 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -2,15 +2,15 @@ import "../styles/globals.css"; import { Metadata, Viewport } from "next"; import { Link } from "@nextui-org/link"; import clsx from "clsx"; - -import { Providers } from "./providers"; -import { NextAuthProvider } from "../components/providers/NextAuthProvider"; import { CookiesProvider } from "next-client-cookies/server"; +import { NextAuthProvider } from "../components/providers/NextAuthProvider"; import { siteConfig } from "../config/site"; import { fontSans } from "../config/fonts"; import { Navbar } from "../components/navbar"; +import { Providers } from "./providers"; + export const metadata: Metadata = { title: { default: siteConfig.name, @@ -52,14 +52,14 @@ export default function RootLayout({ defaultTheme: "dark", }} > -
+
{children}