{"action":"created","comment":{"url":"https://api.github.com/repos/xudongcamsys/homefoodie/pulls/comments/33913187","id":33913187,"diff_hunk":"@@ -44,6 +52,36 @@ def formatted_scheduled_time\n     scheduled_at.to_formatted_s(:long)\n   end\n \n+  def is_bookable_by?(applicant)\n+    applicant && is_future? && !is_booked_by?(applicant) && !is_participated_by?(applicant) && !is_full?\n+  end\n+\n+  def is_unbookable_by?(applicant)\n+    is_future? && is_booked_by?(applicant)\n+  end\n+\n+  def is_booked_by?(applicant)\n+    applicant && applicants.exists?(applicant.id)\n+  end\n+\n+  def booked_by!(applicant)\n+    Booking.create(event: self, applicant: applicant) if !is_booked_by?(applicant)\n+  end\n+\n+  # TODO: is it worth adding :counter_cache in UserEvent model?\n+  def is_full?\n+    capacity && capacity == participants.count\n+  end\n+\n+  def accept_booking!(booking)\n+    UserEvent.create(event: self, participant: booking.applicant)\n+    booking.destroy\n+  end\n+\n+  def is_future?\n+    scheduled_at > Time.zone.now\n+  end\n+","path":"app/models/event.rb","position":57,"original_position":57,"commit_id":"e0f2fe8faf7de4221d6030c8003c6e56892d8fad","original_commit_id":"e0f2fe8faf7de4221d6030c8003c6e56892d8fad","user":{"login":"eliotsykes","id":31698,"avatar_url":"https://avatars.githubusercontent.com/u/31698?v=3","gravatar_id":"","url":"https://api.github.com/users/eliotsykes","html_url":"https://github.com/eliotsykes","followers_url":"https://api.github.com/users/eliotsykes/followers","following_url":"https://api.github.com/users/eliotsykes/following{/other_user}","gists_url":"https://api.github.com/users/eliotsykes/gists{/gist_id}","starred_url":"https://api.github.com/users/eliotsykes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/eliotsykes/subscriptions","organizations_url":"https://api.github.com/users/eliotsykes/orgs","repos_url":"https://api.github.com/users/eliotsykes/repos","events_url":"https://api.github.com/users/eliotsykes/events{/privacy}","received_events_url":"https://api.github.com/users/eliotsykes/received_events","type":"User","site_admin":false},"body":"Excellent work here. The methods are broken down into good sizes and have very clear, understandable names. Following the logic through these methods was a delight.","created_at":"2015-07-06T08:13:49Z","updated_at":"2015-07-06T08:13:49Z","html_url":"https://github.com/xudongcamsys/homefoodie/pull/9#discussion_r33913187","pull_request_url":"https://api.github.com/repos/xudongcamsys/homefoodie/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/xudongcamsys/homefoodie/pulls/comments/33913187"},"html":{"href":"https://github.com/xudongcamsys/homefoodie/pull/9#discussion_r33913187"},"pull_request":{"href":"https://api.github.com/repos/xudongcamsys/homefoodie/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/xudongcamsys/homefoodie/pulls/9","id":39230860,"html_url":"https://github.com/xudongcamsys/homefoodie/pull/9","diff_url":"https://github.com/xudongcamsys/homefoodie/pull/9.diff","patch_url":"https://github.com/xudongcamsys/homefoodie/pull/9.patch","issue_url":"https://api.github.com/repos/xudongcamsys/homefoodie/issues/9","number":9,"state":"open","locked":false,"title":"Event booking&invite","user":{"login":"xudongcamsys","id":6162252,"avatar_url":"https://avatars.githubusercontent.com/u/6162252?v=3","gravatar_id":"","url":"https://api.github.com/users/xudongcamsys","html_url":"https://github.com/xudongcamsys","followers_url":"https://api.github.com/users/xudongcamsys/followers","following_url":"https://api.github.com/users/xudongcamsys/following{/other_user}","gists_url":"https://api.github.com/users/xudongcamsys/gists{/gist_id}","starred_url":"https://api.github.com/users/xudongcamsys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xudongcamsys/subscriptions","organizations_url":"https://api.github.com/users/xudongcamsys/orgs","repos_url":"https://api.github.com/users/xudongcamsys/repos","events_url":"https://api.github.com/users/xudongcamsys/events{/privacy}","received_events_url":"https://api.github.com/users/xudongcamsys/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-07-06T01:39:30Z","updated_at":"2015-07-06T08:13:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2b7e9340f08691cdaaf07dac094f0cc24a77ecc6","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/xudongcamsys/homefoodie/pulls/9/commits","review_comments_url":"https://api.github.com/repos/xudongcamsys/homefoodie/pulls/9/comments","review_comment_url":"https://api.github.com/repos/xudongcamsys/homefoodie/pulls/comments{/number}","comments_url":"https://api.github.com/repos/xudongcamsys/homefoodie/issues/9/comments","statuses_url":"https://api.github.com/repos/xudongcamsys/homefoodie/statuses/e0f2fe8faf7de4221d6030c8003c6e56892d8fad","head":{"label":"xudongcamsys:event-invite","ref":"event-invite","sha":"e0f2fe8faf7de4221d6030c8003c6e56892d8fad","user":{"login":"xudongcamsys","id":6162252,"avatar_url":"https://avatars.githubusercontent.com/u/6162252?v=3","gravatar_id":"","url":"https://api.github.com/users/xudongcamsys","html_url":"https://github.com/xudongcamsys","followers_url":"https://api.github.com/users/xudongcamsys/followers","following_url":"https://api.github.com/users/xudongcamsys/following{/other_user}","gists_url":"https://api.github.com/users/xudongcamsys/gists{/gist_id}","starred_url":"https://api.github.com/users/xudongcamsys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xudongcamsys/subscriptions","organizations_url":"https://api.github.com/users/xudongcamsys/orgs","repos_url":"https://api.github.com/users/xudongcamsys/repos","events_url":"https://api.github.com/users/xudongcamsys/events{/privacy}","received_events_url":"https://api.github.com/users/xudongcamsys/received_events","type":"User","site_admin":false},"repo":{"id":34533950,"name":"homefoodie","full_name":"xudongcamsys/homefoodie","owner":{"login":"xudongcamsys","id":6162252,"avatar_url":"https://avatars.githubusercontent.com/u/6162252?v=3","gravatar_id":"","url":"https://api.github.com/users/xudongcamsys","html_url":"https://github.com/xudongcamsys","followers_url":"https://api.github.com/users/xudongcamsys/followers","following_url":"https://api.github.com/users/xudongcamsys/following{/other_user}","gists_url":"https://api.github.com/users/xudongcamsys/gists{/gist_id}","starred_url":"https://api.github.com/users/xudongcamsys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xudongcamsys/subscriptions","organizations_url":"https://api.github.com/users/xudongcamsys/orgs","repos_url":"https://api.github.com/users/xudongcamsys/repos","events_url":"https://api.github.com/users/xudongcamsys/events{/privacy}","received_events_url":"https://api.github.com/users/xudongcamsys/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/xudongcamsys/homefoodie","description":"A social platform to explore and share home-made delicious food in your neighborhood","fork":false,"url":"https://api.github.com/repos/xudongcamsys/homefoodie","forks_url":"https://api.github.com/repos/xudongcamsys/homefoodie/forks","keys_url":"https://api.github.com/repos/xudongcamsys/homefoodie/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xudongcamsys/homefoodie/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xudongcamsys/homefoodie/teams","hooks_url":"https://api.github.com/repos/xudongcamsys/homefoodie/hooks","issue_events_url":"https://api.github.com/repos/xudongcamsys/homefoodie/issues/events{/number}","events_url":"https://api.github.com/repos/xudongcamsys/homefoodie/events","assignees_url":"https://api.github.com/repos/xudongcamsys/homefoodie/assignees{/user}","branches_url":"https://api.github.com/repos/xudongcamsys/homefoodie/branches{/branch}","tags_url":"https://api.github.com/repos/xudongcamsys/homefoodie/tags","blobs_url":"https://api.github.com/repos/xudongcamsys/homefoodie/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xudongcamsys/homefoodie/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xudongcamsys/homefoodie/git/refs{/sha}","trees_url":"https://api.github.com/repos/xudongcamsys/homefoodie/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xudongcamsys/homefoodie/statuses/{sha}","languages_url":"https://api.github.com/repos/xudongcamsys/homefoodie/languages","stargazers_url":"https://api.github.com/repos/xudongcamsys/homefoodie/stargazers","contributors_url":"https://api.github.com/repos/xudongcamsys/homefoodie/contributors","subscribers_url":"https://api.github.com/repos/xudongcamsys/homefoodie/subscribers","subscription_url":"https://api.github.com/repos/xudongcamsys/homefoodie/subscription","commits_url":"https://api.github.com/repos/xudongcamsys/homefoodie/commits{/sha}","git_commits_url":"https://api.github.com/repos/xudongcamsys/homefoodie/git/commits{/sha}","comments_url":"https://api.github.com/repos/xudongcamsys/homefoodie/comments{/number}","issue_comment_url":"https://api.github.com/repos/xudongcamsys/homefoodie/issues/comments{/number}","contents_url":"https://api.github.com/repos/xudongcamsys/homefoodie/contents/{+path}","compare_url":"https://api.github.com/repos/xudongcamsys/homefoodie/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xudongcamsys/homefoodie/merges","archive_url":"https://api.github.com/repos/xudongcamsys/homefoodie/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xudongcamsys/homefoodie/downloads","issues_url":"https://api.github.com/repos/xudongcamsys/homefoodie/issues{/number}","pulls_url":"https://api.github.com/repos/xudongcamsys/homefoodie/pulls{/number}","milestones_url":"https://api.github.com/repos/xudongcamsys/homefoodie/milestones{/number}","notifications_url":"https://api.github.com/repos/xudongcamsys/homefoodie/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xudongcamsys/homefoodie/labels{/name}","releases_url":"https://api.github.com/repos/xudongcamsys/homefoodie/releases{/id}","created_at":"2015-04-24T18:08:10Z","updated_at":"2015-05-28T19:28:08Z","pushed_at":"2015-07-06T01:41:11Z","git_url":"git://github.com/xudongcamsys/homefoodie.git","ssh_url":"git@github.com:xudongcamsys/homefoodie.git","clone_url":"https://github.com/xudongcamsys/homefoodie.git","svn_url":"https://github.com/xudongcamsys/homefoodie","homepage":"http://www.homefoodie.io","size":964,"stargazers_count":1,"watchers_count":1,"language":"Ruby","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":1,"default_branch":"master"}},"base":{"label":"xudongcamsys:develop","ref":"develop","sha":"190337297f8ad3be84bfb0dc6cdea8eabf7386d7","user":{"login":"xudongcamsys","id":6162252,"avatar_url":"https://avatars.githubusercontent.com/u/6162252?v=3","gravatar_id":"","url":"https://api.github.com/users/xudongcamsys","html_url":"https://github.com/xudongcamsys","followers_url":"https://api.github.com/users/xudongcamsys/followers","following_url":"https://api.github.com/users/xudongcamsys/following{/other_user}","gists_url":"https://api.github.com/users/xudongcamsys/gists{/gist_id}","starred_url":"https://api.github.com/users/xudongcamsys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xudongcamsys/subscriptions","organizations_url":"https://api.github.com/users/xudongcamsys/orgs","repos_url":"https://api.github.com/users/xudongcamsys/repos","events_url":"https://api.github.com/users/xudongcamsys/events{/privacy}","received_events_url":"https://api.github.com/users/xudongcamsys/received_events","type":"User","site_admin":false},"repo":{"id":34533950,"name":"homefoodie","full_name":"xudongcamsys/homefoodie","owner":{"login":"xudongcamsys","id":6162252,"avatar_url":"https://avatars.githubusercontent.com/u/6162252?v=3","gravatar_id":"","url":"https://api.github.com/users/xudongcamsys","html_url":"https://github.com/xudongcamsys","followers_url":"https://api.github.com/users/xudongcamsys/followers","following_url":"https://api.github.com/users/xudongcamsys/following{/other_user}","gists_url":"https://api.github.com/users/xudongcamsys/gists{/gist_id}","starred_url":"https://api.github.com/users/xudongcamsys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xudongcamsys/subscriptions","organizations_url":"https://api.github.com/users/xudongcamsys/orgs","repos_url":"https://api.github.com/users/xudongcamsys/repos","events_url":"https://api.github.com/users/xudongcamsys/events{/privacy}","received_events_url":"https://api.github.com/users/xudongcamsys/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/xudongcamsys/homefoodie","description":"A social platform to explore and share home-made delicious food in your neighborhood","fork":false,"url":"https://api.github.com/repos/xudongcamsys/homefoodie","forks_url":"https://api.github.com/repos/xudongcamsys/homefoodie/forks","keys_url":"https://api.github.com/repos/xudongcamsys/homefoodie/keys{/key_id}","collaborators_url":"https://api.github.com/repos/xudongcamsys/homefoodie/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/xudongcamsys/homefoodie/teams","hooks_url":"https://api.github.com/repos/xudongcamsys/homefoodie/hooks","issue_events_url":"https://api.github.com/repos/xudongcamsys/homefoodie/issues/events{/number}","events_url":"https://api.github.com/repos/xudongcamsys/homefoodie/events","assignees_url":"https://api.github.com/repos/xudongcamsys/homefoodie/assignees{/user}","branches_url":"https://api.github.com/repos/xudongcamsys/homefoodie/branches{/branch}","tags_url":"https://api.github.com/repos/xudongcamsys/homefoodie/tags","blobs_url":"https://api.github.com/repos/xudongcamsys/homefoodie/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/xudongcamsys/homefoodie/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/xudongcamsys/homefoodie/git/refs{/sha}","trees_url":"https://api.github.com/repos/xudongcamsys/homefoodie/git/trees{/sha}","statuses_url":"https://api.github.com/repos/xudongcamsys/homefoodie/statuses/{sha}","languages_url":"https://api.github.com/repos/xudongcamsys/homefoodie/languages","stargazers_url":"https://api.github.com/repos/xudongcamsys/homefoodie/stargazers","contributors_url":"https://api.github.com/repos/xudongcamsys/homefoodie/contributors","subscribers_url":"https://api.github.com/repos/xudongcamsys/homefoodie/subscribers","subscription_url":"https://api.github.com/repos/xudongcamsys/homefoodie/subscription","commits_url":"https://api.github.com/repos/xudongcamsys/homefoodie/commits{/sha}","git_commits_url":"https://api.github.com/repos/xudongcamsys/homefoodie/git/commits{/sha}","comments_url":"https://api.github.com/repos/xudongcamsys/homefoodie/comments{/number}","issue_comment_url":"https://api.github.com/repos/xudongcamsys/homefoodie/issues/comments{/number}","contents_url":"https://api.github.com/repos/xudongcamsys/homefoodie/contents/{+path}","compare_url":"https://api.github.com/repos/xudongcamsys/homefoodie/compare/{base}...{head}","merges_url":"https://api.github.com/repos/xudongcamsys/homefoodie/merges","archive_url":"https://api.github.com/repos/xudongcamsys/homefoodie/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/xudongcamsys/homefoodie/downloads","issues_url":"https://api.github.com/repos/xudongcamsys/homefoodie/issues{/number}","pulls_url":"https://api.github.com/repos/xudongcamsys/homefoodie/pulls{/number}","milestones_url":"https://api.github.com/repos/xudongcamsys/homefoodie/milestones{/number}","notifications_url":"https://api.github.com/repos/xudongcamsys/homefoodie/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/xudongcamsys/homefoodie/labels{/name}","releases_url":"https://api.github.com/repos/xudongcamsys/homefoodie/releases{/id}","created_at":"2015-04-24T18:08:10Z","updated_at":"2015-05-28T19:28:08Z","pushed_at":"2015-07-06T01:41:11Z","git_url":"git://github.com/xudongcamsys/homefoodie.git","ssh_url":"git@github.com:xudongcamsys/homefoodie.git","clone_url":"https://github.com/xudongcamsys/homefoodie.git","svn_url":"https://github.com/xudongcamsys/homefoodie","homepage":"http://www.homefoodie.io","size":964,"stargazers_count":1,"watchers_count":1,"language":"Ruby","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":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/xudongcamsys/homefoodie/pulls/9"},"html":{"href":"https://github.com/xudongcamsys/homefoodie/pull/9"},"issue":{"href":"https://api.github.com/repos/xudongcamsys/homefoodie/issues/9"},"comments":{"href":"https://api.github.com/repos/xudongcamsys/homefoodie/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/xudongcamsys/homefoodie/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/xudongcamsys/homefoodie/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/xudongcamsys/homefoodie/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/xudongcamsys/homefoodie/statuses/e0f2fe8faf7de4221d6030c8003c6e56892d8fad"}}}}