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
3 changes: 3 additions & 0 deletions controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
projects: require('./projectsController')
}
47 changes: 47 additions & 0 deletions controllers/projectsController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var db = require('../models');


function index(req, res){
db.Project.find({}, function(err, allProjects) {
if (err)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need these guys {} for the if statement?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed, but certainly encouraged (and required by pretty much every styleguide) to avoid the goto fail.

console.log(err);
res.json(allProjects);
});
}

function create(req, res){
db.Project.create(req.body, function(err, project) {
if (err) { console.log('error', err); }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation 😭

res.json(project);
});
}

function show(req, res){
db.Project.findById(req.params.id, function(err, project){
res.json(project);
});
}

function destroy(req, res){
db.Project.findByIdAndRemove(req.params.id, function(err, project){
res.json(project);
});
}

function update(req, res){
db.Project.findByIdAndUpdate(req.params.id, req.body, {new: true}, function (err, project){
res.json(project);
});
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

short and sweet controllers are awesome.






module.exports = {
index: index,
create: create,
show: show,
destroy: destroy,
update: update
};
1 change: 1 addition & 0 deletions models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ mongoose.connect( process.env.MONGODB_URI || "mongodb://localhost/personal-api",
mongoose.Promise = global.Promise; // use native Promise

// module.exports.Campsite = require("./campsite.js.example");
module.exports.Project = require("./project.js");
13 changes: 13 additions & 0 deletions models/project.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var mongoose = require("mongoose");
var Schema = mongoose.Schema;

var ProjectSchema = new Schema({
name: String,
description: String,
githubRepoUrl: String,
deployedUrl: String,
screenshot: String
});

var Project = mongoose.model('Project', ProjectSchema);
module.exports = Project;
Loading