{"action":"created","comment":{"url":"https://api.github.com/repos/HackYourFuture/Node.js/pulls/comments/219980931","pull_request_review_id":158274901,"id":219980931,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIxOTk4MDkzMQ==","diff_hunk":"@@ -1,3 +1,140 @@\n 'use strict';\n+const express = require('express');\n+const app = express();\n+const bodyParser = require(\"body-parser\");\n+const fs = require(\"fs\");\n+app.use(bodyParser.json());\n \n-// TODO: Write the homework code in this file\n+app.get('/list', function (request, response) {\n+  fs.readFile('./toDo.json', 'utf8', function (error, data) {\n+    if (error) {\n+      console.log(error);\n+      return;\n+    }\n+    const myToDoList = JSON.parse(data);\n+    if (Object.values(myToDoList).length === 0) {\n+      response.end('You have not any plan in your To Do List');\n+      return;\n+    }\n+    response.json(myToDoList);\n+  });\n+});\n+\n+app.get('/list/:id', function (request, response) {\n+  fs.readFile('./toDo.json', 'utf8', function (error, data) {\n+    if (error) {\n+      console.log(error);\n+      return;\n+    }\n+    const myToDoList = JSON.parse(data);\n+    if (Object.values(myToDoList).length === 0) {\n+      response.end('You have not any plan in your To Do List');\n+      return;\n+    }\n+    const index = request.params.id;\n+    if (isNaN(index) === true) {\n+      response.end('You have to enter a number as /list/2');\n+      return;\n+    }\n+    response.json(myToDoList[index]);\n+    console.log()\n+  });\n+});\n+\n+app.post(\"/add/:item\", function (request, response) {\n+  fs.readFile('./toDo.json', 'utf8', function (error, data) {\n+    if (error) {\n+      console.log(error);\n+      return;\n+    }\n+    const myToDoList = JSON.parse(data);\n+    const newToDoItem = {\n+      'index': myToDoList.length,\n+      'description': request.params.item\n+    };\n+    myToDoList.push(newToDoItem);\n+    fs.writeFile('./toDo.json', JSON.stringify(myToDoList), function (error) {\n+      if (error) {\n+        console.error(error);\n+      }\n+    });\n+    response.json(myToDoList);\n+  });\n+});\n+\n+app.delete('/delete', function (request, response) {\n+  fs.readFile('./toDo.json', 'utf8', function (error, data) {\n+    if (error) {\n+      console.log(error);\n+      return;\n+    }\n+    const myToDoList = JSON.parse(data);\n+    if (Object.values(myToDoList).length === 0) {\n+      response.end('I can not delete an empty list, firsty try to add sth to list.');\n+      return;\n+    }\n+    fs.writeFile('./toDo.json', '[]', function (error) {\n+      if (error) { console.log(error); }\n+    });\n+    response.end(\"You have cleared all items of to-do list\")\n+  });\n+});\n+\n+app.delete('/delete/:item', function (request, response) {\n+  fs.readFile('./toDo.json', 'utf8', function (error, data) {\n+    if (error) {\n+      console.log(error);\n+      return;\n+    }\n+    const myToDoList = JSON.parse(data);\n+    if (request.params.item < 0) {\n+      response.end('The parameter you entered as index is invalid');\n+      return;\n+    }\n+    if (request.params.item > Object.values(myToDoList).length) {\n+      response.end(`There is not any item in the list in the index of \" ${request.params.item} \"`)\n+      return\n+    }\n+    myToDoList.splice(request.params.item, 1);\n+    myToDoList.forEach(function (x) {\n+      x.index = myToDoList.indexOf(x);\n+    });\n+    fs.writeFile('./toDo.json', JSON.stringify(myToDoList), function (error) {\n+      if (error) { console.log(error); }\n+    });\n+    response.end(`You have deleted item \" ${request.params.item} \" and re-created to-do list`)\n+  });\n+});\n+\n+app.post('/mark/:id/done', function (request, response) {\n+  fs.readFile('./toDo.json', 'utf8', function (error, data) {\n+    if (error) {\n+      console.log(error);\n+      return;\n+    }\n+    const myToDoList = JSON.parse(data);\n+    myToDoList[request.params.id].done = \"true\";","path":"week3/homework/src/index.js","position":117,"original_position":117,"commit_id":"98fb468908f145fdfd1978a5f72962c851dcb1ce","original_commit_id":"98fb468908f145fdfd1978a5f72962c851dcb1ce","user":{"login":"J05J4","id":1948641,"node_id":"MDQ6VXNlcjE5NDg2NDE=","avatar_url":"https://avatars0.githubusercontent.com/u/1948641?v=4","gravatar_id":"","url":"https://api.github.com/users/J05J4","html_url":"https://github.com/J05J4","followers_url":"https://api.github.com/users/J05J4/followers","following_url":"https://api.github.com/users/J05J4/following{/other_user}","gists_url":"https://api.github.com/users/J05J4/gists{/gist_id}","starred_url":"https://api.github.com/users/J05J4/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/J05J4/subscriptions","organizations_url":"https://api.github.com/users/J05J4/orgs","repos_url":"https://api.github.com/users/J05J4/repos","events_url":"https://api.github.com/users/J05J4/events{/privacy}","received_events_url":"https://api.github.com/users/J05J4/received_events","type":"User","site_admin":false},"body":"You could use the same kind of error handling here, if someone gives an id that does not exist as you did above...","created_at":"2018-09-24T20:39:02Z","updated_at":"2018-09-24T20:47:21Z","html_url":"https://github.com/HackYourFuture/Node.js/pull/249#discussion_r219980931","pull_request_url":"https://api.github.com/repos/HackYourFuture/Node.js/pulls/249","author_association":"NONE","_links":{"self":{"href":"https://api.github.com/repos/HackYourFuture/Node.js/pulls/comments/219980931"},"html":{"href":"https://github.com/HackYourFuture/Node.js/pull/249#discussion_r219980931"},"pull_request":{"href":"https://api.github.com/repos/HackYourFuture/Node.js/pulls/249"}}},"pull_request":{"url":"https://api.github.com/repos/HackYourFuture/Node.js/pulls/249","id":217343475,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE3MzQzNDc1","html_url":"https://github.com/HackYourFuture/Node.js/pull/249","diff_url":"https://github.com/HackYourFuture/Node.js/pull/249.diff","patch_url":"https://github.com/HackYourFuture/Node.js/pull/249.patch","issue_url":"https://api.github.com/repos/HackYourFuture/Node.js/issues/249","number":249,"state":"open","locked":false,"title":"Week3 Barbaros","user":{"login":"whitepiolin","id":39315387,"node_id":"MDQ6VXNlcjM5MzE1Mzg3","avatar_url":"https://avatars1.githubusercontent.com/u/39315387?v=4","gravatar_id":"","url":"https://api.github.com/users/whitepiolin","html_url":"https://github.com/whitepiolin","followers_url":"https://api.github.com/users/whitepiolin/followers","following_url":"https://api.github.com/users/whitepiolin/following{/other_user}","gists_url":"https://api.github.com/users/whitepiolin/gists{/gist_id}","starred_url":"https://api.github.com/users/whitepiolin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whitepiolin/subscriptions","organizations_url":"https://api.github.com/users/whitepiolin/orgs","repos_url":"https://api.github.com/users/whitepiolin/repos","events_url":"https://api.github.com/users/whitepiolin/events{/privacy}","received_events_url":"https://api.github.com/users/whitepiolin/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-09-21T16:53:40Z","updated_at":"2018-09-24T20:47:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3e9c0361ce7376557342d2f650b8579583126e8c","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":1052715631,"node_id":"MDU6TGFiZWwxMDUyNzE1NjMx","url":"https://api.github.com/repos/HackYourFuture/Node.js/labels/class%2016","name":"class 16","color":"0052cc","default":false},{"id":883891913,"node_id":"MDU6TGFiZWw4ODM4OTE5MTM=","url":"https://api.github.com/repos/HackYourFuture/Node.js/labels/homework3","name":"homework3","color":"0bead8","default":false},{"id":862630052,"node_id":"MDU6TGFiZWw4NjI2MzAwNTI=","url":"https://api.github.com/repos/HackYourFuture/Node.js/labels/to%20review","name":"to review","color":"fbca04","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/HackYourFuture/Node.js/pulls/249/commits","review_comments_url":"https://api.github.com/repos/HackYourFuture/Node.js/pulls/249/comments","review_comment_url":"https://api.github.com/repos/HackYourFuture/Node.js/pulls/comments{/number}","comments_url":"https://api.github.com/repos/HackYourFuture/Node.js/issues/249/comments","statuses_url":"https://api.github.com/repos/HackYourFuture/Node.js/statuses/98fb468908f145fdfd1978a5f72962c851dcb1ce","head":{"label":"whitepiolin:week3edit","ref":"week3edit","sha":"98fb468908f145fdfd1978a5f72962c851dcb1ce","user":{"login":"whitepiolin","id":39315387,"node_id":"MDQ6VXNlcjM5MzE1Mzg3","avatar_url":"https://avatars1.githubusercontent.com/u/39315387?v=4","gravatar_id":"","url":"https://api.github.com/users/whitepiolin","html_url":"https://github.com/whitepiolin","followers_url":"https://api.github.com/users/whitepiolin/followers","following_url":"https://api.github.com/users/whitepiolin/following{/other_user}","gists_url":"https://api.github.com/users/whitepiolin/gists{/gist_id}","starred_url":"https://api.github.com/users/whitepiolin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whitepiolin/subscriptions","organizations_url":"https://api.github.com/users/whitepiolin/orgs","repos_url":"https://api.github.com/users/whitepiolin/repos","events_url":"https://api.github.com/users/whitepiolin/events{/privacy}","received_events_url":"https://api.github.com/users/whitepiolin/received_events","type":"User","site_admin":false},"repo":{"id":147742314,"node_id":"MDEwOlJlcG9zaXRvcnkxNDc3NDIzMTQ=","name":"Node.js","full_name":"whitepiolin/Node.js","private":false,"owner":{"login":"whitepiolin","id":39315387,"node_id":"MDQ6VXNlcjM5MzE1Mzg3","avatar_url":"https://avatars1.githubusercontent.com/u/39315387?v=4","gravatar_id":"","url":"https://api.github.com/users/whitepiolin","html_url":"https://github.com/whitepiolin","followers_url":"https://api.github.com/users/whitepiolin/followers","following_url":"https://api.github.com/users/whitepiolin/following{/other_user}","gists_url":"https://api.github.com/users/whitepiolin/gists{/gist_id}","starred_url":"https://api.github.com/users/whitepiolin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whitepiolin/subscriptions","organizations_url":"https://api.github.com/users/whitepiolin/orgs","repos_url":"https://api.github.com/users/whitepiolin/repos","events_url":"https://api.github.com/users/whitepiolin/events{/privacy}","received_events_url":"https://api.github.com/users/whitepiolin/received_events","type":"User","site_admin":false},"html_url":"https://github.com/whitepiolin/Node.js","description":"HackYourFuture - Node.js","fork":true,"url":"https://api.github.com/repos/whitepiolin/Node.js","forks_url":"https://api.github.com/repos/whitepiolin/Node.js/forks","keys_url":"https://api.github.com/repos/whitepiolin/Node.js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/whitepiolin/Node.js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/whitepiolin/Node.js/teams","hooks_url":"https://api.github.com/repos/whitepiolin/Node.js/hooks","issue_events_url":"https://api.github.com/repos/whitepiolin/Node.js/issues/events{/number}","events_url":"https://api.github.com/repos/whitepiolin/Node.js/events","assignees_url":"https://api.github.com/repos/whitepiolin/Node.js/assignees{/user}","branches_url":"https://api.github.com/repos/whitepiolin/Node.js/branches{/branch}","tags_url":"https://api.github.com/repos/whitepiolin/Node.js/tags","blobs_url":"https://api.github.com/repos/whitepiolin/Node.js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/whitepiolin/Node.js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/whitepiolin/Node.js/git/refs{/sha}","trees_url":"https://api.github.com/repos/whitepiolin/Node.js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/whitepiolin/Node.js/statuses/{sha}","languages_url":"https://api.github.com/repos/whitepiolin/Node.js/languages","stargazers_url":"https://api.github.com/repos/whitepiolin/Node.js/stargazers","contributors_url":"https://api.github.com/repos/whitepiolin/Node.js/contributors","subscribers_url":"https://api.github.com/repos/whitepiolin/Node.js/subscribers","subscription_url":"https://api.github.com/repos/whitepiolin/Node.js/subscription","commits_url":"https://api.github.com/repos/whitepiolin/Node.js/commits{/sha}","git_commits_url":"https://api.github.com/repos/whitepiolin/Node.js/git/commits{/sha}","comments_url":"https://api.github.com/repos/whitepiolin/Node.js/comments{/number}","issue_comment_url":"https://api.github.com/repos/whitepiolin/Node.js/issues/comments{/number}","contents_url":"https://api.github.com/repos/whitepiolin/Node.js/contents/{+path}","compare_url":"https://api.github.com/repos/whitepiolin/Node.js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/whitepiolin/Node.js/merges","archive_url":"https://api.github.com/repos/whitepiolin/Node.js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/whitepiolin/Node.js/downloads","issues_url":"https://api.github.com/repos/whitepiolin/Node.js/issues{/number}","pulls_url":"https://api.github.com/repos/whitepiolin/Node.js/pulls{/number}","milestones_url":"https://api.github.com/repos/whitepiolin/Node.js/milestones{/number}","notifications_url":"https://api.github.com/repos/whitepiolin/Node.js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/whitepiolin/Node.js/labels{/name}","releases_url":"https://api.github.com/repos/whitepiolin/Node.js/releases{/id}","deployments_url":"https://api.github.com/repos/whitepiolin/Node.js/deployments","created_at":"2018-09-06T22:51:06Z","updated_at":"2018-09-06T22:51:08Z","pushed_at":"2018-09-21T17:00:03Z","git_url":"git://github.com/whitepiolin/Node.js.git","ssh_url":"git@github.com:whitepiolin/Node.js.git","clone_url":"https://github.com/whitepiolin/Node.js.git","svn_url":"https://github.com/whitepiolin/Node.js","homepage":"","size":780,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"license":null,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"HackYourFuture:master","ref":"master","sha":"948e655329a5085fe693cc3e8e6c4505428dfd19","user":{"login":"HackYourFuture","id":20858568,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIwODU4NTY4","avatar_url":"https://avatars2.githubusercontent.com/u/20858568?v=4","gravatar_id":"","url":"https://api.github.com/users/HackYourFuture","html_url":"https://github.com/HackYourFuture","followers_url":"https://api.github.com/users/HackYourFuture/followers","following_url":"https://api.github.com/users/HackYourFuture/following{/other_user}","gists_url":"https://api.github.com/users/HackYourFuture/gists{/gist_id}","starred_url":"https://api.github.com/users/HackYourFuture/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HackYourFuture/subscriptions","organizations_url":"https://api.github.com/users/HackYourFuture/orgs","repos_url":"https://api.github.com/users/HackYourFuture/repos","events_url":"https://api.github.com/users/HackYourFuture/events{/privacy}","received_events_url":"https://api.github.com/users/HackYourFuture/received_events","type":"Organization","site_admin":false},"repo":{"id":68906713,"node_id":"MDEwOlJlcG9zaXRvcnk2ODkwNjcxMw==","name":"Node.js","full_name":"HackYourFuture/Node.js","private":false,"owner":{"login":"HackYourFuture","id":20858568,"node_id":"MDEyOk9yZ2FuaXphdGlvbjIwODU4NTY4","avatar_url":"https://avatars2.githubusercontent.com/u/20858568?v=4","gravatar_id":"","url":"https://api.github.com/users/HackYourFuture","html_url":"https://github.com/HackYourFuture","followers_url":"https://api.github.com/users/HackYourFuture/followers","following_url":"https://api.github.com/users/HackYourFuture/following{/other_user}","gists_url":"https://api.github.com/users/HackYourFuture/gists{/gist_id}","starred_url":"https://api.github.com/users/HackYourFuture/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HackYourFuture/subscriptions","organizations_url":"https://api.github.com/users/HackYourFuture/orgs","repos_url":"https://api.github.com/users/HackYourFuture/repos","events_url":"https://api.github.com/users/HackYourFuture/events{/privacy}","received_events_url":"https://api.github.com/users/HackYourFuture/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/HackYourFuture/Node.js","description":"HackYourFuture - Node.js","fork":false,"url":"https://api.github.com/repos/HackYourFuture/Node.js","forks_url":"https://api.github.com/repos/HackYourFuture/Node.js/forks","keys_url":"https://api.github.com/repos/HackYourFuture/Node.js/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HackYourFuture/Node.js/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HackYourFuture/Node.js/teams","hooks_url":"https://api.github.com/repos/HackYourFuture/Node.js/hooks","issue_events_url":"https://api.github.com/repos/HackYourFuture/Node.js/issues/events{/number}","events_url":"https://api.github.com/repos/HackYourFuture/Node.js/events","assignees_url":"https://api.github.com/repos/HackYourFuture/Node.js/assignees{/user}","branches_url":"https://api.github.com/repos/HackYourFuture/Node.js/branches{/branch}","tags_url":"https://api.github.com/repos/HackYourFuture/Node.js/tags","blobs_url":"https://api.github.com/repos/HackYourFuture/Node.js/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HackYourFuture/Node.js/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HackYourFuture/Node.js/git/refs{/sha}","trees_url":"https://api.github.com/repos/HackYourFuture/Node.js/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HackYourFuture/Node.js/statuses/{sha}","languages_url":"https://api.github.com/repos/HackYourFuture/Node.js/languages","stargazers_url":"https://api.github.com/repos/HackYourFuture/Node.js/stargazers","contributors_url":"https://api.github.com/repos/HackYourFuture/Node.js/contributors","subscribers_url":"https://api.github.com/repos/HackYourFuture/Node.js/subscribers","subscription_url":"https://api.github.com/repos/HackYourFuture/Node.js/subscription","commits_url":"https://api.github.com/repos/HackYourFuture/Node.js/commits{/sha}","git_commits_url":"https://api.github.com/repos/HackYourFuture/Node.js/git/commits{/sha}","comments_url":"https://api.github.com/repos/HackYourFuture/Node.js/comments{/number}","issue_comment_url":"https://api.github.com/repos/HackYourFuture/Node.js/issues/comments{/number}","contents_url":"https://api.github.com/repos/HackYourFuture/Node.js/contents/{+path}","compare_url":"https://api.github.com/repos/HackYourFuture/Node.js/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HackYourFuture/Node.js/merges","archive_url":"https://api.github.com/repos/HackYourFuture/Node.js/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HackYourFuture/Node.js/downloads","issues_url":"https://api.github.com/repos/HackYourFuture/Node.js/issues{/number}","pulls_url":"https://api.github.com/repos/HackYourFuture/Node.js/pulls{/number}","milestones_url":"https://api.github.com/repos/HackYourFuture/Node.js/milestones{/number}","notifications_url":"https://api.github.com/repos/HackYourFuture/Node.js/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HackYourFuture/Node.js/labels{/name}","releases_url":"https://api.github.com/repos/HackYourFuture/Node.js/releases{/id}","deployments_url":"https://api.github.com/repos/HackYourFuture/Node.js/deployments","created_at":"2016-09-22T09:36:44Z","updated_at":"2018-06-22T10:15:58Z","pushed_at":"2018-09-24T17:23:40Z","git_url":"git://github.com/HackYourFuture/Node.js.git","ssh_url":"git@github.com:HackYourFuture/Node.js.git","clone_url":"https://github.com/HackYourFuture/Node.js.git","svn_url":"https://github.com/HackYourFuture/Node.js","homepage":"","size":695,"stargazers_count":26,"watchers_count":26,"language":"JavaScript","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":135,"mirror_url":null,"archived":false,"open_issues_count":40,"license":null,"forks":135,"open_issues":40,"watchers":26,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/HackYourFuture/Node.js/pulls/249"},"html":{"href":"https://github.com/HackYourFuture/Node.js/pull/249"},"issue":{"href":"https://api.github.com/repos/HackYourFuture/Node.js/issues/249"},"comments":{"href":"https://api.github.com/repos/HackYourFuture/Node.js/issues/249/comments"},"review_comments":{"href":"https://api.github.com/repos/HackYourFuture/Node.js/pulls/249/comments"},"review_comment":{"href":"https://api.github.com/repos/HackYourFuture/Node.js/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/HackYourFuture/Node.js/pulls/249/commits"},"statuses":{"href":"https://api.github.com/repos/HackYourFuture/Node.js/statuses/98fb468908f145fdfd1978a5f72962c851dcb1ce"}},"author_association":"NONE"}}
{"actor":{"display_login":"J05J4"}}