Skip to content
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

Feature/us23 adding resources #178

Merged
merged 29 commits into from
Feb 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cceef87
#165 added backend controller and routes for getting and adding resou…
cynthiac3 Feb 1, 2020
b65d8bf
#165 added education level to resource model
cynthiac3 Feb 1, 2020
83ec7b7
#165 added resources to tutor side bar
jaslatendresse Feb 1, 2020
4044f6a
Merge branch 'feature/us23-adding-resources' of https://github.com/co…
jaslatendresse Feb 1, 2020
84e154f
#165 added add resource component with conditional rendering
jaslatendresse Feb 1, 2020
ecca0a7
#165 moved all the resources to the database and fetched them, remove…
cynthiac3 Feb 1, 2020
3a65402
Merge branch 'feature/us23-adding-resources' of https://github.com/co…
cynthiac3 Feb 1, 2020
1ac695f
#165 added component AddResource as a modal window
jaslatendresse Feb 1, 2020
cc7395c
#165 added functional close button for modal window
jaslatendresse Feb 1, 2020
bef799b
#165 added function in frontend to save the new resource to the db
cynthiac3 Feb 1, 2020
b936dbb
#165 added options for user input to add a resource
jaslatendresse Feb 1, 2020
b24cca8
#165 merge conflict fix
jaslatendresse Feb 1, 2020
dd4191a
#165 missing import
jaslatendresse Feb 1, 2020
f5991f0
#165 added drop down components for education level and category
jaslatendresse Feb 1, 2020
7b3d2f2
#165 added function to add button in dialog box
cynthiac3 Feb 2, 2020
b2461a4
Merge branch 'feature/us23-adding-resources' of https://github.com/co…
cynthiac3 Feb 2, 2020
b03e671
#165 added current value to dropdown menu, state is updated when valu…
cynthiac3 Feb 2, 2020
0754a4b
#165 Removed unused code and fixed the frontend for the add resource …
jaslatendresse Feb 3, 2020
485f7b7
#165 added input validation to the add resource component
jaslatendresse Feb 3, 2020
0fa494e
#165 added default image if provided url is not reachable
jaslatendresse Feb 3, 2020
95ab496
#165 added descriptive comments for the functions
jaslatendresse Feb 3, 2020
f9bdb8e
Merge branch 'master' into feature/us23-adding-resources
cynthiac3 Feb 6, 2020
0c4c0fe
#165 reset fields to default value after closing dialog window
jaslatendresse Feb 7, 2020
b6e3c9a
#165 trying to close modal window upon adding resource
jaslatendresse Feb 7, 2020
04f1f6e
#165 fixed handleClose for modal window
cynthiac3 Feb 7, 2020
45c2757
#165 made fields required and provided feedback to user regarding ima…
jaslatendresse Feb 7, 2020
48e1e92
#165 check if the link is valid or not and prepend http if missing
cynthiac3 Feb 8, 2020
70b9a91
#165 adjusted grid spacing in the resource levels page
jaslatendresse Feb 8, 2020
a184d69
fix
jaslatendresse Feb 8, 2020
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
36 changes: 36 additions & 0 deletions tutify/backend/controllers/resource.controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const Resource = require('../models/models').Resource;

// this method fetches all available resources in our database
exports.getResources = async function (req, res) {
Resource.find((err, data) => {
if (err) {
console.error("The resources were not found");
return res.json({ success: false, error: err });
}
console.info("The resources were found");
return res.json({ success: true, data: data });
});
};

// this method adds a new resource to the db
exports.addResource = async function (req, res) {
const { title, description, image, link, category, educationLevel } = req.body;

// new resource to add
let resource = new Resource();
resource.title = title;
resource.description = description;
resource.image = image;
resource.link = link;
resource.category = category;
resource.educationLevel = educationLevel;

resource.save(function (err, resource) {
if (err) {
console.error("The resource couldn't get added to the database (API request failed)");
return res.json({ success: false, error: err });
}
console.info("The resource was successfully added to the database");
return res.json({ success: true, course: resource });
});
};
47 changes: 38 additions & 9 deletions tutify/backend/models/models.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// /backend/data.js
const mongoose = require("mongoose");
const Schema = mongoose.Schema;

// -------- ACCOUNT --------- //
// -------- Account --------- //

