Skip to content
Open
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
28 changes: 27 additions & 1 deletion backend/controllers/courseController.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
const { response } = require("express");
const Course = require("../model/courseModel");
const mongoose = require("mongoose");

Expand All @@ -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")
Expand Down Expand Up @@ -145,4 +171,4 @@ const updateCourse = async (req,res) => {



module.exports = { showCourse, indexCourse,createCourse,deleteCourse,updateCourse };
module.exports = { courseByName, showCourse, indexCourse,createCourse,deleteCourse,updateCourse };
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{"proxy":"http://localhost:4000",
"name": "backend",
"version": "1.0.0",
"description": "",
Expand Down
11 changes: 2 additions & 9 deletions backend/routes/courses.js
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 2 additions & 1 deletion carleton-pathways/package.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
{
"proxy":"http://localhost:4000",
"name": "carleton-pathways",
"version": "0.1.0",
"private": true,
Expand Down
12 changes: 8 additions & 4 deletions carleton-pathways/src/components/courseHeader/CourseHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ export default function CourseHeader(props) {
<div className="bg-[#BA3C40] m-6 rounded-3xl">
<div className="flex bg-[#D76767] rounded-3xl items-center pt-14 justify-center mb-2">
<div className="flex-item m-4 font-header">
<div className="text-[36px] text-white">{props.course.faculty} {props.course.course_code}</div>
<div className="text-[20px] text-white ">{props.course.title}</div>
<div className="text-[36px] text-white">{props.course[0].faculty} {props.course[0].course_code}</div>
<div className="text-[20px] text-white ">{props.course[0].title}</div>
</div>
<div className="flex-item bg-[#CA464A] w-[66%] rounded-3xl text-center p-2 text-white sm:m-4">
<div className="container text-white">
{props.course.description}
{props.course[0].section_information ? (
<p>{props.course[0].section_information}</p>
) : (
<p>No description</p>
)}
</div>
</div>
</div>
<div className="text-[16px] text-white text-center p-1">{props.course.prereqs}</div>
<div className="text-[16px] text-white text-center p-1">{props.course[0].prereq_string}</div>
</div>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<days.length; i++){
if (days[i] === "Monday"){
days[i] = "M"
}
if (days[i] === "Tuesday"){
days[i] = "T"
}
if (days[i] === "Wednesday"){
days[i] = "W"
}
if (days[i] === "Thursday"){
days[i] = "TH"
}
if (days[i] === "Friday"){
days[i] = "F"
}
}
return (
<>
{
["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(<Dates date={day} highlighted={true}/>)
} else {
return(<Dates date={day} highlighted={false}/>)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 (
<span>{props.time}</span>
<span>{time}</span>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import CourseInstructor from '../courseScheduleRowComponents/CourseInstructor'

export default function CourseScheduleRow(props) {
return (

<table class = "font-table text-sm table-auto w-[85%] m-3">
<thead class = "font-semibold">
<tr>
Expand All @@ -20,30 +20,17 @@ export default function CourseScheduleRow(props) {
<th>Instructor</th>
</tr>
</thead>
{props.course.map((course)=>(
<tr>
<th class = "font-normal"><CourseSection section={props.course.section}/></th>
<th class = "font-normal"><CourseAvailability availability={props.course.availability}/></th>
<th class = "font-normal"><CourseTime time={props.course.time}/></th>
<th class = "font-normal"><CourseDates dates = {props.course.dates}/></th>
<th class = "font-normal"><CourseLocation location={props.course.location}/></th>
<th class = "font-normal"><CourseInstructor instructor={props.course.instructor}/></th>
</tr>
<tr>
<th class = "font-normal"><CourseSection section={props.course.section}/></th>
<th class = "font-normal"><CourseAvailability availability={props.course.availability}/></th>
<th class = "font-normal"><CourseTime time={props.course.time}/></th>
<th class = "font-normal"><CourseDates dates = {props.course.dates}/></th>
<th class = "font-normal"><CourseLocation location={props.course.location}/></th>
<th class = "font-normal"><CourseInstructor instructor={props.course.instructor}/></th>
</tr>
<tr>
<th class = "font-normal"><CourseSection section={props.course.section}/></th>
<th class = "font-normal"><CourseAvailability availability={props.course.availability}/></th>
<th class = "font-normal"><CourseTime time={props.course.time}/></th>
<th class = "font-normal"><CourseDates dates = {props.course.dates}/></th>
<th class = "font-normal"><CourseLocation location={props.course.location}/></th>
<th class = "font-normal"><CourseInstructor instructor={props.course.instructor}/></th>
<th class = "font-normal"><CourseSection section={course.section}/></th>
<th class = "font-normal"><CourseAvailability availability={course.status}/></th>
<th class = "font-normal"><CourseTime course={course}/></th>
{course.days && <th class = "font-normal"><CourseDates dates = {course.days} /></th>}
<th class = "font-normal"><CourseLocation location={course.building}/></th>
<th class = "font-normal"><CourseInstructor instructor={course.instructor}/></th>
</tr>

))}
</table>
)
}
4 changes: 2 additions & 2 deletions carleton-pathways/src/components/header/Header.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import SearchBar from "../searchBar/SearchBar";
import Logo from "../logo/logo";

export default function Header() {
export default function Header( {handleCoursesChange} ) {
return (
<div class="flex m-4">
<Logo/>
<SearchBar/>
<SearchBar onCoursesChange = {handleCoursesChange}/>
</div>
);
};
28 changes: 24 additions & 4 deletions carleton-pathways/src/components/searchBar/SearchBar.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import React, { useRef } from 'react';
import React, { useEffect, useRef, useState } from 'react';

export default function SearchBar() {

export default function SearchBar({onCoursesChange}) {
const [searchQuery, setSearchQuery] = useState(null)

const searchInput = useRef(null)

const handleSearch = () => {
const searchQuery = searchInput.current.value;
console.log(searchQuery)
setSearchQuery(searchInput.current.value);

}
const handleKeyDown = (event) => {
if (event.key === 'Enter') {
Expand All @@ -14,6 +17,23 @@ export default function SearchBar() {
}
};

useEffect(() =>{
console.log("ran")
console.log(searchQuery)
if(searchQuery === null){
return;
}
const fetchCourses = async () =>{
const response = await fetch('/search/course/' + searchQuery)
const json = await response.json()
if(response.ok){
onCoursesChange(json)
}
// console.log(json)
}
fetchCourses()
},[searchQuery])


return (
<>
Expand Down
34 changes: 21 additions & 13 deletions carleton-pathways/src/screens/coursePage/CoursePage.jsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
import React 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 course = {

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",
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",
start_time: "11:35",
end_time: "12:25",
days:["Monday", "Tuesday"],
building: "Nicol Building",
instructor: "Alexa Sharp",
prereqs: "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);
}

return (
<>
<Header/>
<CourseHeader course={course}/>
<Header handleCoursesChange = {handleCoursesChange}/>
{courses && <CourseHeader course={courses}/>}
<div class = "mx-1">
<CourseSchedule course = {course}/>
{courses && <CourseSchedule course = {courses}/>}
</div>
</>
)
Expand Down