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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1 @@
**/node_modules
**/node_modules
11 changes: 11 additions & 0 deletions .idea/express-personal-api.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

582 changes: 582 additions & 0 deletions .idea/workspace.xml

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// // GET /api/albums
Copy link

Choose a reason for hiding this comment

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

This commented out code doesn't need to be here

// function index(req, res) {
// // send back all albums as JSON
// db.Album.find({}, function(err, allAlbums) {
// res.json(allAlbums);
// });
// }


//need to connect index function to display data from seed, start with ajax in app.js

module.exports = {
movies: require('./moviesController'),
}
58 changes: 58 additions & 0 deletions controllers/moviesController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/************
* DATABASE *
************/
//change everything here into movies
var db = require('../models');

// GET /api/albums
function index(req, res) {
// send back all albums as JSON
db.Movie.find({}, function(err, allMovies) {
res.json(allMovies);
// console.log(allMovies);
});
}

// POST /api/albums
function create(req, res) {
// create an album based on request body and send it back as JSON
console.log('body', req.body);
db.Movie.create(req.body)
// if (err) { console.log('error', err); }
console.log("hello");
res.json(req.body);
Copy link

Choose a reason for hiding this comment

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

Here, you should use a callback, and actually send the saved movie, rather than sending back whatever was sent by the client.

db.Movie.create(req.body, function(err, savedMovie) {
  res.json(savedMovie);
})

}

function show(req, res) {
// send back all albums as JSON
db.Movie.findById({_id: req.params.movieid}, function(err, allMovies) {
Copy link

Choose a reason for hiding this comment

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

findById just takes in the ID as the first argument, not an object.

res.json(allMovies);
// console.log(allMovies);
});
}

function destroy(req, res) {
db.Movie.findOneAndRemove({_id: req.params.movieid}, function(err, remainingMovies) {
Copy link

Choose a reason for hiding this comment

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

please send a response after the movie has been removed!

})
}

function update(req, res) {
console.log(req.body);
db.Movie.findByIdAndUpdate(req.params.movieid, {new: true}, (err, movie) => {
Copy link

Choose a reason for hiding this comment

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

You should look at the documentation for findByIdAndUpdate; it takes in one more argument than that, with the data that you want to use to update the movie. What you're doing now might work, but it's weird.

movie.title = req.body.title;
movie.director= req.body.director;
movie.year= req.body.year;
movie.image = req.body.image
movie.save();
})
console.log('testing');
Copy link

Choose a reason for hiding this comment

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

You need to send back a response once the movie has been saved.

}

// export public methods here
module.exports = {
index: index,
create: create,
show: show,
destroy: destroy,
update: update
};
11 changes: 11 additions & 0 deletions models/hobbies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
var mongoose = require("mongoose");
var Schema = mongoose.Schema;

var HobbySchema = new Schema({
name: String,
yearsPlaying: Number
});

var Hobby = mongoose.model('Hobby', HobbySchema);

module.exports = Hobby;
4 changes: 3 additions & 1 deletion models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ var mongoose = require("mongoose");
mongoose.connect( process.env.MONGODB_URI || "mongodb://localhost/personal-api", {useMongoClient: true});
mongoose.Promise = global.Promise; // use native Promise

// module.exports.Campsite = require("./campsite.js.example");
module.exports.Personal = require("./personal_data");
module.exports.Hobby = require("./hobbies");
module.exports.Movie = require("./movies");
12 changes: 12 additions & 0 deletions models/movies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var mongoose = require("mongoose");
var Schema = mongoose.Schema;

var MovieSchema = new Schema({
title: String,
year: Number,
director: String,
image: String,
});

var Movie = mongoose.model('Movie', MovieSchema);
module.exports = Movie;
19 changes: 19 additions & 0 deletions models/personal_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var mongoose = require("mongoose");
var Schema = mongoose.Schema;

var Hobby = require('./hobbies');
Copy link

Choose a reason for hiding this comment

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

we said it would be serious overkill to keep this data in your database! and that you should just send back a hardcoded bunch of data!



var PersonalSchema = new Schema({
name: String,
githubUsername: String,
githubLink: String,
githubProfileImage: String,
personalSiteLink: String,
currentCity: String,
hobbies: [Hobby.schema]
});

var Personal = mongoose.model('Personal', PersonalSchema);

module.exports = Personal;
Loading