thoughts/controllers/thoughtController.js
controllers/thoughtController.jsRaw
1//File: controllers/tvshows.js
2var mongoose = require('mongoose');
3var thoughtModel = mongoose.model('thoughtModel');
4
5//GET - Return all tvshows in the DB
6exports.findAllThoughts = function(req, res) {
7 thoughtModel.find(function(err, thoughts) {
8 if(err) res.send(500, err.message);
9
10 console.log('GET /thoughts');
11 res.status(200).jsonp(thoughts);
12 });
13};
14
15//GET - Return a TVShow with specified ID
16exports.findById = function(req, res) {
17 thoughtModel.findById(req.params.id, function(err, thought) {
18 if(err) return res.send(500, err.message);
19
20 console.log('GET /thought/' + req.params.id);
21 res.status(200).jsonp(thought);
22 });
23};
24
25//POST - Insert a new TVShow in the DB
26exports.addThought = function(req, res) {
27 console.log('POST new thought, content: ' + req.body.content);
28 console.log(req.body);
29
30 var thought = new thoughtModel({
31 time: req.body.time,
32 content: req.body.content,
33 authorname: req.body.authorname
34 });
35
36 thought.save(function(err, thought) {
37 if(err) return res.send(500, err.message);
38 res.status(200).jsonp(thought);
39 });
40};
41
42//PUT - Update a register already exists
43exports.updateActivity = function(req, res) {
44 ActivityModel.findById(req.params.id, function(err, tvshow) {
45 tvshow.title = req.body.petId;
46 tvshow.year = req.body.year;
47 tvshow.country = req.body.country;
48 tvshow.poster = req.body.poster;
49 tvshow.seasons = req.body.seasons;
50 tvshow.genre = req.body.genre;
51 tvshow.summary = req.body.summary;
52
53 tvshow.save(function(err) {
54 if(err) return res.send(500, err.message);
55 res.status(200).jsonp(tvshow);
56 });
57 });
58};
59
60//DELETE - Delete a TVShow with specified ID
61exports.deleteActivity = function(req, res) {
62 ActivityModel.findById(req.params.id, function(err, activity) {
63 activity.remove(function(err) {
64 if(err) return res.send(500, err.message);
65 res.status(200).jsonp(req.params.id);
66 console.log('DELETE /activities/' + req.params.id);
67 })
68 });
69};