forked from sf-wdi-25/express_self_api
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathmoviesController.js
More file actions
58 lines (52 loc) · 1.42 KB
/
moviesController.js
File metadata and controls
58 lines (52 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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);
}
function show(req, res) {
// send back all albums as JSON
db.Movie.findById({_id: req.params.movieid}, function(err, allMovies) {
res.json(allMovies);
// console.log(allMovies);
});
}
function destroy(req, res) {
db.Movie.findOneAndRemove({_id: req.params.movieid}, function(err, remainingMovies) {
})
}
function update(req, res) {
console.log(req.body);
db.Movie.findByIdAndUpdate(req.params.movieid, {new: true}, (err, movie) => {
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');
}
// export public methods here
module.exports = {
index: index,
create: create,
show: show,
destroy: destroy,
update: update
};