const Account = mongoose.model('Account', new mongoose.Schema({
email: {
Expand All @@ -18,7 +17,7 @@ const Account = mongoose.model('Account', new mongoose.Schema({
}), 'accounts'
);

// -------- PROFILE --------- //
// -------- Profile --------- //

// these properties are shared with our schemas Tutor and User
const Profile = mongoose.model('Profile', new mongoose.Schema({
Expand Down Expand Up @@ -73,7 +72,7 @@ const Profile = mongoose.model('Profile', new mongoose.Schema({
);


// -------- TUTOR --------- //
// -------- Tutor --------- //

const TutorSchema = mongoose.Schema({
subjects: [String],
Expand Down Expand Up @@ -101,7 +100,7 @@ const TutorSchema = mongoose.Schema({

var Tutor = Profile.discriminator('Tutor', TutorSchema, "tutor");

// -------- STUDENT --------- //
// -------- Student --------- //

const StudentSchema = mongoose.Schema({
education_level: {
Expand All @@ -127,7 +126,7 @@ const StudentSchema = mongoose.Schema({

var Student = Profile.discriminator('Student', StudentSchema, "student");

// -------- APPOINTMENT --------- //
// -------- Appointment --------- //

var Appointment = mongoose.model('Appointment', new Schema({
id: {
Expand All @@ -154,7 +153,7 @@ var Appointment = mongoose.model('Appointment', new Schema({
}), "appointments");


// -------- COURSE --------- //
// -------- Course --------- //

var Course = mongoose.model('Course', new Schema({
name: {
Expand All @@ -177,7 +176,7 @@ var Course = mongoose.model('Course', new Schema({
}), "courses");


// -------- FILES --------- //
// -------- Files --------- //

var Files = mongoose.model('uploaded_files', new Schema({
name: {
Expand Down Expand Up @@ -275,6 +274,35 @@ var Mchunks = mongoose.model('Mchunks', new Schema({
data: Schema.Types.Buffer
}), "uploads.chunks");

// -------- Resource --------- //

var Resource = mongoose.model('Resource', new Schema({
title: {
type: String,
required: true
},
description: {
type: String,
required: true
},
image: {
type: String,
required: true
},
link: {
type: String,
required: true
},
category: {
type: String,
required: true
},
educationLevel: {
type: String,
required: true
}
}), "resources");


// export the Schemas
module.exports = {
Expand All @@ -288,7 +316,8 @@ module.exports = {
Files: Files,
Event: Event,
Mfiles: Mfiles,
Mchunks: Mchunks
Mchunks: Mchunks,
Resource: Resource
}


9 changes: 8 additions & 1 deletion tutify/backend/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var userController = require('./controllers/user.controller')
var courseController = require('./controllers/course.controller')
var filesController = require('./controllers/files.controller')
var uploadedFilesController = require('./controllers/uploaded_files.controller')
var resourceController = require('./controllers/resource.controller')

// -------- TUTOR ROUTES --------- //

Expand Down Expand Up @@ -108,12 +109,18 @@ router.get('/viewCourse/:coursename', uploadedFilesController.viewCourseDocs);

router.get('/doc/:studentid',uploadedFilesController.viewSpecificStudentFiles);

// -------- DELETE ROUTES --------- //
// -------- DELETE FILES ROUTES --------- //

router.post('/getFileToDelete', uploadedFilesController.deleteFiles);

router.post('/getSpecificStudentsFilestoDelete', uploadedFilesController.deleteSpecificStudentsFiles);

router.post('/getSpecificCourseFilestoDelete', uploadedFilesController.deleteSpecificCourseFiles);

// -------- RESOURCES --------- //

router.get('/getResources', resourceController.getResources);

router.post('/addResource', resourceController.addResource);

module.exports = router;
6 changes: 6 additions & 0 deletions tutify/src/components/ProfilePage/Tutor/TutorSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ export class TutorSidebar extends Component {
</ListItemIcon>
<ListItemText primary="Announcements" />
</ListItem>
<ListItem button component="a" href="/resources">
<ListItemIcon>
<MenuBookIcon />
</ListItemIcon>
<ListItemText primary="Useful Resources" />
</ListItem>
<ListItem button component="a" href="/students">
<ListItemIcon>
<SchoolIcon />
Expand Down
Loading