|
| 1 | +/** |
| 2 | + * VideoController |
| 3 | + * |
| 4 | + * @description :: Server-side logic for managing videos |
| 5 | + * @help :: See http://links.sailsjs.org/docs/controllers |
| 6 | + */ |
| 7 | + |
| 8 | +module.exports = { |
| 9 | + |
| 10 | + /** |
| 11 | + * `VideoController.create()` |
| 12 | + * Usage: POST /api/video |
| 13 | + */ |
| 14 | + create: function (req, res) { |
| 15 | + Video.create(req.body).exec(function (err, video) { |
| 16 | + if (err) throw err; |
| 17 | + res.json(video); |
| 18 | + }); |
| 19 | + }, |
| 20 | + |
| 21 | + /** |
| 22 | + * `VideoController.read()` |
| 23 | + * Usage: GET /api/video/:id |
| 24 | + */ |
| 25 | + read: function (req, res) { |
| 26 | + Video.findOne({ |
| 27 | + id: req.param('id') |
| 28 | + }).exec(function (err, video) { |
| 29 | + if (err) throw err; |
| 30 | + res.json(video); |
| 31 | + }); |
| 32 | + }, |
| 33 | + |
| 34 | + /** |
| 35 | + * `VideoController.readAll()` |
| 36 | + * Usage: GET /api/video |
| 37 | + */ |
| 38 | + readAll: function (req, res) { |
| 39 | + Video.find().exec(function (err, videos) { |
| 40 | + if (err) throw err; |
| 41 | + res.json(videos); |
| 42 | + }); |
| 43 | + }, |
| 44 | + |
| 45 | + /** |
| 46 | + * `VideoController.destroy()` |
| 47 | + * Usage: DELETE /api/video/:id |
| 48 | + */ |
| 49 | + destroy: function (req, res) { |
| 50 | + Video.destroy({ |
| 51 | + id: req.param('id') |
| 52 | + }).exec(function (err, video) { |
| 53 | + console.log(req.body.videoId); |
| 54 | + if (err) throw err; |
| 55 | + res.json(video); |
| 56 | + }); |
| 57 | + }, |
| 58 | + |
| 59 | + |
| 60 | + /** |
| 61 | + * `VideoController.update()` |
| 62 | + * Usage: PUT /api/video/:id |
| 63 | + */ |
| 64 | + update: function (req, res) { |
| 65 | + Video.update({ |
| 66 | + id: req.param('id') |
| 67 | + }, req.body).exec(function (err, updated) { |
| 68 | + if (err) throw err; |
| 69 | + res.json(updated); |
| 70 | + }); |
| 71 | + }, |
| 72 | + |
| 73 | + |
| 74 | + /** |
| 75 | + * `VideoController.tags()` |
| 76 | + * Usage: |
| 77 | + */ |
| 78 | + tags: function (req, res) { |
| 79 | + return res.json({ |
| 80 | + todo: 'tags() is not implemented yet!' |
| 81 | + }); |
| 82 | + }, |
| 83 | + |
| 84 | + /** |
| 85 | + * `VideoController.getVideo()` |
| 86 | + * Usage: POST /api/video/getVideo |
| 87 | + * Content: {id: ':id'} |
| 88 | + */ |
| 89 | + getVideo: function (req, res) { |
| 90 | + Video.findOne({ |
| 91 | + id: req.param('id') |
| 92 | + }).exec(function (err, video) { |
| 93 | + if (err) throw err; |
| 94 | + res.json(video.videoDir); |
| 95 | + }); |
| 96 | + } |
| 97 | +}; |
| 98 | + |
0 commit comments