{"action":"created","comment":{"url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/pulls/comments/64135132","id":64135132,"diff_hunk":"@@ -0,0 +1,80 @@\n+import logging\n+from datetime import datetime\n+\n+from marshmallow import ValidationError\n+from pyramid.httpexceptions import HTTPBadRequest, HTTPInternalServerError\n+from pyramid.view import view_defaults, view_config\n+\n+from smartgymapi.models import persist, commit, rollback, delete\n+from smartgymapi.lib.factories.cardio_acitivty import CardioActivityFactory, is_cardio_activity_active\n+from smartgymapi.lib.validation.cardio_activity import CardioActivitySchema\n+from smartgymapi.models.cardio_activity import CardioActivity\n+\n+log = logging.getLogger(__name__)\n+\n+\n+@view_defaults(containment=CardioActivityFactory,\n+               permission='public',\n+               renderer='json')\n+class RESTCardioActivty(object):\n+    def __init__(self, request):\n+        self.request = request\n+\n+    @view_config(context=CardioActivityFactory, request_method='GET')\n+    def list(self):\n+        try:\n+            activity_id = self.request.GET['activity_id']\n+            return CardioActivitySchema(many=True).dump(self.request.context.list_cardio_activities(activity_id)).data\n+        except KeyError as e:\n+            raise HTTPBadRequest(json={'message': 'Query parameter %s is needed' % e})\n+\n+    @view_config(context=CardioActivity, request_method='GET')\n+    def get(self):\n+        return CardioActivity().dump(self.request.context).data\n+\n+    @view_config(context=CardioActivityFactory, request_method='POST')\n+    def post(self):\n+        self.save(CardioActivity())\n+\n+    @view_config(context=CardioActivity, request_method='PUT')\n+    def put(self):\n+        cardio_activity = self.request.context\n+        if cardio_activity.end_date is None:\n+            cardio_activity.end_date = datetime.now()\n+        else:\n+            log.critical('Cardio activity is already ended')\n+            raise HTTPBadRequest\n+\n+        self.save(cardio_activity)\n+\n+    @view_config(context=CardioActivity, request_method='DELETE')\n+    def delete(self):\n+        try:\n+            delete(self.request.context)\n+        except:\n+            log.critical('Something went wrong deleting the cardio activity')\n+            rollback()\n+            raise HTTPInternalServerError\n+        finally:\n+            commit()\n+\n+    def save(self, cardio_activity):\n+        try:\n+            result, errors = CardioActivitySchema(strict=True).load(self.request.json_body)\n+        except ValidationError as e:\n+            raise HTTPBadRequest(json={'message': str(e)})\n+\n+        cardio_activity.set_fields(result)\n+\n+        if is_cardio_activity_active(cardio_activity.activity_id) and self.request.method == 'POST':","path":"smartgymapi/handlers/cardio_activity.py","position":69,"original_position":69,"commit_id":"d45b41d543522481a89550b70211a9252e6e65cb","original_commit_id":"d45b41d543522481a89550b70211a9252e6e65cb","user":{"login":"Melloww","id":5303534,"avatar_url":"https://avatars.githubusercontent.com/u/5303534?v=3","gravatar_id":"","url":"https://api.github.com/users/Melloww","html_url":"https://github.com/Melloww","followers_url":"https://api.github.com/users/Melloww/followers","following_url":"https://api.github.com/users/Melloww/following{/other_user}","gists_url":"https://api.github.com/users/Melloww/gists{/gist_id}","starred_url":"https://api.github.com/users/Melloww/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Melloww/subscriptions","organizations_url":"https://api.github.com/users/Melloww/orgs","repos_url":"https://api.github.com/users/Melloww/repos","events_url":"https://api.github.com/users/Melloww/events{/privacy}","received_events_url":"https://api.github.com/users/Melloww/received_events","type":"User","site_admin":false},"body":"This should be done in the POST handler.","created_at":"2016-05-21T14:15:27Z","updated_at":"2016-05-21T14:15:27Z","html_url":"https://github.com/NerdsWitAttitudes/Smart-Gym-API/pull/14#discussion_r64135132","pull_request_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/pulls/14","_links":{"self":{"href":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/pulls/comments/64135132"},"html":{"href":"https://github.com/NerdsWitAttitudes/Smart-Gym-API/pull/14#discussion_r64135132"},"pull_request":{"href":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/pulls/14"}}},"pull_request":{"url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/pulls/14","id":70943336,"html_url":"https://github.com/NerdsWitAttitudes/Smart-Gym-API/pull/14","diff_url":"https://github.com/NerdsWitAttitudes/Smart-Gym-API/pull/14.diff","patch_url":"https://github.com/NerdsWitAttitudes/Smart-Gym-API/pull/14.patch","issue_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/issues/14","number":14,"state":"open","locked":false,"title":"Cardio","user":{"login":"sanderdewinter","id":5989846,"avatar_url":"https://avatars.githubusercontent.com/u/5989846?v=3","gravatar_id":"","url":"https://api.github.com/users/sanderdewinter","html_url":"https://github.com/sanderdewinter","followers_url":"https://api.github.com/users/sanderdewinter/followers","following_url":"https://api.github.com/users/sanderdewinter/following{/other_user}","gists_url":"https://api.github.com/users/sanderdewinter/gists{/gist_id}","starred_url":"https://api.github.com/users/sanderdewinter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sanderdewinter/subscriptions","organizations_url":"https://api.github.com/users/sanderdewinter/orgs","repos_url":"https://api.github.com/users/sanderdewinter/repos","events_url":"https://api.github.com/users/sanderdewinter/events{/privacy}","received_events_url":"https://api.github.com/users/sanderdewinter/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-05-21T08:05:21Z","updated_at":"2016-05-21T14:15:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7360017e27e467c53f075ed830cb33dcc0d06eaa","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/pulls/14/commits","review_comments_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/pulls/14/comments","review_comment_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/pulls/comments{/number}","comments_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/issues/14/comments","statuses_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/statuses/d45b41d543522481a89550b70211a9252e6e65cb","head":{"label":"NerdsWitAttitudes:cardio","ref":"cardio","sha":"d45b41d543522481a89550b70211a9252e6e65cb","user":{"login":"NerdsWitAttitudes","id":17319344,"avatar_url":"https://avatars.githubusercontent.com/u/17319344?v=3","gravatar_id":"","url":"https://api.github.com/users/NerdsWitAttitudes","html_url":"https://github.com/NerdsWitAttitudes","followers_url":"https://api.github.com/users/NerdsWitAttitudes/followers","following_url":"https://api.github.com/users/NerdsWitAttitudes/following{/other_user}","gists_url":"https://api.github.com/users/NerdsWitAttitudes/gists{/gist_id}","starred_url":"https://api.github.com/users/NerdsWitAttitudes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NerdsWitAttitudes/subscriptions","organizations_url":"https://api.github.com/users/NerdsWitAttitudes/orgs","repos_url":"https://api.github.com/users/NerdsWitAttitudes/repos","events_url":"https://api.github.com/users/NerdsWitAttitudes/events{/privacy}","received_events_url":"https://api.github.com/users/NerdsWitAttitudes/received_events","type":"Organization","site_admin":false},"repo":{"id":54145397,"name":"Smart-Gym-API","full_name":"NerdsWitAttitudes/Smart-Gym-API","owner":{"login":"NerdsWitAttitudes","id":17319344,"avatar_url":"https://avatars.githubusercontent.com/u/17319344?v=3","gravatar_id":"","url":"https://api.github.com/users/NerdsWitAttitudes","html_url":"https://github.com/NerdsWitAttitudes","followers_url":"https://api.github.com/users/NerdsWitAttitudes/followers","following_url":"https://api.github.com/users/NerdsWitAttitudes/following{/other_user}","gists_url":"https://api.github.com/users/NerdsWitAttitudes/gists{/gist_id}","starred_url":"https://api.github.com/users/NerdsWitAttitudes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NerdsWitAttitudes/subscriptions","organizations_url":"https://api.github.com/users/NerdsWitAttitudes/orgs","repos_url":"https://api.github.com/users/NerdsWitAttitudes/repos","events_url":"https://api.github.com/users/NerdsWitAttitudes/events{/privacy}","received_events_url":"https://api.github.com/users/NerdsWitAttitudes/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/NerdsWitAttitudes/Smart-Gym-API","description":"REST API for the N.W.A Smart Gym","fork":false,"url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API","forks_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/forks","keys_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/teams","hooks_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/hooks","issue_events_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/issues/events{/number}","events_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/events","assignees_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/assignees{/user}","branches_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/branches{/branch}","tags_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/tags","blobs_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/git/refs{/sha}","trees_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/statuses/{sha}","languages_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/languages","stargazers_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/stargazers","contributors_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/contributors","subscribers_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/subscribers","subscription_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/subscription","commits_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/commits{/sha}","git_commits_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/git/commits{/sha}","comments_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/comments{/number}","issue_comment_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/issues/comments{/number}","contents_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/contents/{+path}","compare_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/merges","archive_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/downloads","issues_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/issues{/number}","pulls_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/pulls{/number}","milestones_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/milestones{/number}","notifications_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/labels{/name}","releases_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/releases{/id}","deployments_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/deployments","created_at":"2016-03-17T19:22:44Z","updated_at":"2016-05-17T08:01:36Z","pushed_at":"2016-05-21T08:05:21Z","git_url":"git://github.com/NerdsWitAttitudes/Smart-Gym-API.git","ssh_url":"git@github.com:NerdsWitAttitudes/Smart-Gym-API.git","clone_url":"https://github.com/NerdsWitAttitudes/Smart-Gym-API.git","svn_url":"https://github.com/NerdsWitAttitudes/Smart-Gym-API","homepage":null,"size":99,"stargazers_count":1,"watchers_count":1,"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":1,"default_branch":"develop"}},"base":{"label":"NerdsWitAttitudes:develop","ref":"develop","sha":"c0e39bd53047bdcd53622d25a6db939370601d0e","user":{"login":"NerdsWitAttitudes","id":17319344,"avatar_url":"https://avatars.githubusercontent.com/u/17319344?v=3","gravatar_id":"","url":"https://api.github.com/users/NerdsWitAttitudes","html_url":"https://github.com/NerdsWitAttitudes","followers_url":"https://api.github.com/users/NerdsWitAttitudes/followers","following_url":"https://api.github.com/users/NerdsWitAttitudes/following{/other_user}","gists_url":"https://api.github.com/users/NerdsWitAttitudes/gists{/gist_id}","starred_url":"https://api.github.com/users/NerdsWitAttitudes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NerdsWitAttitudes/subscriptions","organizations_url":"https://api.github.com/users/NerdsWitAttitudes/orgs","repos_url":"https://api.github.com/users/NerdsWitAttitudes/repos","events_url":"https://api.github.com/users/NerdsWitAttitudes/events{/privacy}","received_events_url":"https://api.github.com/users/NerdsWitAttitudes/received_events","type":"Organization","site_admin":false},"repo":{"id":54145397,"name":"Smart-Gym-API","full_name":"NerdsWitAttitudes/Smart-Gym-API","owner":{"login":"NerdsWitAttitudes","id":17319344,"avatar_url":"https://avatars.githubusercontent.com/u/17319344?v=3","gravatar_id":"","url":"https://api.github.com/users/NerdsWitAttitudes","html_url":"https://github.com/NerdsWitAttitudes","followers_url":"https://api.github.com/users/NerdsWitAttitudes/followers","following_url":"https://api.github.com/users/NerdsWitAttitudes/following{/other_user}","gists_url":"https://api.github.com/users/NerdsWitAttitudes/gists{/gist_id}","starred_url":"https://api.github.com/users/NerdsWitAttitudes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/NerdsWitAttitudes/subscriptions","organizations_url":"https://api.github.com/users/NerdsWitAttitudes/orgs","repos_url":"https://api.github.com/users/NerdsWitAttitudes/repos","events_url":"https://api.github.com/users/NerdsWitAttitudes/events{/privacy}","received_events_url":"https://api.github.com/users/NerdsWitAttitudes/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/NerdsWitAttitudes/Smart-Gym-API","description":"REST API for the N.W.A Smart Gym","fork":false,"url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API","forks_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/forks","keys_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/keys{/key_id}","collaborators_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/teams","hooks_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/hooks","issue_events_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/issues/events{/number}","events_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/events","assignees_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/assignees{/user}","branches_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/branches{/branch}","tags_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/tags","blobs_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/git/refs{/sha}","trees_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/git/trees{/sha}","statuses_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/statuses/{sha}","languages_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/languages","stargazers_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/stargazers","contributors_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/contributors","subscribers_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/subscribers","subscription_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/subscription","commits_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/commits{/sha}","git_commits_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/git/commits{/sha}","comments_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/comments{/number}","issue_comment_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/issues/comments{/number}","contents_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/contents/{+path}","compare_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/compare/{base}...{head}","merges_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/merges","archive_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/downloads","issues_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/issues{/number}","pulls_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/pulls{/number}","milestones_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/milestones{/number}","notifications_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/labels{/name}","releases_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/releases{/id}","deployments_url":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/deployments","created_at":"2016-03-17T19:22:44Z","updated_at":"2016-05-17T08:01:36Z","pushed_at":"2016-05-21T08:05:21Z","git_url":"git://github.com/NerdsWitAttitudes/Smart-Gym-API.git","ssh_url":"git@github.com:NerdsWitAttitudes/Smart-Gym-API.git","clone_url":"https://github.com/NerdsWitAttitudes/Smart-Gym-API.git","svn_url":"https://github.com/NerdsWitAttitudes/Smart-Gym-API","homepage":null,"size":99,"stargazers_count":1,"watchers_count":1,"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":1,"default_branch":"develop"}},"_links":{"self":{"href":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/pulls/14"},"html":{"href":"https://github.com/NerdsWitAttitudes/Smart-Gym-API/pull/14"},"issue":{"href":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/issues/14"},"comments":{"href":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/issues/14/comments"},"review_comments":{"href":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/pulls/14/comments"},"review_comment":{"href":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/pulls/14/commits"},"statuses":{"href":"https://api.github.com/repos/NerdsWitAttitudes/Smart-Gym-API/statuses/d45b41d543522481a89550b70211a9252e6e65cb"}}}}
{"actor":{"display_login":"Melloww"}}