-
Notifications
You must be signed in to change notification settings - Fork 0
/
handlers.js
executable file
·58 lines (51 loc) · 1.33 KB
/
handlers.js
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
var mongoose = require('mongoose'),
Pin = mongoose.model('Pin');
exports.index = function(req, res) {
res.send("Welcome to CS 1501");
}
var watchf = function(req, res) {
var video_id = req.query.v;
res.render('watch', { id: video_id }, function(err, html) {
res.send(html);
})
}
exports.bootstrap = function(req, res) {
res.render('bootstrap101', function(err, html) {
res.send(html);
})
}
exports.pinterless = function(req, res) {
console.log("Query: " + req.query);
if (req.query.search) {
Pin.findByTitle(req.query.search, function(err, all_pins) {
console.log("Pins: " + JSON.stringify(all_pins) );
res.render('pinterless', { pins: all_pins }, function(err, html) {
res.send(html);
})
// res.send(JSON.stringify(result))
});
} else {
Pin.find({}, function(err, all_pins) {
console.log("Pins: " + JSON.stringify(all_pins) );
res.render('pinterless', { pins: all_pins }, function(err, html) {
res.send(html);
})
// res.send(JSON.stringify(result))
});
}
}
exports.createPin = function(req, res) {
var newPin = new Pin({
title: req.body.title,
description: req.body.description,
image_url: req.body.image_url
});
newPin.save(function(err) {
if (err) {
console.log("Error saving pin");
} else {
res.redirect('/pinterless');
};
});
}
exports.watch = watchf;