Skip to content

Demo #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 47 additions & 64 deletions overload/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion overload/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"@nextui-org/react": "^2.2.9",
"@prisma/client": "^5.5.2",
"framer-motion": "^10.16.16",
"next": "13.5.6",
"next": "^14.0.5-canary.56",
"prisma": "^5.5.2",
"react": "^18",
"react-dom": "^18"
Expand Down
1 change: 1 addition & 0 deletions overload/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

generator client {
provider = "prisma-client-js"
previewFeatures = ["referentialIntegrity"]
}

datasource db {
Expand Down
1 change: 0 additions & 1 deletion overload/src/app/api/course-details/[courseCode]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export async function GET(request: NextRequest, { params }: { params: { courseCo
courseCode: courseCode,
},
});

if (course) {
return NextResponse.json(course, { status: 200 });
} else {
Expand Down
46 changes: 46 additions & 0 deletions overload/src/app/api/course-update/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { NextRequest, NextResponse } from 'next/server';
import prisma from '../../../../prisma/client';

// Update doom voters (still under progress)
export async function PUT(req: Request) {
if (req.method === "PUT") {
try {
// const data = await req.body.json();
const body = await req.json();
let { doomness, courseCode } = body;
// Find course details
const course = await prisma.course.findUnique({
where: {
courseCode: courseCode,
},
});
// Update course details
if (course?.doomness !== null) {
let newDoomness: number = (parseInt(doomness) + parseInt((course as any).doomness))/2;
const updatedCourse = await prisma.course.update({
where: { courseCode: courseCode },
data: {
doomness: newDoomness,
doomnessVoters: (parseInt((course as any).doomnessVoters) + 1)
}
});
return NextResponse.json(updatedCourse, { status: 200 });
} else {
return NextResponse.json(
{ error: 'Course not found' },
{ status: 404 }
);
}
} catch (error) {
return NextResponse.json(
{ error: 'Internal server error' },
{ status: 500 }
);
}
} else {
return NextResponse.json(
{ error: 'Course code is empty' },
{ status: 400 }
);
}
}
6 changes: 2 additions & 4 deletions overload/src/app/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ export const SearchBar = ({ filterOn, setFilterOn }: SearchBarProps) => {

React.useEffect(() => {
// Fetch the term list
fetch('http://localhost:3000/api/home', { cache: 'no-store' }) // Fetch terms
fetch('/api/home', { cache: 'no-store' }) // Fetch terms
.then((response) => response.json()) // turn data from promise into a json file so we can use data
.then((data) => {
setDataList(data);
console.log(data)
}) // set data using setData hook
.catch((error) => {
// if promise not fulfilled
Expand Down Expand Up @@ -93,6 +94,3 @@ export const SearchBar = ({ filterOn, setFilterOn }: SearchBarProps) => {
</div>
);
};

// pull filter
// for each thingy
4 changes: 2 additions & 2 deletions overload/src/app/components/courseOption.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';
import { Button } from '@nextui-org/react';
import { Course } from '../home/page';
import { Course } from '../types';

type CourseOptionProps = {
course: Course;
Expand All @@ -12,7 +12,7 @@ export const CourseOption = ({
}: CourseOptionProps) => {
return (
<div
className=" flex justify-center bg-white m-5 cursor-pointer"
className=" flex justify-center bg-white m-5 cursor-pointer rounded-md"
onClick={() => handleSelectCourse(course)}
>
{course.courseCode}: {course.courseName}
Expand Down
2 changes: 1 addition & 1 deletion overload/src/app/components/coursesList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client';
import { Course } from '../home/page';
import { Course } from '../types';
import CourseOption from './courseOption';

type CoursesListProps = {
Expand Down
4 changes: 1 addition & 3 deletions overload/src/app/components/selectedCourse.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { Course } from '../home/page';

type SelectedCourseProps = {
courseCode: string;
courseName: string;
Expand All @@ -13,7 +11,7 @@ export const SelectedCourse = ({
}: SelectedCourseProps) => {
return (
<div
className="bg-white w-[100%] m-3 rounded-md cursor-pointer"
className="bg-white w-[100%] m-3 p-1 rounded-md cursor-pointer"
onClick={() => handleDeselectCourse(courseCode)}
>
{courseCode}: {courseName}
Expand Down
4 changes: 2 additions & 2 deletions overload/src/app/components/selectedCourses.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use client';
import { Course } from '../home/page';
import { Course } from '../types';
import SelectedCourse from './selectedCourse';
import Dropdown from './termSelectDropDown';

Expand Down Expand Up @@ -28,7 +28,7 @@ export const SelectedCourses = ({
<div className="flex justify-center pb-8">
<Dropdown handleSelectTerm={handleSelectTerm} />
</div>
<div className="flex flex-col items-center p-8 bg-black ">{courses}</div>
<div className="flex flex-col items-center p-8 bg-black">{courses}</div>
</div>
);
};
Expand Down
Loading