From de852382d175b5ccba4dc9620a51f792bed585f0 Mon Sep 17 00:00:00 2001 From: Damian <37555910+DCRepublic@users.noreply.github.com> Date: Fri, 8 Nov 2024 13:49:23 -0500 Subject: [PATCH] DB:Allow scrapper to add all atributes --- app/page.tsx | 17 ++- components/FullCourseList.tsx | 106 ++++++++++++------ components/Search.tsx | 60 +++++++++- .../migration.sql | 29 +++++ .../migration.sql | 20 ++++ .../migration.sql | 14 +++ prisma/schema.prisma | 2 +- 7 files changed, 208 insertions(+), 40 deletions(-) create mode 100644 prisma/migrations/20241108165116_section_attribute_change/migration.sql create mode 100644 prisma/migrations/20241108165432_section_attribute_change1/migration.sql create mode 100644 prisma/migrations/20241108170518_section_attribute_change1/migration.sql diff --git a/app/page.tsx b/app/page.tsx index b972bcf..beecd91 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -9,6 +9,7 @@ import { auth } from "../lib/auth"; import prisma from "../lib/prisma"; import { Course, CoursePlan } from "@prisma/client"; import { getPlanCookie } from "../app/actions"; +import { dA } from "@fullcalendar/core/internal-common"; async function getCourses() { const courses = await prisma.course.findMany(); @@ -47,6 +48,19 @@ async function getUniqueStartEndTimes() { return times; } +async function getUniquCodes() { + const codes = await prisma.sectionAttribute.findMany(); + let daCodes: any = []; + + for (let i = 0; i < codes.length; i++) { + if (!daCodes.includes(codes[i].code)) { + daCodes.push(codes[i].code); + } + } + console.log(daCodes); + return daCodes; +} + export default async function Page(props: { searchParams?: Promise<{ query?: string; @@ -88,6 +102,7 @@ export default async function Page(props: { async function Home(props: any) { const terms = await getCourses(); const uniqueTimes = await getUniqueStartEndTimes(); + const codes = await getUniquCodes(); return ( <> @@ -95,7 +110,7 @@ async function Home(props: any) {
- +
{props.fullCourseList} diff --git a/components/FullCourseList.tsx b/components/FullCourseList.tsx index 5437bb5..f30e20f 100644 --- a/components/FullCourseList.tsx +++ b/components/FullCourseList.tsx @@ -11,9 +11,10 @@ async function getCourses( ) { //let DOTW: Array = dotw.split(","); + //query = query.trim().replace(/^[a-zA-Z0-9:]+$/g, ""); + let startTime = stime.toString().split(",").filter(Number); - console.log(startTime); return await prisma.course.findMany({ relationLoadStrategy: "join", // or 'query' include: { @@ -36,46 +37,81 @@ async function getCourses( }, ], where: { - ...(term + ...(query ? { - year: term, - } - : {}), - //year: term, - - OR: [ - { courseTitle: { search: query.trim().split(" ").join(" & ") } }, - { subject: { search: query.trim().split(" ").join(" & ") } }, - { courseNumber: { search: query.trim().split(" ").join(" & ") } }, - ], + ...(term + ? { + year: term, + } + : {}), + //year: term, - ...(startTime.length > 0 - ? { - facultyMeet: { - meetingTimes: { - beginTime: { - in: startTime, + OR: [ + { + courseTitle: { + search: query.trim().split(" ").join(" | "), + mode: "insensitive", }, }, - }, - } - : {}), - - ...(dotw.length > 0 - ? { - facultyMeet: { - meetingTimes: { - is: { - monday: dotw.includes("monday") ? true : Prisma.skip, - tuesday: dotw.includes("tuesday") ? true : Prisma.skip, - wednesday: dotw.includes("wednesday") ? true : Prisma.skip, - thursday: dotw.includes("thursday") ? true : Prisma.skip, - friday: dotw.includes("friday") ? true : Prisma.skip, - saturday: dotw.includes("saturday") ? true : Prisma.skip, - sunday: dotw.includes("sunday") ? true : Prisma.skip, + { + sectionAttributes: { + some: { + code: { + search: query.trim().split(" ").join(" | "), + mode: "insensitive", + }, + }, + }, + }, + { + subject: { + search: query.trim().split(" ").join(" | "), + mode: "insensitive", }, }, - }, + { + courseNumber: { + search: query.trim().split(" ").join(" | "), + mode: "insensitive", + }, + }, + ], + + ...(startTime.length > 0 + ? { + facultyMeet: { + meetingTimes: { + beginTime: { + in: startTime, + }, + }, + }, + } + : {}), + + ...(dotw.length > 0 + ? { + facultyMeet: { + meetingTimes: { + is: { + monday: dotw.includes("monday") ? true : Prisma.skip, + tuesday: dotw.includes("tuesday") ? true : Prisma.skip, + wednesday: dotw.includes("wednesday") + ? true + : Prisma.skip, + thursday: dotw.includes("thursday") + ? true + : Prisma.skip, + friday: dotw.includes("friday") ? true : Prisma.skip, + saturday: dotw.includes("saturday") + ? true + : Prisma.skip, + sunday: dotw.includes("sunday") ? true : Prisma.skip, + }, + }, + }, + } + : {}), } : {}), }, diff --git a/components/Search.tsx b/components/Search.tsx index d84a284..aa304ee 100644 --- a/components/Search.tsx +++ b/components/Search.tsx @@ -6,19 +6,42 @@ import { useDebouncedCallback } from "use-debounce"; import { Select, SelectItem } from "@nextui-org/react"; import { useEffect, useState } from "react"; import moment from "moment"; +import { Autocomplete, TextField, Chip } from "@mui/material"; + export default function Search(props: any) { let router = useRouter(); const searchParams = useSearchParams(); - const [selectedTerm, setSelectedTerm]: any = useState([]); + const [selectedTerm, setSelectedTerm]: any = useState(["S2025"]); const [selectedDOTW, setSelectedDOTW]: any = useState([]); + const [selectedCodes, setSelectedCodes]: any = useState([]); + const [selectedStartTime, setSelectedStartTime]: any = useState([]); + const [search, setSearch]: any = useState(); const pathname = usePathname(); const { replace } = useRouter(); + const replaceText = (text: any) => { + setSearch(text?.replace(/\w+:/, {text})); + console.log(search); + }; + const handleSearch = useDebouncedCallback((term: string) => { + //replaceText(term); + //setSearch(term); + //const term_regex = new RegExp(\w, "g"); + let filtered_term = term.replace(/[^a-zA-Z0-9 ]+/gi, ""); + let include_colons = term.replace(/[^a-zA-Z0-9: ]+/gi, ""); + let term_list = include_colons.split(" "); + + for (var i = 0; i < term_list.length; i++) { + if (/\w+:/.test(term_list[i])) { + console.log(term_list[i]); + } + } const params = new URLSearchParams(searchParams); if (term) { - params.set("query", term); + decodeURIComponent; + params.set("query", filtered_term); } else { params.delete("query"); } @@ -28,6 +51,7 @@ export default function Search(props: any) { const handleSelectionChange = (e: any) => { setSelectedTerm([e.target.value]); const params = new URLSearchParams(searchParams); + if (e.target.value) { params.set("term", e.target.value); } else { @@ -40,6 +64,18 @@ export default function Search(props: any) { //setPlanCookie(e.target.value); }; + const handleCodeChange = (e: any) => { + setSelectedCodes([e.target.value]); + const params = new URLSearchParams(searchParams); + + if (e.target.value) { + params.set("codes", e.target.value); + } else { + params.delete("codes"); + } + replace(`${pathname}?${params.toString()}`); + }; + useEffect(() => { // Update the document title using the browser API setSelectedTerm(searchParams.get("term")?.toString().split(",")); @@ -102,6 +138,7 @@ export default function Search(props: any) { label="Search" labelPlacement="inside" variant="bordered" + value={search} onClear={() => { handleSearch(""); }} @@ -163,7 +200,6 @@ export default function Search(props: any) { var time = startTime.slice(0, 2) + ":" + startTime.slice(2); var daTime = moment(time, "HH:mm").format("hh:mm A"); - console.log(daTime); return ( {daTime} @@ -171,6 +207,24 @@ export default function Search(props: any) { ); })} + {/* + + */}
); } diff --git a/prisma/migrations/20241108165116_section_attribute_change/migration.sql b/prisma/migrations/20241108165116_section_attribute_change/migration.sql new file mode 100644 index 0000000..9dee958 --- /dev/null +++ b/prisma/migrations/20241108165116_section_attribute_change/migration.sql @@ -0,0 +1,29 @@ +/* + Warnings: + + - You are about to drop the column `courseId` on the `sectionAttribute` table. All the data in the column will be lost. + +*/ +-- DropForeignKey +ALTER TABLE "sectionAttribute" DROP CONSTRAINT "sectionAttribute_courseId_fkey"; + +-- AlterTable +ALTER TABLE "sectionAttribute" DROP COLUMN "courseId"; + +-- CreateTable +CREATE TABLE "_CourseTosectionAttribute" ( + "A" INTEGER NOT NULL, + "B" INTEGER NOT NULL +); + +-- CreateIndex +CREATE UNIQUE INDEX "_CourseTosectionAttribute_AB_unique" ON "_CourseTosectionAttribute"("A", "B"); + +-- CreateIndex +CREATE INDEX "_CourseTosectionAttribute_B_index" ON "_CourseTosectionAttribute"("B"); + +-- AddForeignKey +ALTER TABLE "_CourseTosectionAttribute" ADD CONSTRAINT "_CourseTosectionAttribute_A_fkey" FOREIGN KEY ("A") REFERENCES "Course"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_CourseTosectionAttribute" ADD CONSTRAINT "_CourseTosectionAttribute_B_fkey" FOREIGN KEY ("B") REFERENCES "sectionAttribute"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/20241108165432_section_attribute_change1/migration.sql b/prisma/migrations/20241108165432_section_attribute_change1/migration.sql new file mode 100644 index 0000000..0ddcccc --- /dev/null +++ b/prisma/migrations/20241108165432_section_attribute_change1/migration.sql @@ -0,0 +1,20 @@ +/* + Warnings: + + - You are about to drop the `_CourseTosectionAttribute` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropForeignKey +ALTER TABLE "_CourseTosectionAttribute" DROP CONSTRAINT "_CourseTosectionAttribute_A_fkey"; + +-- DropForeignKey +ALTER TABLE "_CourseTosectionAttribute" DROP CONSTRAINT "_CourseTosectionAttribute_B_fkey"; + +-- AlterTable +ALTER TABLE "sectionAttribute" ADD COLUMN "courseId" INTEGER; + +-- DropTable +DROP TABLE "_CourseTosectionAttribute"; + +-- AddForeignKey +ALTER TABLE "sectionAttribute" ADD CONSTRAINT "sectionAttribute_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "Course"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/migrations/20241108170518_section_attribute_change1/migration.sql b/prisma/migrations/20241108170518_section_attribute_change1/migration.sql new file mode 100644 index 0000000..3760707 --- /dev/null +++ b/prisma/migrations/20241108170518_section_attribute_change1/migration.sql @@ -0,0 +1,14 @@ +/* + Warnings: + + - Made the column `courseId` on table `sectionAttribute` required. This step will fail if there are existing NULL values in that column. + +*/ +-- DropForeignKey +ALTER TABLE "sectionAttribute" DROP CONSTRAINT "sectionAttribute_courseId_fkey"; + +-- AlterTable +ALTER TABLE "sectionAttribute" ALTER COLUMN "courseId" SET NOT NULL; + +-- AddForeignKey +ALTER TABLE "sectionAttribute" ADD CONSTRAINT "sectionAttribute_courseId_fkey" FOREIGN KEY ("courseId") REFERENCES "Course"("id") ON DELETE RESTRICT ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index dd24487..98731af 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -99,7 +99,7 @@ model sectionAttribute { code String description String courseReferenceNumber String @unique - courseId Int? + courseId Int Course Course? @relation(fields: [courseId], references: [id]) year String }