forked from sf-wdi-25/express_self_api
-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathshopsController.js
More file actions
71 lines (47 loc) · 1.41 KB
/
shopsController.js
File metadata and controls
71 lines (47 loc) · 1.41 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
59
60
61
62
63
64
65
66
67
68
69
70
71
//Database
var db = require('../models');
// GET /api/shops
function index(req, res) {
// send back all shops as JSON
db.Shop.find({}, function(err, allShops) {
res.json(allShops);
});
}
// POST /api/shops
function create(req, res) {
// create an shop based on request body and send it back as JSON
console.log('body', req.body);
// split at comma and remove and trailing space
db.Shop.create(req.body, function(err, shop) {
if (err) { console.log('error', err); }
console.log(shop);
res.json(shop);
});
}
// GET /api/albums/:shopId
function show(req, res) {
// find one album by id and send it back as JSON
db.Show.findById(req.params.showId, function(err, foundShop) {
if(err) { console.log('albumsController.show error', err); }
console.log('shopsController.show responding with', foundShop);
res.json(foundShop);
});
}
// DELETE /api/albums/:albumId
function destroy(req, res) {
console.log(req.params.shopId)
// find one album by id, delete it, and send it back as JSON
db.Shop.findByIdAndRemove(req.params.shopId, function(err, deleteShop) {
if(err) { console.log('albumsController.destroy error', err); }
console.log('albumsController.destroy responding with', deleteShop);
res.json(deleteShop);
});
}
// export public methods here
module.exports = {
index: index,
create: create,
show: show,
destroy: destroy,
// update: update
};