Skip to content

Commit 89c5ce3

Browse files
committed
Add GET routes for likes and comments
1 parent 6c1989e commit 89c5ce3

File tree

5 files changed

+289
-11
lines changed

5 files changed

+289
-11
lines changed

api/doc/api_data.js

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ define({ "api": [
115115
"examples": [
116116
{
117117
"title": "Success-Response:",
118-
"content": "HTTP/1.1 200 OK\n {\n \"id\": \"cheval-noir\",\n \"name\": \"Cheval Noir\",\n \"type\": \"Rouge\",\n \"appellation\": {\"name\": \"Saint-Emilion\", \"region\": \"Bordeaux\"},\n \"grapes\": [\"Cabernet Sauvignon\", \"Merlot\", \"Cabernet Franc\"]\n }",
118+
"content": "HTTP/1.1 200 OK\n{\n \"id\": \"cheval-noir\",\n \"name\": \"Cheval Noir\",\n \"type\": \"Rouge\",\n \"appellation\": {\"name\": \"Saint-Emilion\", \"region\": \"Bordeaux\"},\n \"grapes\": [\"Cabernet Sauvignon\", \"Merlot\", \"Cabernet Franc\"]\n}",
119119
"type": "json"
120120
}
121121
]
@@ -247,6 +247,68 @@ define({ "api": [
247247
"filename": "src/server.js",
248248
"groupTitle": "Wines"
249249
},
250+
{
251+
"type": "get",
252+
"url": "/wines/:id/comments",
253+
"title": "Comments",
254+
"name": "Comments",
255+
"group": "Wines",
256+
"parameter": {
257+
"fields": {
258+
"Parameter": [
259+
{
260+
"group": "Parameter",
261+
"type": "String",
262+
"optional": false,
263+
"field": "id",
264+
"description": "<p>the id of the wine</p>"
265+
}
266+
]
267+
}
268+
},
269+
"sampleRequest": [
270+
{
271+
"url": "/api/wines/:id/comments"
272+
}
273+
],
274+
"success": {
275+
"fields": {
276+
"Success 200": [
277+
{
278+
"group": "Success 200",
279+
"type": "String",
280+
"optional": false,
281+
"field": "date",
282+
"description": "<p>the date of the comment</p>"
283+
},
284+
{
285+
"group": "Success 200",
286+
"type": "String",
287+
"optional": false,
288+
"field": "title",
289+
"description": "<p>the title of the comment</p>"
290+
},
291+
{
292+
"group": "Success 200",
293+
"type": "String",
294+
"optional": false,
295+
"field": "content",
296+
"description": "<p>the comment</p>"
297+
}
298+
]
299+
},
300+
"examples": [
301+
{
302+
"title": "Success-Response:",
303+
"content": "HTTP/1.1 200 OK\n[\n {\n date: \"2016-03-13T20:49:12.129Z\",\n title: \"Un bon bordeaux !\",\n content: \"J'ai bu le millésime 2009, parfait après une heure en carafe !\"\n }\n]",
304+
"type": "json"
305+
}
306+
]
307+
},
308+
"version": "0.0.0",
309+
"filename": "src/server.js",
310+
"groupTitle": "Wines"
311+
},
250312
{
251313
"type": "get",
252314
"url": "/wines/:id/image",
@@ -269,5 +331,53 @@ define({ "api": [
269331
"version": "0.0.0",
270332
"filename": "src/server.js",
271333
"groupTitle": "Wines"
334+
},
335+
{
336+
"type": "get",
337+
"url": "/wines/:id/image",
338+
"title": "Liked ?",
339+
"name": "Liked__",
340+
"group": "Wines",
341+
"parameter": {
342+
"fields": {
343+
"Parameter": [
344+
{
345+
"group": "Parameter",
346+
"type": "String",
347+
"optional": false,
348+
"field": "id",
349+
"description": "<p>the id of the wine</p>"
350+
}
351+
]
352+
}
353+
},
354+
"sampleRequest": [
355+
{
356+
"url": "/api/wines/:id/like"
357+
}
358+
],
359+
"success": {
360+
"fields": {
361+
"Success 200": [
362+
{
363+
"group": "Success 200",
364+
"type": "Boolean",
365+
"optional": false,
366+
"field": "like",
367+
"description": "<p>indicates if the current user likes the wine</p>"
368+
}
369+
]
370+
},
371+
"examples": [
372+
{
373+
"title": "Success-Response:",
374+
"content": "HTTP/1.1 200 OK\n{\n \"like\": false\n}",
375+
"type": "json"
376+
}
377+
]
378+
},
379+
"version": "0.0.0",
380+
"filename": "src/server.js",
381+
"groupTitle": "Wines"
272382
}
273383
] });

api/doc/api_data.json

Lines changed: 111 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@
115115
"examples": [
116116
{
117117
"title": "Success-Response:",
118-
"content": "HTTP/1.1 200 OK\n {\n \"id\": \"cheval-noir\",\n \"name\": \"Cheval Noir\",\n \"type\": \"Rouge\",\n \"appellation\": {\"name\": \"Saint-Emilion\", \"region\": \"Bordeaux\"},\n \"grapes\": [\"Cabernet Sauvignon\", \"Merlot\", \"Cabernet Franc\"]\n }",
118+
"content": "HTTP/1.1 200 OK\n{\n \"id\": \"cheval-noir\",\n \"name\": \"Cheval Noir\",\n \"type\": \"Rouge\",\n \"appellation\": {\"name\": \"Saint-Emilion\", \"region\": \"Bordeaux\"},\n \"grapes\": [\"Cabernet Sauvignon\", \"Merlot\", \"Cabernet Franc\"]\n}",
119119
"type": "json"
120120
}
121121
]
@@ -247,6 +247,68 @@
247247
"filename": "src/server.js",
248248
"groupTitle": "Wines"
249249
},
250+
{
251+
"type": "get",
252+
"url": "/wines/:id/comments",
253+
"title": "Comments",
254+
"name": "Comments",
255+
"group": "Wines",
256+
"parameter": {
257+
"fields": {
258+
"Parameter": [
259+
{
260+
"group": "Parameter",
261+
"type": "String",
262+
"optional": false,
263+
"field": "id",
264+
"description": "<p>the id of the wine</p>"
265+
}
266+
]
267+
}
268+
},
269+
"sampleRequest": [
270+
{
271+
"url": "/api/wines/:id/comments"
272+
}
273+
],
274+
"success": {
275+
"fields": {
276+
"Success 200": [
277+
{
278+
"group": "Success 200",
279+
"type": "String",
280+
"optional": false,
281+
"field": "date",
282+
"description": "<p>the date of the comment</p>"
283+
},
284+
{
285+
"group": "Success 200",
286+
"type": "String",
287+
"optional": false,
288+
"field": "title",
289+
"description": "<p>the title of the comment</p>"
290+
},
291+
{
292+
"group": "Success 200",
293+
"type": "String",
294+
"optional": false,
295+
"field": "content",
296+
"description": "<p>the comment</p>"
297+
}
298+
]
299+
},
300+
"examples": [
301+
{
302+
"title": "Success-Response:",
303+
"content": "HTTP/1.1 200 OK\n[\n {\n date: \"2016-03-13T20:49:12.129Z\",\n title: \"Un bon bordeaux !\",\n content: \"J'ai bu le millésime 2009, parfait après une heure en carafe !\"\n }\n]",
304+
"type": "json"
305+
}
306+
]
307+
},
308+
"version": "0.0.0",
309+
"filename": "src/server.js",
310+
"groupTitle": "Wines"
311+
},
250312
{
251313
"type": "get",
252314
"url": "/wines/:id/image",
@@ -269,5 +331,53 @@
269331
"version": "0.0.0",
270332
"filename": "src/server.js",
271333
"groupTitle": "Wines"
334+
},
335+
{
336+
"type": "get",
337+
"url": "/wines/:id/image",
338+
"title": "Liked ?",
339+
"name": "Liked__",
340+
"group": "Wines",
341+
"parameter": {
342+
"fields": {
343+
"Parameter": [
344+
{
345+
"group": "Parameter",
346+
"type": "String",
347+
"optional": false,
348+
"field": "id",
349+
"description": "<p>the id of the wine</p>"
350+
}
351+
]
352+
}
353+
},
354+
"sampleRequest": [
355+
{
356+
"url": "/api/wines/:id/like"
357+
}
358+
],
359+
"success": {
360+
"fields": {
361+
"Success 200": [
362+
{
363+
"group": "Success 200",
364+
"type": "Boolean",
365+
"optional": false,
366+
"field": "like",
367+
"description": "<p>indicates if the current user likes the wine</p>"
368+
}
369+
]
370+
},
371+
"examples": [
372+
{
373+
"title": "Success-Response:",
374+
"content": "HTTP/1.1 200 OK\n{\n \"like\": false\n}",
375+
"type": "json"
376+
}
377+
]
378+
},
379+
"version": "0.0.0",
380+
"filename": "src/server.js",
381+
"groupTitle": "Wines"
272382
}
273383
]

api/doc/api_project.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ define({
88
"apidoc": "0.2.0",
99
"generator": {
1010
"name": "apidoc",
11-
"time": "2016-03-13T18:17:54.196Z",
11+
"time": "2016-03-13T20:50:54.459Z",
1212
"url": "http://apidocjs.com",
1313
"version": "0.15.1"
1414
}

api/doc/api_project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"apidoc": "0.2.0",
99
"generator": {
1010
"name": "apidoc",
11-
"time": "2016-03-13T18:17:54.196Z",
11+
"time": "2016-03-13T20:50:54.459Z",
1212
"url": "http://apidocjs.com",
1313
"version": "0.15.1"
1414
}

api/src/server.js

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ BurgundyWines.forEach(byId);
2525
ChampagneWines.forEach(byId);
2626
LoireWines.forEach(byId);
2727

28+
// Likes and Comments
29+
var Likes = [];
30+
var Comments = {
31+
"chevrol-bel-air": [{
32+
"date": new Date(),
33+
"title": "Un bon bordeaux !",
34+
"content": "J'ai bu le millésime 2009, parfait après une heure en carafe !"
35+
}]
36+
};
37+
2838
// Serve API documentation
2939
app.use(express.static('doc'));
3040

@@ -104,13 +114,13 @@ app.get('/api/wines', function (req, res) {
104114
*
105115
* @apiSuccessExample {json} Success-Response:
106116
* HTTP/1.1 200 OK
107-
* {
108-
* "id": "cheval-noir",
109-
* "name": "Cheval Noir",
110-
* "type": "Rouge",
111-
* "appellation": {"name": "Saint-Emilion", "region": "Bordeaux"},
112-
* "grapes": ["Cabernet Sauvignon", "Merlot", "Cabernet Franc"]
113-
* }
117+
* {
118+
* "id": "cheval-noir",
119+
* "name": "Cheval Noir",
120+
* "type": "Rouge",
121+
* "appellation": {"name": "Saint-Emilion", "region": "Bordeaux"},
122+
* "grapes": ["Cabernet Sauvignon", "Merlot", "Cabernet Franc"]
123+
* }
114124
*
115125
* @apiError {String} 404 Not found - No wine corresponding to given 'id'
116126
*/
@@ -136,6 +146,54 @@ app.get('/api/wines/:id/image', function (req, res) {
136146
res.sendFile(__dirname + '/data/images/' + req.params.id + '.png');
137147
});
138148

149+
/**
150+
* @api {get} /wines/:id/image Liked ?
151+
* @apiName Liked ?
152+
* @apiGroup Wines
153+
*
154+
* @apiParam {String} id the id of the wine
155+
*
156+
* @apiSampleRequest /api/wines/:id/like
157+
*
158+
* @apiSuccess {Boolean} like indicates if the current user likes the wine
159+
*
160+
* @apiSuccessExample {json} Success-Response:
161+
* HTTP/1.1 200 OK
162+
* {
163+
* "like": false
164+
* }
165+
*/
166+
app.get('/api/wines/:id/like', function (req, res) {
167+
res.send({like: Likes.indexOf(req.params.id) >= 0});
168+
});
169+
170+
/**
171+
* @api {get} /wines/:id/comments Comments
172+
* @apiName Comments
173+
* @apiGroup Wines
174+
*
175+
* @apiParam {String} id the id of the wine
176+
*
177+
* @apiSampleRequest /api/wines/:id/comments
178+
*
179+
* @apiSuccess {String} date the date of the comment
180+
* @apiSuccess {String} title the title of the comment
181+
* @apiSuccess {String} content the comment
182+
*
183+
* @apiSuccessExample {json} Success-Response:
184+
* HTTP/1.1 200 OK
185+
* [
186+
* {
187+
* date: "2016-03-13T20:49:12.129Z",
188+
* title: "Un bon bordeaux !",
189+
* content: "J'ai bu le millésime 2009, parfait après une heure en carafe !"
190+
* }
191+
* ]
192+
*/
193+
app.get('/api/wines/:id/comments', function (req, res) {
194+
res.send(Comments[req.params.id] || []);
195+
});
196+
139197
/**
140198
* @api {get} /regions All
141199
* @apiName All

0 commit comments

Comments
 (0)