{"action":"created","comment":{"url":"https://api.github.com/repos/NdagiStanley/bucketlist/pulls/comments/57164761","id":57164761,"diff_hunk":"@@ -0,0 +1,115 @@\n+# bucketlist/models.py\n+\n+\n+from flask import Flask, g\n+from flask.ext.sqlalchemy import SQLAlchemy\n+\n+from passlib.apps import custom_app_context as pwd_context\n+from itsdangerous import (TimedJSONWebSignatureSerializer\n+                          as Serializer, BadSignature, SignatureExpired)\n+from flask.ext.httpauth import HTTPBasicAuth\n+\n+auth = HTTPBasicAuth()\n+\n+# Initialise Flask\n+app = Flask(__name__)\n+\n+db = SQLAlchemy(app)\n+\n+class User(db.Model):\n+    \"\"\"User model\"\"\"\n+    id = db.Column(db.Integer, primary_key=True)\n+    username = db.Column(db.String(20), unique=True)\n+    password = db.Column(db.String(128))\n+\n+    def hash_password(self, password):\n+        \"\"\"Hash the password to be saved in db\"\"\"\n+        return pwd_context.encrypt(password)\n+\n+    def verify_password(self, password):\n+        return pwd_context.verify(password, self.password)\n+\n+    def generate_auth_token(self, expiration = 3600):\n+        s = Serializer(app.config['SECRET_KEY'], expires_in = expiration)\n+        return s.dumps({ 'id': self.id })\n+\n+    @staticmethod\n+    def verify_auth_token(token):\n+        s = Serializer(app.config['SECRET_KEY'])\n+        try:\n+            data = s.loads(token)\n+        except SignatureExpired:\n+            return None # valid token, but expired\n+        except BadSignature:\n+            return None # invalid token\n+        user = User.query.get(data['id'])\n+        return user\n+\n+    #  Constructor for User\n+    def __init__(self, username, password):\n+        self.username = username\n+        self.password = self.hash_password(password)\n+\n+    def __repr__(self):\n+        return '<User {0}>'.format(self.username)\n+\n+\n+class Bucketlist(db.Model):\n+    \"\"\"Model for Bucketlist\"\"\"\n+    id = db.Column(db.Integer, primary_key=True)\n+    name = db.Column(db.String(20), unique=True)\n+    date_created = db.Column(db.DateTime,\n+                             default=db.func.current_timestamp())\n+    date_modified = db.Column(db.DateTime,\n+                              default=db.func.current_timestamp())\n+    created_by = db.Column(db.String(20))","path":"api/app/models.py","position":65,"original_position":65,"commit_id":"8f361687e9d99ee98cb7508504dc599d614d5ac9","original_commit_id":"8f361687e9d99ee98cb7508504dc599d614d5ac9","user":{"login":"andela-cnnadi","id":3100850,"avatar_url":"https://avatars.githubusercontent.com/u/3100850?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-cnnadi","html_url":"https://github.com/andela-cnnadi","followers_url":"https://api.github.com/users/andela-cnnadi/followers","following_url":"https://api.github.com/users/andela-cnnadi/following{/other_user}","gists_url":"https://api.github.com/users/andela-cnnadi/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-cnnadi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-cnnadi/subscriptions","organizations_url":"https://api.github.com/users/andela-cnnadi/orgs","repos_url":"https://api.github.com/users/andela-cnnadi/repos","events_url":"https://api.github.com/users/andela-cnnadi/events{/privacy}","received_events_url":"https://api.github.com/users/andela-cnnadi/received_events","type":"User","site_admin":false},"body":"**Code Quality: Critical**\r\n\r\nThis should be a foreign key field linked to the user model","created_at":"2016-03-23T14:11:01Z","updated_at":"2016-03-23T14:11:01Z","html_url":"https://github.com/NdagiStanley/bucketlist/pull/9#discussion_r57164761","pull_request_url":"https://api.github.com/repos/NdagiStanley/bucketlist/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/NdagiStanley/bucketlist/pulls/comments/57164761"},"html":{"href":"https://github.com/NdagiStanley/bucketlist/pull/9#discussion_r57164761"},"pull_request":{"href":"https://api.github.com/repos/NdagiStanley/bucketlist/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/NdagiStanley/bucketlist/pulls/9","id":63526785,"html_url":"https://github.com/NdagiStanley/bucketlist/pull/9","diff_url":"https://github.com/NdagiStanley/bucketlist/pull/9.diff","patch_url":"https://github.com/NdagiStanley/bucketlist/pull/9.patch","issue_url":"https://api.github.com/repos/NdagiStanley/bucketlist/issues/9","number":9,"state":"open","locked":false,"title":"Checkpoint 2","user":{"login":"NdagiStanley","id":15629602,"avatar_url":"https://avatars.githubusercontent.com/u/15629602?v=3","gravatar_id":"","url":"https://api.github.com/users/NdagiStanley","html_url":"https://github.com/NdagiStanley","followers_url":"https://api.github.com/users/NdagiStanley/followers","following_url":"https://api.github.com/users/NdagiStanley/following{/other_user}","gists_url":"https://api.github.com/users/NdagiStanley/gists{/gist_id}","starred_url":"https://api.github.com/users/NdagiStanley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NdagiStanley/subscriptions","organizations_url":"https://api.github.com/users/NdagiStanley/orgs","repos_url":"https://api.github.com/users/NdagiStanley/repos","events_url":"https://api.github.com/users/NdagiStanley/events{/privacy}","received_events_url":"https://api.github.com/users/NdagiStanley/received_events","type":"User","site_admin":false},"body":"#### What does this PR do?\r\nConfirms that the checkpoint is complete plus:\r\n- Code functionality\r\n- TDD is implemented (minimum of 70%)\r\n- Readme file with Badges and Images\r\n- Organised File structure\r\n\r\n#### Description of Task to be completed?\r\n**Four tasks**\r\nTask 0 - Create API\r\nTask 1 - Implement Token Based Authentication\r\nTask 2 - Implement Pagination on your API\r\nTask 3 - Implement Searching by name\r\n\r\n#### How should this be manually tested?\r\nThe [README](https://github.com/NdagiStanley/bucketlist/blob/feature-review/README.md) is quite detailed in this.\r\n\r\n#### Any background context you want to provide?\r\nI stuck to the file? folder structure that had given me most milage. You'll note that app and db initialization is done in \"api/models.py\"\r\n\r\n#### Screenshots\r\n_One of the endpoints_\r\n<img width=\"1659\" alt=\"screenshot 2016-03-18 20 29 13\" src=\"https://cloud.githubusercontent.com/assets/15629602/13911943/8c373e0c-ef48-11e5-918f-c58b47928c86.png\">\r\n_PAGINATION_\r\n_set limit_\r\n<img width=\"1670\" alt=\"screenshot 2016-03-21 09 43 55\" src=\"https://cloud.githubusercontent.com/assets/15629602/13912027/8b875644-ef49-11e5-9222-f990c5e89cc1.png\">\r\n_limit that is more than 100 is set to 100 automatically_\r\n<img width=\"1666\" alt=\"screenshot 2016-03-21 09 43 32\" src=\"https://cloud.githubusercontent.com/assets/15629602/13912026/8b75e80a-ef49-11e5-8668-e97f39951656.png\">\r\n_SEARCH_\r\n_positive results_\r\n<img width=\"1665\" alt=\"screenshot 2016-03-18 20 30 34\" src=\"https://cloud.githubusercontent.com/assets/15629602/13911944/8c4a7698-ef48-11e5-9134-2fd078dd2553.png\">\r\n_negative results_\r\n<img width=\"1661\" alt=\"screenshot 2016-03-18 20 30 52\" src=\"https://cloud.githubusercontent.com/assets/15629602/13911945/8c4c1c96-ef48-11e5-8b7d-5bbc1ca09794.png\">","created_at":"2016-03-21T06:54:26Z","updated_at":"2016-03-23T14:11:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"acaa342a388bf116806e8e84989b41906ad6ea6c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/NdagiStanley/bucketlist/pulls/9/commits","review_comments_url":"https://api.github.com/repos/NdagiStanley/bucketlist/pulls/9/comments","review_comment_url":"https://api.github.com/repos/NdagiStanley/bucketlist/pulls/comments{/number}","comments_url":"https://api.github.com/repos/NdagiStanley/bucketlist/issues/9/comments","statuses_url":"https://api.github.com/repos/NdagiStanley/bucketlist/statuses/8f361687e9d99ee98cb7508504dc599d614d5ac9","head":{"label":"NdagiStanley:feature-review","ref":"feature-review","sha":"8f361687e9d99ee98cb7508504dc599d614d5ac9","user":{"login":"NdagiStanley","id":15629602,"avatar_url":"https://avatars.githubusercontent.com/u/15629602?v=3","gravatar_id":"","url":"https://api.github.com/users/NdagiStanley","html_url":"https://github.com/NdagiStanley","followers_url":"https://api.github.com/users/NdagiStanley/followers","following_url":"https://api.github.com/users/NdagiStanley/following{/other_user}","gists_url":"https://api.github.com/users/NdagiStanley/gists{/gist_id}","starred_url":"https://api.github.com/users/NdagiStanley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NdagiStanley/subscriptions","organizations_url":"https://api.github.com/users/NdagiStanley/orgs","repos_url":"https://api.github.com/users/NdagiStanley/repos","events_url":"https://api.github.com/users/NdagiStanley/events{/privacy}","received_events_url":"https://api.github.com/users/NdagiStanley/received_events","type":"User","site_admin":false},"repo":{"id":50042193,"name":"bucketlist","full_name":"NdagiStanley/bucketlist","owner":{"login":"NdagiStanley","id":15629602,"avatar_url":"https://avatars.githubusercontent.com/u/15629602?v=3","gravatar_id":"","url":"https://api.github.com/users/NdagiStanley","html_url":"https://github.com/NdagiStanley","followers_url":"https://api.github.com/users/NdagiStanley/followers","following_url":"https://api.github.com/users/NdagiStanley/following{/other_user}","gists_url":"https://api.github.com/users/NdagiStanley/gists{/gist_id}","starred_url":"https://api.github.com/users/NdagiStanley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NdagiStanley/subscriptions","organizations_url":"https://api.github.com/users/NdagiStanley/orgs","repos_url":"https://api.github.com/users/NdagiStanley/repos","events_url":"https://api.github.com/users/NdagiStanley/events{/privacy}","received_events_url":"https://api.github.com/users/NdagiStanley/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/NdagiStanley/bucketlist","description":"Checkpoint 2 Python","fork":false,"url":"https://api.github.com/repos/NdagiStanley/bucketlist","forks_url":"https://api.github.com/repos/NdagiStanley/bucketlist/forks","keys_url":"https://api.github.com/repos/NdagiStanley/bucketlist/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NdagiStanley/bucketlist/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NdagiStanley/bucketlist/teams","hooks_url":"https://api.github.com/repos/NdagiStanley/bucketlist/hooks","issue_events_url":"https://api.github.com/repos/NdagiStanley/bucketlist/issues/events{/number}","events_url":"https://api.github.com/repos/NdagiStanley/bucketlist/events","assignees_url":"https://api.github.com/repos/NdagiStanley/bucketlist/assignees{/user}","branches_url":"https://api.github.com/repos/NdagiStanley/bucketlist/branches{/branch}","tags_url":"https://api.github.com/repos/NdagiStanley/bucketlist/tags","blobs_url":"https://api.github.com/repos/NdagiStanley/bucketlist/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NdagiStanley/bucketlist/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NdagiStanley/bucketlist/git/refs{/sha}","trees_url":"https://api.github.com/repos/NdagiStanley/bucketlist/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NdagiStanley/bucketlist/statuses/{sha}","languages_url":"https://api.github.com/repos/NdagiStanley/bucketlist/languages","stargazers_url":"https://api.github.com/repos/NdagiStanley/bucketlist/stargazers","contributors_url":"https://api.github.com/repos/NdagiStanley/bucketlist/contributors","subscribers_url":"https://api.github.com/repos/NdagiStanley/bucketlist/subscribers","subscription_url":"https://api.github.com/repos/NdagiStanley/bucketlist/subscription","commits_url":"https://api.github.com/repos/NdagiStanley/bucketlist/commits{/sha}","git_commits_url":"https://api.github.com/repos/NdagiStanley/bucketlist/git/commits{/sha}","comments_url":"https://api.github.com/repos/NdagiStanley/bucketlist/comments{/number}","issue_comment_url":"https://api.github.com/repos/NdagiStanley/bucketlist/issues/comments{/number}","contents_url":"https://api.github.com/repos/NdagiStanley/bucketlist/contents/{+path}","compare_url":"https://api.github.com/repos/NdagiStanley/bucketlist/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NdagiStanley/bucketlist/merges","archive_url":"https://api.github.com/repos/NdagiStanley/bucketlist/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NdagiStanley/bucketlist/downloads","issues_url":"https://api.github.com/repos/NdagiStanley/bucketlist/issues{/number}","pulls_url":"https://api.github.com/repos/NdagiStanley/bucketlist/pulls{/number}","milestones_url":"https://api.github.com/repos/NdagiStanley/bucketlist/milestones{/number}","notifications_url":"https://api.github.com/repos/NdagiStanley/bucketlist/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NdagiStanley/bucketlist/labels{/name}","releases_url":"https://api.github.com/repos/NdagiStanley/bucketlist/releases{/id}","deployments_url":"https://api.github.com/repos/NdagiStanley/bucketlist/deployments","created_at":"2016-01-20T16:13:38Z","updated_at":"2016-02-25T09:56:39Z","pushed_at":"2016-03-21T07:15:58Z","git_url":"git://github.com/NdagiStanley/bucketlist.git","ssh_url":"git@github.com:NdagiStanley/bucketlist.git","clone_url":"https://github.com/NdagiStanley/bucketlist.git","svn_url":"https://github.com/NdagiStanley/bucketlist","homepage":null,"size":137,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"feature-review"}},"base":{"label":"NdagiStanley:master","ref":"master","sha":"58967eb21417564c0509aee8a66b6bb8dfcf31f3","user":{"login":"NdagiStanley","id":15629602,"avatar_url":"https://avatars.githubusercontent.com/u/15629602?v=3","gravatar_id":"","url":"https://api.github.com/users/NdagiStanley","html_url":"https://github.com/NdagiStanley","followers_url":"https://api.github.com/users/NdagiStanley/followers","following_url":"https://api.github.com/users/NdagiStanley/following{/other_user}","gists_url":"https://api.github.com/users/NdagiStanley/gists{/gist_id}","starred_url":"https://api.github.com/users/NdagiStanley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NdagiStanley/subscriptions","organizations_url":"https://api.github.com/users/NdagiStanley/orgs","repos_url":"https://api.github.com/users/NdagiStanley/repos","events_url":"https://api.github.com/users/NdagiStanley/events{/privacy}","received_events_url":"https://api.github.com/users/NdagiStanley/received_events","type":"User","site_admin":false},"repo":{"id":50042193,"name":"bucketlist","full_name":"NdagiStanley/bucketlist","owner":{"login":"NdagiStanley","id":15629602,"avatar_url":"https://avatars.githubusercontent.com/u/15629602?v=3","gravatar_id":"","url":"https://api.github.com/users/NdagiStanley","html_url":"https://github.com/NdagiStanley","followers_url":"https://api.github.com/users/NdagiStanley/followers","following_url":"https://api.github.com/users/NdagiStanley/following{/other_user}","gists_url":"https://api.github.com/users/NdagiStanley/gists{/gist_id}","starred_url":"https://api.github.com/users/NdagiStanley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NdagiStanley/subscriptions","organizations_url":"https://api.github.com/users/NdagiStanley/orgs","repos_url":"https://api.github.com/users/NdagiStanley/repos","events_url":"https://api.github.com/users/NdagiStanley/events{/privacy}","received_events_url":"https://api.github.com/users/NdagiStanley/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/NdagiStanley/bucketlist","description":"Checkpoint 2 Python","fork":false,"url":"https://api.github.com/repos/NdagiStanley/bucketlist","forks_url":"https://api.github.com/repos/NdagiStanley/bucketlist/forks","keys_url":"https://api.github.com/repos/NdagiStanley/bucketlist/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NdagiStanley/bucketlist/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NdagiStanley/bucketlist/teams","hooks_url":"https://api.github.com/repos/NdagiStanley/bucketlist/hooks","issue_events_url":"https://api.github.com/repos/NdagiStanley/bucketlist/issues/events{/number}","events_url":"https://api.github.com/repos/NdagiStanley/bucketlist/events","assignees_url":"https://api.github.com/repos/NdagiStanley/bucketlist/assignees{/user}","branches_url":"https://api.github.com/repos/NdagiStanley/bucketlist/branches{/branch}","tags_url":"https://api.github.com/repos/NdagiStanley/bucketlist/tags","blobs_url":"https://api.github.com/repos/NdagiStanley/bucketlist/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NdagiStanley/bucketlist/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NdagiStanley/bucketlist/git/refs{/sha}","trees_url":"https://api.github.com/repos/NdagiStanley/bucketlist/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NdagiStanley/bucketlist/statuses/{sha}","languages_url":"https://api.github.com/repos/NdagiStanley/bucketlist/languages","stargazers_url":"https://api.github.com/repos/NdagiStanley/bucketlist/stargazers","contributors_url":"https://api.github.com/repos/NdagiStanley/bucketlist/contributors","subscribers_url":"https://api.github.com/repos/NdagiStanley/bucketlist/subscribers","subscription_url":"https://api.github.com/repos/NdagiStanley/bucketlist/subscription","commits_url":"https://api.github.com/repos/NdagiStanley/bucketlist/commits{/sha}","git_commits_url":"https://api.github.com/repos/NdagiStanley/bucketlist/git/commits{/sha}","comments_url":"https://api.github.com/repos/NdagiStanley/bucketlist/comments{/number}","issue_comment_url":"https://api.github.com/repos/NdagiStanley/bucketlist/issues/comments{/number}","contents_url":"https://api.github.com/repos/NdagiStanley/bucketlist/contents/{+path}","compare_url":"https://api.github.com/repos/NdagiStanley/bucketlist/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NdagiStanley/bucketlist/merges","archive_url":"https://api.github.com/repos/NdagiStanley/bucketlist/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NdagiStanley/bucketlist/downloads","issues_url":"https://api.github.com/repos/NdagiStanley/bucketlist/issues{/number}","pulls_url":"https://api.github.com/repos/NdagiStanley/bucketlist/pulls{/number}","milestones_url":"https://api.github.com/repos/NdagiStanley/bucketlist/milestones{/number}","notifications_url":"https://api.github.com/repos/NdagiStanley/bucketlist/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NdagiStanley/bucketlist/labels{/name}","releases_url":"https://api.github.com/repos/NdagiStanley/bucketlist/releases{/id}","deployments_url":"https://api.github.com/repos/NdagiStanley/bucketlist/deployments","created_at":"2016-01-20T16:13:38Z","updated_at":"2016-02-25T09:56:39Z","pushed_at":"2016-03-21T07:15:58Z","git_url":"git://github.com/NdagiStanley/bucketlist.git","ssh_url":"git@github.com:NdagiStanley/bucketlist.git","clone_url":"https://github.com/NdagiStanley/bucketlist.git","svn_url":"https://github.com/NdagiStanley/bucketlist","homepage":null,"size":137,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":2,"forks":1,"open_issues":2,"watchers":0,"default_branch":"feature-review"}},"_links":{"self":{"href":"https://api.github.com/repos/NdagiStanley/bucketlist/pulls/9"},"html":{"href":"https://github.com/NdagiStanley/bucketlist/pull/9"},"issue":{"href":"https://api.github.com/repos/NdagiStanley/bucketlist/issues/9"},"comments":{"href":"https://api.github.com/repos/NdagiStanley/bucketlist/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/NdagiStanley/bucketlist/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/NdagiStanley/bucketlist/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/NdagiStanley/bucketlist/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/NdagiStanley/bucketlist/statuses/8f361687e9d99ee98cb7508504dc599d614d5ac9"}}}}