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
7 changes: 1 addition & 6 deletions backend/controllers/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,8 @@ const registerStudent = async (req, res) => {
if (!group) {
return res.status(404).send(`Group not found with the code : ${classCode}`)
}

if(!student.groups.includes(group._id)) {
student.groups.push(group._id)
await student.save()
}

if (!group.students.includes(student._id)) {
if (group.students.length === 0 || !group.students.includes(student._id)) {
group.students.push(student._id)
await group.save()
}
Expand Down
30 changes: 13 additions & 17 deletions backend/controllers/groupController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ const Quest = require("../models/QuestModel");
const Task = require("../models/TaskModel")
const Hint = require('../models/HintModel');
const Student = require("../models/StudentModel");

const Professor = require('../models/ProfessorModel')
const Group = require('../models/GroupModel')

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -19,10 +20,12 @@ const getProfessor = async(req, res) => {
}

return res.status(200).json({
_id: professor._id,
profName: professor.name,
email: professor.email,
groups: professor.ownedGroups,
quests: professor.quests
quests: professor.quests,
verified: professor.verified
});
} catch(error) {
console.debug(`Error in getProfessor function: ${error}`)
Expand Down Expand Up @@ -77,7 +80,8 @@ const createGroup = async (req, res) => {
res.status(201).json({
professorID: newGroup.professor,
groupName: newGroup.groupName,
classCode: newGroup.classCode
classCode: newGroup.classCode,
active: true
})
} else {
return res.status(400).json({error: `Error creating new group for professor with id ${professorID}`})
Expand All @@ -95,7 +99,7 @@ const getGroups = async (req, res) => {
const { professorID } = req.params;

try{
const prof = await Professor.findById(professorID)
const prof = await Professor.findById(professorID).populate('ownedGroups');
if (!prof) {
return res.status(400).json({error: "No professor provided"})
}
Expand All @@ -113,19 +117,9 @@ const getGroups = async (req, res) => {
// given professorID and groupID
//return info for one of professor's groups
const getGroup = async (req, res ) => {
const { professorID, groupID } = req.params;

const { groupID } = req.params;
try{
const professorExists = await Professor.findById(professorID)
if (!professorExists) {
return res.status(400).json({error: "No professor provided"})
}

if (!professorExists.ownedGroups.includes(groupID)) {
return res.status(403).json({ error: `Group with ID ${groupID} is not owned by professor ${professorID}` });
}

const group = await Group.findById(groupID);
const group = await Group.findById(groupID).populate('students');
if (!group) {
return res.status(404).json({ error: `Group with ID ${groupID} not found` });
}
Expand All @@ -134,9 +128,10 @@ const getGroup = async (req, res ) => {
groupID: group._id,
groupName: group.groupName,
professorID: group.professor,
members: group.members,
students: group.students,
admin: group.admin,
quests: group.quests,
classCode: group.classCode
});

} catch(error) {
Expand All @@ -149,6 +144,7 @@ const getGroup = async (req, res ) => {
const deleteGroup = async(req, res) => {
const { professorID, groupID } = req.params;

//! change this to disable group
try {
const professor = await Professor.findById(professorID)
if (!professor) {
Expand Down
5 changes: 3 additions & 2 deletions backend/controllers/studentController.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const getStudents = async(req, res) => {
if (!group) {
return res.status(400).json({error: `Group with ID ${groupID} not found`})
}

const students = group.students

return res.status(200).json({students})
} catch(error) {
console.debug(`Error in addStudentToGroup function: ${error}`)
Expand All @@ -20,4 +20,5 @@ const getStudents = async(req, res) => {

module.exports = {
getStudents
}
}

7 changes: 5 additions & 2 deletions backend/models/GroupModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const GroupSchema = mongoose.Schema({
ref: "Student"
}],
professor:{
//describes teacher/professor/organization/etc...
type: mongoose.Schema.Types.ObjectId,
ref: "GroupOrganizer"
},
Expand All @@ -28,7 +27,11 @@ const GroupSchema = mongoose.Schema({
students: [{
type: mongoose.Schema.Types.ObjectId,
ref: "Student"
}]
}],
active: {
type: Boolean,
default: true
}
})

module.exports = mongoose.model("Group", GroupSchema)
19 changes: 19 additions & 0 deletions backend/models/QuestCompletionModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import mongoose from "mongoose";

const QuestCompletionSchema = mongoose.Schema({
quest: {
type: mongoose.Schema.Types.ObjectId,
ref:"Quest",
required: [true, "Please add quest to questCompletion"]
},
completed: {
type: Boolean,
required: [true, "Please provide completion status for quest"]
},
tasks: {
type: mongoose.Schema.Types.ObjectId,
ref: "Task"
}
})

export default mongoose.model("QuestCompletion", QuestCompletionSchema)
4 changes: 2 additions & 2 deletions backend/models/StudentModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ const StudentSchema = mongoose.Schema({
type: String,
required: [true, "Please enter your student email"]
},
groups: [{
progress: [{
type: mongoose.Schema.Types.ObjectId,
ref: "Group"
ref: "StudentProgress"
}]
})

Expand Down
46 changes: 46 additions & 0 deletions backend/models/StudentProgressModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const mongoose = require("mongoose");

const StudentProgressSchema = mongoose.Schema({
group: {
type: mongoose.Schema.Types.ObjectId,
ref: "Group",
required: true
},
xp: {
type: Number,
default: 0
},
points: {
type: Number,
default: 0
},
completion: {
type: Number, // Percentage (0-100) of completion
default: 0
},
streakCount: {
type: Number,
default: 0
},
currentStreak: {
type: Number,
default: 0
},
completed:[{
type: mongoose.Schema.Types.ObjectId,
ref: "QuestCompletion"
}],
accepted: QuestCompletionSchema,
current: {
quest: {
type: mongoose.Schema.Types.ObjectId,
ref: "Quest"
},
task:{
type: mongoose.Schema.Types.ObjectId,
ref: "Task"
}
}
});

export default mongoose.model("StudentProgress", StudentProgressSchema)
31 changes: 31 additions & 0 deletions backend/models/TaskCompletionModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import mongoose from "mongoose";

const TaskCompletionSchema = mongoose.Schema({
task:{
type: mongoose.Schema.Types.ObjectId,
ref:"Task",
required: [true, "Please add task to taskCompletion"]
},
completed: {
type: Boolean,
required: [true, "Please provide completion status for task"]
},
attemps: {
type: Number
},
timeStart: {
type: Date
},
timeEnd: {
type: Date
},
hintsUsed: {
type: Number,
default: 0
},
issueNum: {
type: Number
}
})

export default mongoose.model("TaskCompletion", TaskCompletionSchema)
1 change: 1 addition & 0 deletions backend/routes/authRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require("express");
const router = express.Router();
const { signup, login, registerStudent, verifyEmail } = require("../controllers/authController");

// api/auth
router.route("/").post(signup);
router.route("/verify").put(verifyEmail);
router.route("/login").post(login)
Expand Down
5 changes: 4 additions & 1 deletion backend/routes/groupRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ const router = express.Router();
const { getProfessor, createGroup, getGroup, getGroups, deleteGroup, createQuest, addQuestToGroup, removeQuestFromGroup, getQuests, getQuestsInGroup, updateQuest, deleteQuest, getQuest, addTask,
getTasks, updateTask, deleteTask, getTask, addHint, getHints, updateHint, deleteHint, getHint } = require("../controllers/groupController")


//api/group

router.route('/:professorID').get(getProfessor)

router.route("/:professorID/groups").post(createGroup).get(getGroups)
router.route("/:professorID/group/:groupID").get(getGroup).delete(deleteGroup)
router.route("/class/:groupID").get(getGroup).delete(deleteGroup)

router.route("/:professorID/quests").get(getQuests).post(createQuest)
router.route("/:professorID/quest/:questID").get(getQuest).put(updateQuest).delete(deleteQuest)
Expand Down
2 changes: 2 additions & 0 deletions backend/routes/studentRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const express = require("express");
const router = express.Router();
const {getStudents} = require('../controllers/studentController')


//api/student/${groupID}
router.route('/:groupID').get(getStudents)

module.exports = router;
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"react": "^18.3.1",
"react-bootstrap": "^2.10.7",
"react-dom": "^18.3.1",
"react-scripts": "5.0.1",
"react-router-dom": "^6.0.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
},
"scripts": {
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/App.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.App {
text-align: center;
height: 100vh;
}

.App-logo {
Expand Down Expand Up @@ -36,3 +37,7 @@
transform: rotate(360deg);
}
}

div {
background: #c9d6ff
}
10 changes: 6 additions & 4 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import './App.css';
import LoginSignup from './pages/login-signup/LoginSignup';
import EmailVerification from './pages/login-signup/EmailVerification'
import StudentRegister from './pages/studentSignup/StudentRegister';
import ClassView from './pages/class-view/ClassView'
import Home from './pages/home/Home'
import { Navigate, Route, Routes } from "react-router-dom";
import { useEffect } from 'react';
Expand All @@ -22,10 +23,11 @@ const App = () => {
return (
<div className="App">
<Routes>
<Route path='/login' element={authUser ? <Home /> : <LoginSignup />} />
<Route path='/' element={authUser ? (authUser.verified ? <Home /> : <EmailVerification />) : <LoginSignup /> } />
<Route path='/verify' element={authUser && !authUser.verified ? <EmailVerification /> : <Home/>} />
<Route path='/studentRegister' element={< StudentRegister />} />
<Route exact path='/login' element={authUser ? <Home /> : <LoginSignup />} />
<Route exact path='/' element={authUser ? (authUser.verified ? <Home /> : <EmailVerification />) : <LoginSignup /> } />
<Route exact path='/verify' element={authUser && !authUser.verified ? <EmailVerification /> : <Home/>} />
<Route exact path='/studentRegister' element={< StudentRegister />} />
<Route path="/class/:classId" element={<ClassView />} />
</Routes>
</div>
);
Expand Down
Binary file added frontend/src/images/reshape.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading