You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.9 KiB

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