{"action":"created","comment":{"url":"https://api.github.com/repos/grofers/TODO-Application/pulls/comments/68729239","id":68729239,"diff_hunk":"@@ -9,108 +10,218 @@\n from .serializers import UserSerializer, ScheduleSerializer\n \n \n+def logged_in(request):\n+    if 'login' in request.session.keys():\n+        if request.session['login'] == \"Yes\":\n+            return True\n+    return False\n+\n+\n @api_view(['GET', 'POST'])\n-def list_users(request, format = None):\n+def list_users(request, format=None):\n     if request.method == 'GET':\n-        users = Users.objects.all().filter(verified=True)\n+        if not logged_in(request):\n+            return Response(status=status.HTTP_401_UNAUTHORIZED)\n+        users = Users.objects.all().filter(verified=True, deleted_flag=False)\n         serializer = UserSerializer(users, many=True)\n-        responses = serializer.data\n-        for response in responses:\n-            del response['password']\n-            del response['verified']\n-        return Response(responses)\n+        responses = {}\n+        try:\n+            responses['data'] = serializer.data\n+            responses['status'] = {'success': True,\n+                                   'message': \"Data Retrieved\"}\n+            for response in responses['data']:\n+                del response['password']\n+                del response['verified']\n+                del response['deleted_flag']\n+            return Response(responses)\n+        except:\n+            responses['status'] = {'success': False,\n+                                   'error': \"Data could not be retrieved\"}\n+            return Response(responses, status=status.HTTP_400_BAD_REQUEST)\n \n     elif request.method == 'POST':\n+        response = {}\n         data = JSONParser().parse(request)\n+        data['password'] = hashlib.sha1(data['password']).hexdigest()\n         serializer = UserSerializer(data=data)\n         if serializer.is_valid():\n             serializer.save()\n-            return Response(serializer.data, status=status.HTTP_201_CREATED)\n-        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)\n+            response['status'] = {'success': True,\n+                                  'error': \"Verification Mail Sent\"}\n+            return Response(response, status=status.HTTP_201_CREATED)\n+        response['status'] = {'success': False,\n+                              'message': \"Registration Failed\",\n+                              'error': serializer.errors}\n+        return Response(response, status=status.HTTP_400_BAD_REQUEST)\n \n \n @api_view(['GET', 'PUT', 'DELETE'])\n-def get_users(request, pk, format = None):\n+def get_users(request, pk, format=None):\n     try:\n-        user = Users.objects.get(pk=pk)\n+        user = Users.objects.get(pk=pk, deleted_flag=False)\n     except:\n         return Response(status=status.HTTP_404_NOT_FOUND)\n-    if request.method == 'GET':     \n+    if request.method == 'GET':\n+        if not logged_in(request):\n+            return Response(status=status.HTTP_401_UNAUTHORIZED)\n         serializer = UserSerializer(user)\n         response = serializer.data\n         del response['password']\n         del response['verified']\n+        del response['deleted_flag']\n         return Response(response)\n \n     elif request.method == 'PUT':\n+        response = {}\n         serializer = UserSerializer(user, data=request.data)\n         if serializer.is_valid():\n             serializer.save()\n-            return Response(serializer.data, status=status.HTTP_201_CREATED)\n-        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)\n+            response['status'] = {\"success\": True,\n+                                  \"message\": \"Registration Successful\"}\n+            return Response(response, status=status.HTTP_201_CREATED)\n+        response['status'] = {'success': False,\n+                              'message': \"Registration Failed\",\n+                              'error': serializer.errors}\n+        return Response(response, status=status.HTTP_400_BAD_REQUEST)\n \n     elif request.method == 'DELETE':\n-        user.delete()\n-        return Response(status=status.HTTP_204_NO_CONTENT)\n+        if not logged_in(request):\n+            return Response(status=status.HTTP_401_UNAUTHORIZED)\n+        serializer = UserSerializer(user)\n+        response = serializer.data\n+        response['deleted_flag'] = True\n+        res = {}\n+        serializer_delete = UserSerializer(user, data=response)\n+        if serializer_delete.is_valid():\n+            serializer_delete.save()\n+            res['status'] = {\"success\": True, \"message\": \"User Deleted\"}\n+            return Response(res, status=status.HTTP_204_NO_CONTENT)\n+        res['status'] = {'success': False,\n+                         'message': \"Registration Failed\",\n+                         'error': serializer.errors}\n+        return Response(res, status=status.HTTP_400_BAD_REQUEST)\n \n \n @api_view(['POST', 'GET'])\n-def schedule(request, format = None):\n-    print dict(request.session)\n+def schedule(request, format=None):\n+    if not logged_in(request):\n+        return Response(status=status.HTTP_401_UNAUTHORIZED)\n     if request.method == 'GET':\n+        response = {}\n         schedule = Schedule.objects.all()\n         serializer = ScheduleSerializer(schedule, many=True)\n         try:\n-            return Response(serializer.data)\n+            response['data'] = serializer.data\n+            for resp in response['data']:\n+                resp['user_id'] = resp.get('user').get('id')\n+                del resp['user']\n+                del resp['checked']\n+                del resp['id']\n+            response['status'] = {\"success\": True}\n+            return Response(response)\n         except:\n-            pass\n-        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)\n+            response['status'] = {'success': False,\n+                                  'message': \"Resource not available\"}\n+            return Response(response, status=status.HTTP_400_BAD_REQUEST)\n \n     elif request.method == 'POST':\n         data = JSONParser().parse(request)\n-        serializer = ScheduleSerializer(data=data)\n-        if serializer.is_valid():\n-            serializer.save()\n-            return Response(serializer.data, status=status.HTTP_201_CREATED)\n-        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)\n+        response = {}\n+        try:\n+            user = Users.objects.get(id=data['user_id'])\n+            schedule = Schedule(user=user, task=data['task'],\n+                                scheduled_time=data['scheduled_time'],\n+                                checked=True)\n+            schedule.save()\n+            response['status'] = {'success': True,\n+                                  'message': \"Schedule Entry Added\"}\n+            return Response(response, status=status.HTTP_201_CREATED)\n+        except:\n+            response['status'] = {'success': False,\n+                                  'message': \"Entry could not be added\",\n+                                  'error': \"Check for missing or Invalid Fields\"}\n+            return Response(response, status=status.HTTP_400_BAD_REQUEST)\n \n \n-@api_view(['POST', 'GET'])\n+@api_view(['POST'])\n def login(request):\n-    request.session['login'] = \"Yes\"\n-    return Response({}, status=status.HTTP_200_OK)\n+    if request.method == 'POST':\n+        email = request.data['email']\n+        password = request.data['password']\n+        password = hashlib.sha1(password).hexdigest()\n+        if Users.objects.filter(email=email, password=password).exists():\n+            user = Users.objects.get(email=email)","path":"schedule/views.py","position":153,"original_position":178,"commit_id":"25316888ddb592d2679465ce8a1a907695db5b69","original_commit_id":"25316888ddb592d2679465ce8a1a907695db5b69","user":{"login":"sourabhagarwal-grofers","id":15225999,"avatar_url":"https://avatars.githubusercontent.com/u/15225999?v=3","gravatar_id":"","url":"https://api.github.com/users/sourabhagarwal-grofers","html_url":"https://github.com/sourabhagarwal-grofers","followers_url":"https://api.github.com/users/sourabhagarwal-grofers/followers","following_url":"https://api.github.com/users/sourabhagarwal-grofers/following{/other_user}","gists_url":"https://api.github.com/users/sourabhagarwal-grofers/gists{/gist_id}","starred_url":"https://api.github.com/users/sourabhagarwal-grofers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sourabhagarwal-grofers/subscriptions","organizations_url":"https://api.github.com/users/sourabhagarwal-grofers/orgs","repos_url":"https://api.github.com/users/sourabhagarwal-grofers/repos","events_url":"https://api.github.com/users/sourabhagarwal-grofers/events{/privacy}","received_events_url":"https://api.github.com/users/sourabhagarwal-grofers/received_events","type":"User","site_admin":false},"body":"Why query twice?","created_at":"2016-06-28T09:58:00Z","updated_at":"2016-06-28T09:58:00Z","html_url":"https://github.com/grofers/TODO-Application/pull/1#discussion_r68729239","pull_request_url":"https://api.github.com/repos/grofers/TODO-Application/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/grofers/TODO-Application/pulls/comments/68729239"},"html":{"href":"https://github.com/grofers/TODO-Application/pull/1#discussion_r68729239"},"pull_request":{"href":"https://api.github.com/repos/grofers/TODO-Application/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/grofers/TODO-Application/pulls/1","id":74927291,"html_url":"https://github.com/grofers/TODO-Application/pull/1","diff_url":"https://github.com/grofers/TODO-Application/pull/1.diff","patch_url":"https://github.com/grofers/TODO-Application/pull/1.patch","issue_url":"https://api.github.com/repos/grofers/TODO-Application/issues/1","number":1,"state":"open","locked":false,"title":"APIs","user":{"login":"skthinks","id":19723655,"avatar_url":"https://avatars.githubusercontent.com/u/19723655?v=3","gravatar_id":"","url":"https://api.github.com/users/skthinks","html_url":"https://github.com/skthinks","followers_url":"https://api.github.com/users/skthinks/followers","following_url":"https://api.github.com/users/skthinks/following{/other_user}","gists_url":"https://api.github.com/users/skthinks/gists{/gist_id}","starred_url":"https://api.github.com/users/skthinks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/skthinks/subscriptions","organizations_url":"https://api.github.com/users/skthinks/orgs","repos_url":"https://api.github.com/users/skthinks/repos","events_url":"https://api.github.com/users/skthinks/events{/privacy}","received_events_url":"https://api.github.com/users/skthinks/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-06-23T10:01:17Z","updated_at":"2016-06-28T09:58:00Z","closed_at":null,"merged_at":null,"merge_commit_sha":"25ea42091c79db6de3b86b418fb0ff70a420f025","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/grofers/TODO-Application/pulls/1/commits","review_comments_url":"https://api.github.com/repos/grofers/TODO-Application/pulls/1/comments","review_comment_url":"https://api.github.com/repos/grofers/TODO-Application/pulls/comments{/number}","comments_url":"https://api.github.com/repos/grofers/TODO-Application/issues/1/comments","statuses_url":"https://api.github.com/repos/grofers/TODO-Application/statuses/25316888ddb592d2679465ce8a1a907695db5b69","head":{"label":"grofers:api","ref":"api","sha":"25316888ddb592d2679465ce8a1a907695db5b69","user":{"login":"grofers","id":8791674,"avatar_url":"https://avatars.githubusercontent.com/u/8791674?v=3","gravatar_id":"","url":"https://api.github.com/users/grofers","html_url":"https://github.com/grofers","followers_url":"https://api.github.com/users/grofers/followers","following_url":"https://api.github.com/users/grofers/following{/other_user}","gists_url":"https://api.github.com/users/grofers/gists{/gist_id}","starred_url":"https://api.github.com/users/grofers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grofers/subscriptions","organizations_url":"https://api.github.com/users/grofers/orgs","repos_url":"https://api.github.com/users/grofers/repos","events_url":"https://api.github.com/users/grofers/events{/privacy}","received_events_url":"https://api.github.com/users/grofers/received_events","type":"Organization","site_admin":false},"repo":{"id":61790101,"name":"TODO-Application","full_name":"grofers/TODO-Application","owner":{"login":"grofers","id":8791674,"avatar_url":"https://avatars.githubusercontent.com/u/8791674?v=3","gravatar_id":"","url":"https://api.github.com/users/grofers","html_url":"https://github.com/grofers","followers_url":"https://api.github.com/users/grofers/followers","following_url":"https://api.github.com/users/grofers/following{/other_user}","gists_url":"https://api.github.com/users/grofers/gists{/gist_id}","starred_url":"https://api.github.com/users/grofers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grofers/subscriptions","organizations_url":"https://api.github.com/users/grofers/orgs","repos_url":"https://api.github.com/users/grofers/repos","events_url":"https://api.github.com/users/grofers/events{/privacy}","received_events_url":"https://api.github.com/users/grofers/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/grofers/TODO-Application","description":"","fork":false,"url":"https://api.github.com/repos/grofers/TODO-Application","forks_url":"https://api.github.com/repos/grofers/TODO-Application/forks","keys_url":"https://api.github.com/repos/grofers/TODO-Application/keys{/key_id}","collaborators_url":"https://api.github.com/repos/grofers/TODO-Application/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/grofers/TODO-Application/teams","hooks_url":"https://api.github.com/repos/grofers/TODO-Application/hooks","issue_events_url":"https://api.github.com/repos/grofers/TODO-Application/issues/events{/number}","events_url":"https://api.github.com/repos/grofers/TODO-Application/events","assignees_url":"https://api.github.com/repos/grofers/TODO-Application/assignees{/user}","branches_url":"https://api.github.com/repos/grofers/TODO-Application/branches{/branch}","tags_url":"https://api.github.com/repos/grofers/TODO-Application/tags","blobs_url":"https://api.github.com/repos/grofers/TODO-Application/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/grofers/TODO-Application/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/grofers/TODO-Application/git/refs{/sha}","trees_url":"https://api.github.com/repos/grofers/TODO-Application/git/trees{/sha}","statuses_url":"https://api.github.com/repos/grofers/TODO-Application/statuses/{sha}","languages_url":"https://api.github.com/repos/grofers/TODO-Application/languages","stargazers_url":"https://api.github.com/repos/grofers/TODO-Application/stargazers","contributors_url":"https://api.github.com/repos/grofers/TODO-Application/contributors","subscribers_url":"https://api.github.com/repos/grofers/TODO-Application/subscribers","subscription_url":"https://api.github.com/repos/grofers/TODO-Application/subscription","commits_url":"https://api.github.com/repos/grofers/TODO-Application/commits{/sha}","git_commits_url":"https://api.github.com/repos/grofers/TODO-Application/git/commits{/sha}","comments_url":"https://api.github.com/repos/grofers/TODO-Application/comments{/number}","issue_comment_url":"https://api.github.com/repos/grofers/TODO-Application/issues/comments{/number}","contents_url":"https://api.github.com/repos/grofers/TODO-Application/contents/{+path}","compare_url":"https://api.github.com/repos/grofers/TODO-Application/compare/{base}...{head}","merges_url":"https://api.github.com/repos/grofers/TODO-Application/merges","archive_url":"https://api.github.com/repos/grofers/TODO-Application/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/grofers/TODO-Application/downloads","issues_url":"https://api.github.com/repos/grofers/TODO-Application/issues{/number}","pulls_url":"https://api.github.com/repos/grofers/TODO-Application/pulls{/number}","milestones_url":"https://api.github.com/repos/grofers/TODO-Application/milestones{/number}","notifications_url":"https://api.github.com/repos/grofers/TODO-Application/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/grofers/TODO-Application/labels{/name}","releases_url":"https://api.github.com/repos/grofers/TODO-Application/releases{/id}","deployments_url":"https://api.github.com/repos/grofers/TODO-Application/deployments","created_at":"2016-06-23T08:50:16Z","updated_at":"2016-06-23T08:50:16Z","pushed_at":"2016-06-27T11:35:24Z","git_url":"git://github.com/grofers/TODO-Application.git","ssh_url":"git@github.com:grofers/TODO-Application.git","clone_url":"https://github.com/grofers/TODO-Application.git","svn_url":"https://github.com/grofers/TODO-Application","homepage":null,"size":12,"stargazers_count":0,"watchers_count":0,"language":null,"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":"grofers:master","ref":"master","sha":"2a3b83578c71a2a4e86e54bb6ccf498952da74dc","user":{"login":"grofers","id":8791674,"avatar_url":"https://avatars.githubusercontent.com/u/8791674?v=3","gravatar_id":"","url":"https://api.github.com/users/grofers","html_url":"https://github.com/grofers","followers_url":"https://api.github.com/users/grofers/followers","following_url":"https://api.github.com/users/grofers/following{/other_user}","gists_url":"https://api.github.com/users/grofers/gists{/gist_id}","starred_url":"https://api.github.com/users/grofers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grofers/subscriptions","organizations_url":"https://api.github.com/users/grofers/orgs","repos_url":"https://api.github.com/users/grofers/repos","events_url":"https://api.github.com/users/grofers/events{/privacy}","received_events_url":"https://api.github.com/users/grofers/received_events","type":"Organization","site_admin":false},"repo":{"id":61790101,"name":"TODO-Application","full_name":"grofers/TODO-Application","owner":{"login":"grofers","id":8791674,"avatar_url":"https://avatars.githubusercontent.com/u/8791674?v=3","gravatar_id":"","url":"https://api.github.com/users/grofers","html_url":"https://github.com/grofers","followers_url":"https://api.github.com/users/grofers/followers","following_url":"https://api.github.com/users/grofers/following{/other_user}","gists_url":"https://api.github.com/users/grofers/gists{/gist_id}","starred_url":"https://api.github.com/users/grofers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/grofers/subscriptions","organizations_url":"https://api.github.com/users/grofers/orgs","repos_url":"https://api.github.com/users/grofers/repos","events_url":"https://api.github.com/users/grofers/events{/privacy}","received_events_url":"https://api.github.com/users/grofers/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/grofers/TODO-Application","description":"","fork":false,"url":"https://api.github.com/repos/grofers/TODO-Application","forks_url":"https://api.github.com/repos/grofers/TODO-Application/forks","keys_url":"https://api.github.com/repos/grofers/TODO-Application/keys{/key_id}","collaborators_url":"https://api.github.com/repos/grofers/TODO-Application/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/grofers/TODO-Application/teams","hooks_url":"https://api.github.com/repos/grofers/TODO-Application/hooks","issue_events_url":"https://api.github.com/repos/grofers/TODO-Application/issues/events{/number}","events_url":"https://api.github.com/repos/grofers/TODO-Application/events","assignees_url":"https://api.github.com/repos/grofers/TODO-Application/assignees{/user}","branches_url":"https://api.github.com/repos/grofers/TODO-Application/branches{/branch}","tags_url":"https://api.github.com/repos/grofers/TODO-Application/tags","blobs_url":"https://api.github.com/repos/grofers/TODO-Application/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/grofers/TODO-Application/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/grofers/TODO-Application/git/refs{/sha}","trees_url":"https://api.github.com/repos/grofers/TODO-Application/git/trees{/sha}","statuses_url":"https://api.github.com/repos/grofers/TODO-Application/statuses/{sha}","languages_url":"https://api.github.com/repos/grofers/TODO-Application/languages","stargazers_url":"https://api.github.com/repos/grofers/TODO-Application/stargazers","contributors_url":"https://api.github.com/repos/grofers/TODO-Application/contributors","subscribers_url":"https://api.github.com/repos/grofers/TODO-Application/subscribers","subscription_url":"https://api.github.com/repos/grofers/TODO-Application/subscription","commits_url":"https://api.github.com/repos/grofers/TODO-Application/commits{/sha}","git_commits_url":"https://api.github.com/repos/grofers/TODO-Application/git/commits{/sha}","comments_url":"https://api.github.com/repos/grofers/TODO-Application/comments{/number}","issue_comment_url":"https://api.github.com/repos/grofers/TODO-Application/issues/comments{/number}","contents_url":"https://api.github.com/repos/grofers/TODO-Application/contents/{+path}","compare_url":"https://api.github.com/repos/grofers/TODO-Application/compare/{base}...{head}","merges_url":"https://api.github.com/repos/grofers/TODO-Application/merges","archive_url":"https://api.github.com/repos/grofers/TODO-Application/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/grofers/TODO-Application/downloads","issues_url":"https://api.github.com/repos/grofers/TODO-Application/issues{/number}","pulls_url":"https://api.github.com/repos/grofers/TODO-Application/pulls{/number}","milestones_url":"https://api.github.com/repos/grofers/TODO-Application/milestones{/number}","notifications_url":"https://api.github.com/repos/grofers/TODO-Application/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/grofers/TODO-Application/labels{/name}","releases_url":"https://api.github.com/repos/grofers/TODO-Application/releases{/id}","deployments_url":"https://api.github.com/repos/grofers/TODO-Application/deployments","created_at":"2016-06-23T08:50:16Z","updated_at":"2016-06-23T08:50:16Z","pushed_at":"2016-06-27T11:35:24Z","git_url":"git://github.com/grofers/TODO-Application.git","ssh_url":"git@github.com:grofers/TODO-Application.git","clone_url":"https://github.com/grofers/TODO-Application.git","svn_url":"https://github.com/grofers/TODO-Application","homepage":null,"size":12,"stargazers_count":0,"watchers_count":0,"language":null,"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/grofers/TODO-Application/pulls/1"},"html":{"href":"https://github.com/grofers/TODO-Application/pull/1"},"issue":{"href":"https://api.github.com/repos/grofers/TODO-Application/issues/1"},"comments":{"href":"https://api.github.com/repos/grofers/TODO-Application/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/grofers/TODO-Application/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/grofers/TODO-Application/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/grofers/TODO-Application/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/grofers/TODO-Application/statuses/25316888ddb592d2679465ce8a1a907695db5b69"}}}}
{"actor":{"display_login":"sourabhagarwal-grofers"}}