{"action":"created","comment":{"url":"https://api.github.com/repos/laudeon/nodejs-api/pulls/comments/27873069","id":27873069,"diff_hunk":"@@ -0,0 +1,220 @@\n+var express = require('express');\n+var router \t= express.Router();\n+var Reviews  = require('../models/reviews.js');\n+\n+/*\n+ * Get all reviews\n+ * @Method GET\n+ * Route: /\n+ */\n+router.get('/reviews', function (req, res, next) \n+{\n+\tReviews.find({},function(err, reviews){\n+\t\tif(err) {\n+\t\t\tres.status(500).send(err);\n+\t\t} else {\n+\t\t\tif(req.accepts('text/html') || req.accepts('html')) {\n+\t\t\t\tres.render('reviews/index', {title: \"All reviews\", reviews: reviews});\n+\t\t\t} else {\n+\t\t\t\tres.status(200).send(reviews);\n+\t\t\t}\n+\t\t}\n+\t});\n+});\n+\n+/*\n+ * Get top 3 reviews\n+ * @Method GET\n+ * Route: /\n+ */\n+router.get('/reviews/top', function (req, res, next) \n+{\n+\tReviews.find().limit(3).sort('-stars').exec(function(err, reviews){\n+\t\tif(err) {\n+\t\t\tres.status(500).send(err);\n+\t\t} else {\n+\t\t\tif(req.accepts('text/html') || req.accepts('html')) {\n+\t\t\t\tres.render('reviews/top', {title: \"Top 3\", reviews: reviews});\n+\t\t\t} else {\n+\t\t\t\tres.status(200).send(reviews);\n+\t\t\t}\n+\t\t}\n+\t});\n+});\n+\n+/*\n+ * Search for reviews\n+ * @Method GET\n+ * Route: /\n+ */\n+router.get('/reviews/search', function (req, res, next) \n+{\n+\tReviews.find().or([{stars: parseInt(req.query.search) || null}, {name: req.query.search}, {placeType: req.query.search}]).exec(function(err, reviews){\n+\t\tif(err) {\n+\t\t\tres.status(500).send(err);\n+\t\t} else {\n+\t\t\tif(req.accepts('text/html') || req.accepts('html')) {\n+\t\t\t\tres.render('reviews/search', {title: \"Search Result\", reviews: reviews});\n+\t\t\t} else {\n+\t\t\t\tres.status(200).send(reviews);\n+\t\t\t}\n+\t\t}\n+\t});\n+});\n+\n+/*\n+ * View form add a review\n+ * @Method POST\n+ * Route: /\n+ * Param: id\n+ */\n+router.get('/reviews/add', function (req, res, next) \n+{\n+\tres.status(200).render('reviews/add', {title: \"Add Review\"});\n+});\n+\n+/*\n+ * Add a review\n+ * @Method POST\n+ * Route: /\n+ */\n+router.post('/reviews', function (req, res, next) \n+{\n+\tif(req.body.name && req.body.placeType && req.body.stars) {\n+\t\treview = new Reviews();\n+\n+\t\treview.name = req.body.name;\n+\t\treview.placeType = req.body.placeType;\n+\t\treview.stars = req.body.stars;\n+\n+\t\treview.save(function(err, review){\n+\t\t\tif(err) {\n+\t\t\t\tres.status(500).send(err);\n+\t\t\t} else {\n+\t\t\t\tif(req.accepts('text/html') || req.accepts('html')) {\n+\t\t\t\t\tReviews.find({}, function(err, reviews){\n+\t\t\t\t\t\tres.render('reviews/index', {title: \"All reviews\", reviews: reviews});\n+\t\t\t\t\t});\n+\t\t\t\t} else {\n+\t\t\t\t\tres.status(201).send(review);\n+\t\t\t\t}\n+\t\t\t}\n+\t\t});\n+  \t} else {\n+  \t\tres.status(400).send('Bad request...');\n+  \t}\n+});\n+\n+/*\n+ * Delete all reviews\n+ * @Method DELETE\n+ * Route: /\n+ */\n+router.delete('/reviews', function (req, res, next) \n+{\n+\tvar query = Reviews.remove();\n+\tquery.exec();\n+\tif(req.accepts('text/html') || req.accepts('html')) {\n+  \t\tres.redirect('/reviews');\n+\t} else {\n+  \t\tres.status(204).send();\n+\t}\n+});\n+\n+/*\n+ * Get a review\n+ * @Method GET\n+ * Route: /\n+ * Param: id\n+ */\n+router.get('/review/:id', function (req, res, next) \n+{\n+\tReviews.findOne({_id: req.params.id}, function (err, review){\n+\t\tif(!review || review.length <= 0 || err) {","path":"routes/reviews.js","position":133,"original_position":133,"commit_id":"2b924f11619b4a2ace6482d2c7fd4194157c6cdb","original_commit_id":"2b924f11619b4a2ace6482d2c7fd4194157c6cdb","user":{"login":"jomaora","id":7602475,"avatar_url":"https://avatars.githubusercontent.com/u/7602475?v=3","gravatar_id":"","url":"https://api.github.com/users/jomaora","html_url":"https://github.com/jomaora","followers_url":"https://api.github.com/users/jomaora/followers","following_url":"https://api.github.com/users/jomaora/following{/other_user}","gists_url":"https://api.github.com/users/jomaora/gists{/gist_id}","starred_url":"https://api.github.com/users/jomaora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jomaora/subscriptions","organizations_url":"https://api.github.com/users/jomaora/orgs","repos_url":"https://api.github.com/users/jomaora/repos","events_url":"https://api.github.com/users/jomaora/events{/privacy}","received_events_url":"https://api.github.com/users/jomaora/received_events","type":"User","site_admin":false},"body":"Si jamais err est truthy, alors il s'agit d'un erreur coté base de données, possiblement un erreur plus technique, et pas le fait que la ressource n'existe pas en base. L'erreur à renvoyer en ce cas est un 500. Vaut mieux traiter les err dans un bloc à part :\r\n\r\n```\r\nif (err) {\r\n    res.status(500).send(err);\r\n}\r\n```","created_at":"2015-04-07T12:32:13Z","updated_at":"2015-04-07T12:32:13Z","html_url":"https://github.com/laudeon/nodejs-api/pull/6#discussion_r27873069","pull_request_url":"https://api.github.com/repos/laudeon/nodejs-api/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/laudeon/nodejs-api/pulls/comments/27873069"},"html":{"href":"https://github.com/laudeon/nodejs-api/pull/6#discussion_r27873069"},"pull_request":{"href":"https://api.github.com/repos/laudeon/nodejs-api/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/laudeon/nodejs-api/pulls/6","id":32758455,"html_url":"https://github.com/laudeon/nodejs-api/pull/6","diff_url":"https://github.com/laudeon/nodejs-api/pull/6.diff","patch_url":"https://github.com/laudeon/nodejs-api/pull/6.patch","issue_url":"https://api.github.com/repos/laudeon/nodejs-api/issues/6","number":6,"state":"open","locked":false,"title":"Code Review","user":{"login":"jomaora","id":7602475,"avatar_url":"https://avatars.githubusercontent.com/u/7602475?v=3","gravatar_id":"","url":"https://api.github.com/users/jomaora","html_url":"https://github.com/jomaora","followers_url":"https://api.github.com/users/jomaora/followers","following_url":"https://api.github.com/users/jomaora/following{/other_user}","gists_url":"https://api.github.com/users/jomaora/gists{/gist_id}","starred_url":"https://api.github.com/users/jomaora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jomaora/subscriptions","organizations_url":"https://api.github.com/users/jomaora/orgs","repos_url":"https://api.github.com/users/jomaora/repos","events_url":"https://api.github.com/users/jomaora/events{/privacy}","received_events_url":"https://api.github.com/users/jomaora/received_events","type":"User","site_admin":false},"body":"Cette PR permettra d'afficher mes commentaires et corrections sur ton projet","created_at":"2015-04-07T12:21:02Z","updated_at":"2015-04-07T12:32:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cb155bd8c42c1090851c16de482775fb77d60c77","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/laudeon/nodejs-api/pulls/6/commits","review_comments_url":"https://api.github.com/repos/laudeon/nodejs-api/pulls/6/comments","review_comment_url":"https://api.github.com/repos/laudeon/nodejs-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/laudeon/nodejs-api/issues/6/comments","statuses_url":"https://api.github.com/repos/laudeon/nodejs-api/statuses/2b924f11619b4a2ace6482d2c7fd4194157c6cdb","head":{"label":"laudeon:master","ref":"master","sha":"2b924f11619b4a2ace6482d2c7fd4194157c6cdb","user":{"login":"laudeon","id":7914103,"avatar_url":"https://avatars.githubusercontent.com/u/7914103?v=3","gravatar_id":"","url":"https://api.github.com/users/laudeon","html_url":"https://github.com/laudeon","followers_url":"https://api.github.com/users/laudeon/followers","following_url":"https://api.github.com/users/laudeon/following{/other_user}","gists_url":"https://api.github.com/users/laudeon/gists{/gist_id}","starred_url":"https://api.github.com/users/laudeon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laudeon/subscriptions","organizations_url":"https://api.github.com/users/laudeon/orgs","repos_url":"https://api.github.com/users/laudeon/repos","events_url":"https://api.github.com/users/laudeon/events{/privacy}","received_events_url":"https://api.github.com/users/laudeon/received_events","type":"User","site_admin":false},"repo":{"id":29961443,"name":"nodejs-api","full_name":"laudeon/nodejs-api","owner":{"login":"laudeon","id":7914103,"avatar_url":"https://avatars.githubusercontent.com/u/7914103?v=3","gravatar_id":"","url":"https://api.github.com/users/laudeon","html_url":"https://github.com/laudeon","followers_url":"https://api.github.com/users/laudeon/followers","following_url":"https://api.github.com/users/laudeon/following{/other_user}","gists_url":"https://api.github.com/users/laudeon/gists{/gist_id}","starred_url":"https://api.github.com/users/laudeon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laudeon/subscriptions","organizations_url":"https://api.github.com/users/laudeon/orgs","repos_url":"https://api.github.com/users/laudeon/repos","events_url":"https://api.github.com/users/laudeon/events{/privacy}","received_events_url":"https://api.github.com/users/laudeon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/laudeon/nodejs-api","description":"nodejs api cours","fork":false,"url":"https://api.github.com/repos/laudeon/nodejs-api","forks_url":"https://api.github.com/repos/laudeon/nodejs-api/forks","keys_url":"https://api.github.com/repos/laudeon/nodejs-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/laudeon/nodejs-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/laudeon/nodejs-api/teams","hooks_url":"https://api.github.com/repos/laudeon/nodejs-api/hooks","issue_events_url":"https://api.github.com/repos/laudeon/nodejs-api/issues/events{/number}","events_url":"https://api.github.com/repos/laudeon/nodejs-api/events","assignees_url":"https://api.github.com/repos/laudeon/nodejs-api/assignees{/user}","branches_url":"https://api.github.com/repos/laudeon/nodejs-api/branches{/branch}","tags_url":"https://api.github.com/repos/laudeon/nodejs-api/tags","blobs_url":"https://api.github.com/repos/laudeon/nodejs-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/laudeon/nodejs-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/laudeon/nodejs-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/laudeon/nodejs-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/laudeon/nodejs-api/statuses/{sha}","languages_url":"https://api.github.com/repos/laudeon/nodejs-api/languages","stargazers_url":"https://api.github.com/repos/laudeon/nodejs-api/stargazers","contributors_url":"https://api.github.com/repos/laudeon/nodejs-api/contributors","subscribers_url":"https://api.github.com/repos/laudeon/nodejs-api/subscribers","subscription_url":"https://api.github.com/repos/laudeon/nodejs-api/subscription","commits_url":"https://api.github.com/repos/laudeon/nodejs-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/laudeon/nodejs-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/laudeon/nodejs-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/laudeon/nodejs-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/laudeon/nodejs-api/contents/{+path}","compare_url":"https://api.github.com/repos/laudeon/nodejs-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/laudeon/nodejs-api/merges","archive_url":"https://api.github.com/repos/laudeon/nodejs-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/laudeon/nodejs-api/downloads","issues_url":"https://api.github.com/repos/laudeon/nodejs-api/issues{/number}","pulls_url":"https://api.github.com/repos/laudeon/nodejs-api/pulls{/number}","milestones_url":"https://api.github.com/repos/laudeon/nodejs-api/milestones{/number}","notifications_url":"https://api.github.com/repos/laudeon/nodejs-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/laudeon/nodejs-api/labels{/name}","releases_url":"https://api.github.com/repos/laudeon/nodejs-api/releases{/id}","created_at":"2015-01-28T10:06:05Z","updated_at":"2015-02-20T16:59:23Z","pushed_at":"2015-04-07T12:21:03Z","git_url":"git://github.com/laudeon/nodejs-api.git","ssh_url":"git@github.com:laudeon/nodejs-api.git","clone_url":"https://github.com/laudeon/nodejs-api.git","svn_url":"https://github.com/laudeon/nodejs-api","homepage":null,"size":1044,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"laudeon:code-review","ref":"code-review","sha":"5f5b2969469204af62ed316f8ae8e7dd2578b016","user":{"login":"laudeon","id":7914103,"avatar_url":"https://avatars.githubusercontent.com/u/7914103?v=3","gravatar_id":"","url":"https://api.github.com/users/laudeon","html_url":"https://github.com/laudeon","followers_url":"https://api.github.com/users/laudeon/followers","following_url":"https://api.github.com/users/laudeon/following{/other_user}","gists_url":"https://api.github.com/users/laudeon/gists{/gist_id}","starred_url":"https://api.github.com/users/laudeon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laudeon/subscriptions","organizations_url":"https://api.github.com/users/laudeon/orgs","repos_url":"https://api.github.com/users/laudeon/repos","events_url":"https://api.github.com/users/laudeon/events{/privacy}","received_events_url":"https://api.github.com/users/laudeon/received_events","type":"User","site_admin":false},"repo":{"id":29961443,"name":"nodejs-api","full_name":"laudeon/nodejs-api","owner":{"login":"laudeon","id":7914103,"avatar_url":"https://avatars.githubusercontent.com/u/7914103?v=3","gravatar_id":"","url":"https://api.github.com/users/laudeon","html_url":"https://github.com/laudeon","followers_url":"https://api.github.com/users/laudeon/followers","following_url":"https://api.github.com/users/laudeon/following{/other_user}","gists_url":"https://api.github.com/users/laudeon/gists{/gist_id}","starred_url":"https://api.github.com/users/laudeon/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/laudeon/subscriptions","organizations_url":"https://api.github.com/users/laudeon/orgs","repos_url":"https://api.github.com/users/laudeon/repos","events_url":"https://api.github.com/users/laudeon/events{/privacy}","received_events_url":"https://api.github.com/users/laudeon/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/laudeon/nodejs-api","description":"nodejs api cours","fork":false,"url":"https://api.github.com/repos/laudeon/nodejs-api","forks_url":"https://api.github.com/repos/laudeon/nodejs-api/forks","keys_url":"https://api.github.com/repos/laudeon/nodejs-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/laudeon/nodejs-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/laudeon/nodejs-api/teams","hooks_url":"https://api.github.com/repos/laudeon/nodejs-api/hooks","issue_events_url":"https://api.github.com/repos/laudeon/nodejs-api/issues/events{/number}","events_url":"https://api.github.com/repos/laudeon/nodejs-api/events","assignees_url":"https://api.github.com/repos/laudeon/nodejs-api/assignees{/user}","branches_url":"https://api.github.com/repos/laudeon/nodejs-api/branches{/branch}","tags_url":"https://api.github.com/repos/laudeon/nodejs-api/tags","blobs_url":"https://api.github.com/repos/laudeon/nodejs-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/laudeon/nodejs-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/laudeon/nodejs-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/laudeon/nodejs-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/laudeon/nodejs-api/statuses/{sha}","languages_url":"https://api.github.com/repos/laudeon/nodejs-api/languages","stargazers_url":"https://api.github.com/repos/laudeon/nodejs-api/stargazers","contributors_url":"https://api.github.com/repos/laudeon/nodejs-api/contributors","subscribers_url":"https://api.github.com/repos/laudeon/nodejs-api/subscribers","subscription_url":"https://api.github.com/repos/laudeon/nodejs-api/subscription","commits_url":"https://api.github.com/repos/laudeon/nodejs-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/laudeon/nodejs-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/laudeon/nodejs-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/laudeon/nodejs-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/laudeon/nodejs-api/contents/{+path}","compare_url":"https://api.github.com/repos/laudeon/nodejs-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/laudeon/nodejs-api/merges","archive_url":"https://api.github.com/repos/laudeon/nodejs-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/laudeon/nodejs-api/downloads","issues_url":"https://api.github.com/repos/laudeon/nodejs-api/issues{/number}","pulls_url":"https://api.github.com/repos/laudeon/nodejs-api/pulls{/number}","milestones_url":"https://api.github.com/repos/laudeon/nodejs-api/milestones{/number}","notifications_url":"https://api.github.com/repos/laudeon/nodejs-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/laudeon/nodejs-api/labels{/name}","releases_url":"https://api.github.com/repos/laudeon/nodejs-api/releases{/id}","created_at":"2015-01-28T10:06:05Z","updated_at":"2015-02-20T16:59:23Z","pushed_at":"2015-04-07T12:21:03Z","git_url":"git://github.com/laudeon/nodejs-api.git","ssh_url":"git@github.com:laudeon/nodejs-api.git","clone_url":"https://github.com/laudeon/nodejs-api.git","svn_url":"https://github.com/laudeon/nodejs-api","homepage":null,"size":1044,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/laudeon/nodejs-api/pulls/6"},"html":{"href":"https://github.com/laudeon/nodejs-api/pull/6"},"issue":{"href":"https://api.github.com/repos/laudeon/nodejs-api/issues/6"},"comments":{"href":"https://api.github.com/repos/laudeon/nodejs-api/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/laudeon/nodejs-api/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/laudeon/nodejs-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/laudeon/nodejs-api/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/laudeon/nodejs-api/statuses/2b924f11619b4a2ace6482d2c7fd4194157c6cdb"}}}}