From 753b81b7dac6665b5ee744d4c301e08c882b456f Mon Sep 17 00:00:00 2001 From: Iman1121 Date: Fri, 23 Jun 2023 12:17:24 -0400 Subject: [PATCH 1/6] get request by course name made --- backend/controllers/courseController.js | 28 ++++++++++++++++++++++++- backend/routes/courses.js | 11 ++-------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/backend/controllers/courseController.js b/backend/controllers/courseController.js index 602f381..d28d600 100644 --- a/backend/controllers/courseController.js +++ b/backend/controllers/courseController.js @@ -1,3 +1,4 @@ +const { response } = require("express"); const Course = require("../model/courseModel"); const mongoose = require("mongoose"); @@ -18,6 +19,31 @@ const showCourse = async (req, res) => { }); }; + + +//get course by name +const courseByName = async (req, res) => { + const { id } = req.params; + console.log("getting course from ID: ", id); + + const course = await Course.find({faculty: id.substring(0,4), course_code: id.substring(4,8)}).exec() + + + if (!course) { + return res.status(404).json({ error: "No such Course" }); + } + if(course.length === 0){ + return res.status(404).json({ error: "No such Course" }); + } + res.status(200).json({ + course + }); + console.log(course) +}; + + + + //Gets all Courses const indexCourse = async (req, res) => { console.log("Getting all courses") @@ -145,4 +171,4 @@ const updateCourse = async (req,res) => { -module.exports = { showCourse, indexCourse,createCourse,deleteCourse,updateCourse }; +module.exports = { courseByName, showCourse, indexCourse,createCourse,deleteCourse,updateCourse }; diff --git a/backend/routes/courses.js b/backend/routes/courses.js index 782da6f..f73e81a 100644 --- a/backend/routes/courses.js +++ b/backend/routes/courses.js @@ -1,18 +1,11 @@ const express = require("express"); const router = express.Router(); -<<<<<<< HEAD -const { showCourse, indexCourse,createCourse,deleteCourse,updateCourse } = require("../controllers/courseController"); +const { showCourse, indexCourse,createCourse,deleteCourse,updateCourse, courseByName } = require("../controllers/courseController"); //get specified course +router.get("/course/:id", courseByName) router.get("/:id", showCourse); router.get("/", indexCourse); -======= -const { getCourse, getAllCourses,createCourse,deleteCourse,updateCourse } = require("../controllers/courseController"); - -//get specified course -router.get("/:id", getCourse); -router.get("/", getAllCourses); ->>>>>>> 7b546e4fa9a9a392bb17e31823b0d3f9348abbe8 router.post("",createCourse) router.delete("/:id", deleteCourse) router.patch("/:id", updateCourse) From af4ea406cfe2f4f84eb4be7c8bbad1ebdc1ee41f Mon Sep 17 00:00:00 2001 From: Iman1121 Date: Fri, 23 Jun 2023 13:01:36 -0400 Subject: [PATCH 2/6] searchbar can now fetch course and displays it on console --- backend/package.json | 2 +- carleton-pathways/package.json | 3 ++- .../src/components/searchBar/SearchBar.jsx | 22 +++++++++++++++++-- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/backend/package.json b/backend/package.json index 918e832..60813c0 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,4 +1,4 @@ -{ +{"proxy":"http://localhost:4000", "name": "backend", "version": "1.0.0", "description": "", diff --git a/carleton-pathways/package.json b/carleton-pathways/package.json index 893667d..63dcaa9 100644 --- a/carleton-pathways/package.json +++ b/carleton-pathways/package.json @@ -1,4 +1,5 @@ -{ +{ + "proxy":"http://localhost:4000", "name": "carleton-pathways", "version": "0.1.0", "private": true, diff --git a/carleton-pathways/src/components/searchBar/SearchBar.jsx b/carleton-pathways/src/components/searchBar/SearchBar.jsx index 3a58a8b..42e366e 100644 --- a/carleton-pathways/src/components/searchBar/SearchBar.jsx +++ b/carleton-pathways/src/components/searchBar/SearchBar.jsx @@ -1,10 +1,13 @@ -import React, { useRef } from 'react'; +import React, { useEffect, useRef, useState } from 'react'; + export default function SearchBar() { + const [searchQuery, setSearchQuery] = useState(null) + const [courses, setCourses] = useState(null) const searchInput = useRef(null) const handleSearch = () => { - const searchQuery = searchInput.current.value; + setSearchQuery(searchInput.current.value); console.log(searchQuery) } const handleKeyDown = (event) => { @@ -14,6 +17,21 @@ export default function SearchBar() { } }; + useEffect(() =>{ + if(searchQuery === null){ + return; + } + const fetchCourses = async () =>{ + const response = await fetch('/search/course/' + searchQuery) + const json = await response.json() + if(response.ok){ + setCourses(json.courses) + } + console.log(json) + } + fetchCourses() + },[searchQuery]) + return ( <> From 031cf3bb161fc9d4a11ea0e5a6c70a7a5d2c158e Mon Sep 17 00:00:00 2001 From: Iman1121 Date: Fri, 23 Jun 2023 15:40:45 -0400 Subject: [PATCH 3/6] component works --- carleton-pathways/src/components/header/Header.jsx | 4 ++-- .../src/components/searchBar/SearchBar.jsx | 10 ++++++---- .../src/screens/coursePage/CoursePage.jsx | 11 ++++++++--- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/carleton-pathways/src/components/header/Header.jsx b/carleton-pathways/src/components/header/Header.jsx index dbbbce2..382f512 100644 --- a/carleton-pathways/src/components/header/Header.jsx +++ b/carleton-pathways/src/components/header/Header.jsx @@ -1,11 +1,11 @@ import SearchBar from "../searchBar/SearchBar"; import Logo from "../logo/logo"; -export default function Header() { +export default function Header( {handleCoursesChange} ) { return (
- +
); }; \ No newline at end of file diff --git a/carleton-pathways/src/components/searchBar/SearchBar.jsx b/carleton-pathways/src/components/searchBar/SearchBar.jsx index 42e366e..4fdba17 100644 --- a/carleton-pathways/src/components/searchBar/SearchBar.jsx +++ b/carleton-pathways/src/components/searchBar/SearchBar.jsx @@ -1,14 +1,14 @@ import React, { useEffect, useRef, useState } from 'react'; -export default function SearchBar() { +export default function SearchBar({onCoursesChange}) { const [searchQuery, setSearchQuery] = useState(null) - const [courses, setCourses] = useState(null) + const searchInput = useRef(null) const handleSearch = () => { setSearchQuery(searchInput.current.value); - console.log(searchQuery) + } const handleKeyDown = (event) => { if (event.key === 'Enter') { @@ -18,6 +18,8 @@ export default function SearchBar() { }; useEffect(() =>{ + console.log("ran") + console.log(searchQuery) if(searchQuery === null){ return; } @@ -25,7 +27,7 @@ export default function SearchBar() { const response = await fetch('/search/course/' + searchQuery) const json = await response.json() if(response.ok){ - setCourses(json.courses) + onCoursesChange(json.courses) } console.log(json) } diff --git a/carleton-pathways/src/screens/coursePage/CoursePage.jsx b/carleton-pathways/src/screens/coursePage/CoursePage.jsx index 31aac66..3cdf304 100644 --- a/carleton-pathways/src/screens/coursePage/CoursePage.jsx +++ b/carleton-pathways/src/screens/coursePage/CoursePage.jsx @@ -1,9 +1,14 @@ -import React from 'react' -import CourseSchedule from '../../components/courseSchedule/CourseSchedule' +import React, { useState } from 'react';import CourseSchedule from '../../components/courseSchedule/CourseSchedule' import Header from '../../components/header/Header' import CourseHeader from '../../components/courseHeader/CourseHeader' + export default function CoursePage() { + const [courses, setCourses] = useState(null) + + const handleCoursesChange = (newCourses) => { + setCourses(newCourses); + console.log(courses)} const course = { faculty: "COMP", course_code: "1805", @@ -19,7 +24,7 @@ export default function CoursePage() { } return ( <> -
+
From 9a2ea2ed2eaf1555e1d6974df6d1065823021287 Mon Sep 17 00:00:00 2001 From: Iman1121 Date: Sat, 24 Jun 2023 19:49:41 -0400 Subject: [PATCH 4/6] updated code --- .../components/courseHeader/CourseHeader.jsx | 8 ++--- .../CourseScheduleTable.jsx | 28 ++++------------- .../src/screens/coursePage/CoursePage.jsx | 30 ++++++++++++++----- 3 files changed, 32 insertions(+), 34 deletions(-) diff --git a/carleton-pathways/src/components/courseHeader/CourseHeader.jsx b/carleton-pathways/src/components/courseHeader/CourseHeader.jsx index 027ddcd..7f9f26e 100644 --- a/carleton-pathways/src/components/courseHeader/CourseHeader.jsx +++ b/carleton-pathways/src/components/courseHeader/CourseHeader.jsx @@ -5,16 +5,16 @@ export default function CourseHeader(props) {
-
{props.course.faculty} {props.course.course_code}
-
{props.course.title}
+
{props.course[0].faculty} {props.course[0].course_code}
+
{props.course[0].title}
- {props.course.description} + {props.course[0].description}
-
{props.course.prereqs}
+
{props.course[0].prereqs}
); } diff --git a/carleton-pathways/src/components/courseScheduleTable/CourseScheduleTable.jsx b/carleton-pathways/src/components/courseScheduleTable/CourseScheduleTable.jsx index abcd5ed..7905cf1 100644 --- a/carleton-pathways/src/components/courseScheduleTable/CourseScheduleTable.jsx +++ b/carleton-pathways/src/components/courseScheduleTable/CourseScheduleTable.jsx @@ -21,28 +21,12 @@ export default function CourseScheduleRow(props) { - - - - - - - - - - - - - - - - - - - - - - + + + + + + ) diff --git a/carleton-pathways/src/screens/coursePage/CoursePage.jsx b/carleton-pathways/src/screens/coursePage/CoursePage.jsx index 3cdf304..839ca6f 100644 --- a/carleton-pathways/src/screens/coursePage/CoursePage.jsx +++ b/carleton-pathways/src/screens/coursePage/CoursePage.jsx @@ -1,15 +1,29 @@ -import React, { useState } from 'react';import CourseSchedule from '../../components/courseSchedule/CourseSchedule' +import React, { useEffect, useState } from 'react';import CourseSchedule from '../../components/courseSchedule/CourseSchedule' import Header from '../../components/header/Header' import CourseHeader from '../../components/courseHeader/CourseHeader' export default function CoursePage() { - const [courses, setCourses] = useState(null) - + const [courses, setCourses] = useState([{ + faculty: "COMP", + course_code: "1805", + section: "A", + title: "Discrete Structures I", + description: "Introduction to discrete mathematics and discrete structures. Topics include: propositional logic, predicate calculus, set theory, complexity of algorithms, mathematical reasoning and proof techniques, recurrences, induction, finite automata and graph theory. Material is illustrated through examples from computing.", + availability: "OPEN", + time: "11:35 - 12:25", + dates: ["M", "W"], + location: "Nicol Building", + instructor: "Alexa Sharp", + prereqs: "Prereqs: Grade 12 Math: Advanced Functions or Comp 1004 and Comp 1005", + }]) + useEffect(() => { + console.log(courses) + },[courses]) const handleCoursesChange = (newCourses) => { setCourses(newCourses); - console.log(courses)} - const course = { + } + const course = [{ faculty: "COMP", course_code: "1805", section: "A", @@ -21,13 +35,13 @@ export default function CoursePage() { location: "Nicol Building", instructor: "Alexa Sharp", prereqs: "Prereqs: Grade 12 Math: Advanced Functions or Comp 1004 and Comp 1005", - } + }] return ( <>
- +
- +
) From 0696a51eb6fc44323d846a1a9235b9f59296fc29 Mon Sep 17 00:00:00 2001 From: Iman1121 Date: Tue, 27 Jun 2023 09:57:52 -0400 Subject: [PATCH 5/6] search is working need better bot to display everything properly --- .../components/courseHeader/CourseHeader.jsx | 4 +-- .../CourseScheduleTable.jsx | 17 +++++++----- .../src/components/searchBar/SearchBar.jsx | 4 +-- .../src/screens/coursePage/CoursePage.jsx | 26 +++++++++---------- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/carleton-pathways/src/components/courseHeader/CourseHeader.jsx b/carleton-pathways/src/components/courseHeader/CourseHeader.jsx index 7f9f26e..2d22e6e 100644 --- a/carleton-pathways/src/components/courseHeader/CourseHeader.jsx +++ b/carleton-pathways/src/components/courseHeader/CourseHeader.jsx @@ -10,11 +10,11 @@ export default function CourseHeader(props) {
- {props.course[0].description} + {props.course[0].section_information}
-
{props.course[0].prereqs}
+
{props.course[0].prereqs_string}
); } diff --git a/carleton-pathways/src/components/courseScheduleTable/CourseScheduleTable.jsx b/carleton-pathways/src/components/courseScheduleTable/CourseScheduleTable.jsx index 7905cf1..bbef873 100644 --- a/carleton-pathways/src/components/courseScheduleTable/CourseScheduleTable.jsx +++ b/carleton-pathways/src/components/courseScheduleTable/CourseScheduleTable.jsx @@ -8,7 +8,7 @@ import CourseInstructor from '../courseScheduleRowComponents/CourseInstructor' export default function CourseScheduleRow(props) { return ( - + @@ -20,14 +20,17 @@ export default function CourseScheduleRow(props) { + {props.course.map((course)=>( - - - - - - + + + + {course.dates && } + + + + ))}
Instructor
) } diff --git a/carleton-pathways/src/components/searchBar/SearchBar.jsx b/carleton-pathways/src/components/searchBar/SearchBar.jsx index 4fdba17..5529d8f 100644 --- a/carleton-pathways/src/components/searchBar/SearchBar.jsx +++ b/carleton-pathways/src/components/searchBar/SearchBar.jsx @@ -27,9 +27,9 @@ export default function SearchBar({onCoursesChange}) { const response = await fetch('/search/course/' + searchQuery) const json = await response.json() if(response.ok){ - onCoursesChange(json.courses) + onCoursesChange(json) } - console.log(json) + // console.log(json) } fetchCourses() },[searchQuery]) diff --git a/carleton-pathways/src/screens/coursePage/CoursePage.jsx b/carleton-pathways/src/screens/coursePage/CoursePage.jsx index 839ca6f..555ee21 100644 --- a/carleton-pathways/src/screens/coursePage/CoursePage.jsx +++ b/carleton-pathways/src/screens/coursePage/CoursePage.jsx @@ -4,24 +4,24 @@ import CourseHeader from '../../components/courseHeader/CourseHeader' export default function CoursePage() { + const [courses, setCourses] = useState([{ faculty: "COMP", course_code: "1805", section: "A", title: "Discrete Structures I", - description: "Introduction to discrete mathematics and discrete structures. Topics include: propositional logic, predicate calculus, set theory, complexity of algorithms, mathematical reasoning and proof techniques, recurrences, induction, finite automata and graph theory. Material is illustrated through examples from computing.", - availability: "OPEN", + section_information: "Introduction to discrete mathematics and discrete structures. Topics include: propositional logic, predicate calculus, set theory, complexity of algorithms, mathematical reasoning and proof techniques, recurrences, induction, finite automata and graph theory. Material is illustrated through examples from computing.", + status: "OPEN", time: "11:35 - 12:25", - dates: ["M", "W"], - location: "Nicol Building", + dates: ["M", "T"], + building: "Nicol Building", instructor: "Alexa Sharp", - prereqs: "Prereqs: Grade 12 Math: Advanced Functions or Comp 1004 and Comp 1005", + prereqs_string: "Prereqs: Grade 12 Math: Advanced Functions or Comp 1004 and Comp 1005", }]) - useEffect(() => { - console.log(courses) - },[courses]) + useEffect(() => {},[courses]) const handleCoursesChange = (newCourses) => { - setCourses(newCourses); + console.log(newCourses.course) + setCourses(newCourses.course); } const course = [{ faculty: "COMP", @@ -29,19 +29,19 @@ export default function CoursePage() { section: "A", title: "Discrete Structures I", description: "Introduction to discrete mathematics and discrete structures. Topics include: propositional logic, predicate calculus, set theory, complexity of algorithms, mathematical reasoning and proof techniques, recurrences, induction, finite automata and graph theory. Material is illustrated through examples from computing.", - availability: "OPEN", + status: "OPEN", time: "11:35 - 12:25", dates: ["M", "W"], location: "Nicol Building", instructor: "Alexa Sharp", - prereqs: "Prereqs: Grade 12 Math: Advanced Functions or Comp 1004 and Comp 1005", + prereqs_string: "Prereqs: Grade 12 Math: Advanced Functions or Comp 1004 and Comp 1005", }] return ( <>
- + {courses && }
- + {courses && }
) From a049060bc3e580b3d9b00b6923badb818f97f951 Mon Sep 17 00:00:00 2001 From: Iman1121 Date: Tue, 27 Jun 2023 11:37:26 -0400 Subject: [PATCH 6/6] search need to be tested --- .../components/courseHeader/CourseHeader.jsx | 8 +++++-- .../CourseDates.jsx | 22 +++++++++++++++++-- .../CourseTime.jsx | 4 +++- .../CourseScheduleTable.jsx | 4 ++-- .../src/screens/coursePage/CoursePage.jsx | 21 +++++------------- 5 files changed, 36 insertions(+), 23 deletions(-) diff --git a/carleton-pathways/src/components/courseHeader/CourseHeader.jsx b/carleton-pathways/src/components/courseHeader/CourseHeader.jsx index 2d22e6e..6511517 100644 --- a/carleton-pathways/src/components/courseHeader/CourseHeader.jsx +++ b/carleton-pathways/src/components/courseHeader/CourseHeader.jsx @@ -10,11 +10,15 @@ export default function CourseHeader(props) {
- {props.course[0].section_information} + {props.course[0].section_information ? ( +

{props.course[0].section_information}

+ ) : ( +

No description

+ )}
-
{props.course[0].prereqs_string}
+
{props.course[0].prereq_string}
); } diff --git a/carleton-pathways/src/components/courseScheduleRowComponents/CourseDates.jsx b/carleton-pathways/src/components/courseScheduleRowComponents/CourseDates.jsx index a6589ff..f31951b 100644 --- a/carleton-pathways/src/components/courseScheduleRowComponents/CourseDates.jsx +++ b/carleton-pathways/src/components/courseScheduleRowComponents/CourseDates.jsx @@ -2,11 +2,29 @@ import React from 'react' import Dates from './Dates' export default function CourseDates(props) { + const days = props.dates + for(let i =0; i { - ["M ", "T ", "W ", "T ", "F"].map((day) => { - if (props.dates.includes(day.replace(" ",""))){ + ["M ", "T ", "W ", "TH ", "F"].map((day) => { + if (days.includes(day.replace(" ",""))){ return() } else { return() diff --git a/carleton-pathways/src/components/courseScheduleRowComponents/CourseTime.jsx b/carleton-pathways/src/components/courseScheduleRowComponents/CourseTime.jsx index 8053892..c9bae2a 100644 --- a/carleton-pathways/src/components/courseScheduleRowComponents/CourseTime.jsx +++ b/carleton-pathways/src/components/courseScheduleRowComponents/CourseTime.jsx @@ -1,7 +1,9 @@ import React from 'react' export default function CourseTime(props) { + const time = props.course.start_time.slice(0, 5) + " - " + props.course.end_time.slice(0, 5) + return ( - {props.time} + {time} ) } diff --git a/carleton-pathways/src/components/courseScheduleTable/CourseScheduleTable.jsx b/carleton-pathways/src/components/courseScheduleTable/CourseScheduleTable.jsx index bbef873..ed00e99 100644 --- a/carleton-pathways/src/components/courseScheduleTable/CourseScheduleTable.jsx +++ b/carleton-pathways/src/components/courseScheduleTable/CourseScheduleTable.jsx @@ -24,8 +24,8 @@ export default function CourseScheduleRow(props) { - - {course.dates && } + + {course.days && } diff --git a/carleton-pathways/src/screens/coursePage/CoursePage.jsx b/carleton-pathways/src/screens/coursePage/CoursePage.jsx index 555ee21..9282ae4 100644 --- a/carleton-pathways/src/screens/coursePage/CoursePage.jsx +++ b/carleton-pathways/src/screens/coursePage/CoursePage.jsx @@ -12,30 +12,19 @@ export default function CoursePage() { title: "Discrete Structures I", section_information: "Introduction to discrete mathematics and discrete structures. Topics include: propositional logic, predicate calculus, set theory, complexity of algorithms, mathematical reasoning and proof techniques, recurrences, induction, finite automata and graph theory. Material is illustrated through examples from computing.", status: "OPEN", - time: "11:35 - 12:25", - dates: ["M", "T"], + start_time: "11:35", + end_time: "12:25", + days:["Monday", "Tuesday"], building: "Nicol Building", instructor: "Alexa Sharp", - prereqs_string: "Prereqs: Grade 12 Math: Advanced Functions or Comp 1004 and Comp 1005", + prereq_string: "Prereqs: Grade 12 Math: Advanced Functions or Comp 1004 and Comp 1005", }]) useEffect(() => {},[courses]) const handleCoursesChange = (newCourses) => { console.log(newCourses.course) setCourses(newCourses.course); } - const course = [{ - faculty: "COMP", - course_code: "1805", - section: "A", - title: "Discrete Structures I", - description: "Introduction to discrete mathematics and discrete structures. Topics include: propositional logic, predicate calculus, set theory, complexity of algorithms, mathematical reasoning and proof techniques, recurrences, induction, finite automata and graph theory. Material is illustrated through examples from computing.", - status: "OPEN", - time: "11:35 - 12:25", - dates: ["M", "W"], - location: "Nicol Building", - instructor: "Alexa Sharp", - prereqs_string: "Prereqs: Grade 12 Math: Advanced Functions or Comp 1004 and Comp 1005", - }] + return ( <>