-
Notifications
You must be signed in to change notification settings - Fork 54
David's work on the personal api #24
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
base: master
Are you sure you want to change the base?
Changes from all commits
3f00c09
51db347
342c383
f882896
7fe6d74
19547ee
ca4ff8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| **/node_modules | ||
| **/node_modules |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // // GET /api/albums | ||
| // 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'), | ||
| } | ||
| 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); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| res.json(allMovies); | ||
| // console.log(allMovies); | ||
| }); | ||
| } | ||
|
|
||
| function destroy(req, res) { | ||
| db.Movie.findOneAndRemove({_id: req.params.movieid}, function(err, remainingMovies) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should look at the documentation for |
||
| 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'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
| }; | ||
| 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; |
| 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; |
| 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'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment.
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