{"action":"created","comment":{"url":"https://api.github.com/repos/TimoRoots/TargetMVD/pulls/comments/237222811","pull_request_review_id":179469676,"id":237222811,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzNzIyMjgxMQ==","diff_hunk":"@@ -1,16 +1,38 @@\n class Target < ApplicationRecord\n   belongs_to :topic\n   belongs_to :user\n+  has_many :match_first, foreign_key: :target_first_id, class_name: 'Match', dependent: :destroy\n+  has_many :match_second, foreign_key: :target_second_id, class_name: 'Match', dependent: :destroy\n+\n   validate :targets_count_limit, :on => :create\n   validates :latitude, :longitude, :title, :area, :user_id, :topic_id, presence: true\n   validates :title, length: {minimum: 1, too_short: 'Minimum is %{count} characters'}\n   validates :area, numericality: {less_than: 1000, greater_than: 0}\n+  after_commit :search_and_create_matches, on: [:create]\n \n   def targets_count_limit\n-    puts self.user.target.size\n     if self.user.target.size >= 10\n       errors.add(:limit, \"Exceeded limit, Maximum is 10\")\n     end\n   end\n-  \n+\n+  def search_and_create_matches\n+    targets = Target.where.not(user_id: user.id)\n+    targets.each do |t|\n+      if self.topic_id == t.topic_id\n+        possible_new_target = Geokit::LatLng.new(self.latitude, self.longitude)\n+        dist = possible_new_target.distance_to(\"#{t.latitude},#{t.longitude}\")\n+        if dist <= self.area + t.area","path":"app/models/target.rb","position":27,"original_position":27,"commit_id":"30bbd5c9a96bfb027929066489e63af758f84d3c","original_commit_id":"30bbd5c9a96bfb027929066489e63af758f84d3c","user":{"login":"vitogit","id":5280619,"node_id":"MDQ6VXNlcjUyODA2MTk=","avatar_url":"https://avatars2.githubusercontent.com/u/5280619?v=4","gravatar_id":"","url":"https://api.github.com/users/vitogit","html_url":"https://github.com/vitogit","followers_url":"https://api.github.com/users/vitogit/followers","following_url":"https://api.github.com/users/vitogit/following{/other_user}","gists_url":"https://api.github.com/users/vitogit/gists{/gist_id}","starred_url":"https://api.github.com/users/vitogit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vitogit/subscriptions","organizations_url":"https://api.github.com/users/vitogit/orgs","repos_url":"https://api.github.com/users/vitogit/repos","events_url":"https://api.github.com/users/vitogit/events{/privacy}","received_events_url":"https://api.github.com/users/vitogit/received_events","type":"User","site_admin":false},"body":"https://github.com/geokit/geokit-rails has a `within` method that can reduce the code to find targets","created_at":"2018-11-28T19:13:30Z","updated_at":"2018-11-28T19:13:30Z","html_url":"https://github.com/TimoRoots/TargetMVD/pull/10#discussion_r237222811","pull_request_url":"https://api.github.com/repos/TimoRoots/TargetMVD/pulls/10","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/TimoRoots/TargetMVD/pulls/comments/237222811"},"html":{"href":"https://github.com/TimoRoots/TargetMVD/pull/10#discussion_r237222811"},"pull_request":{"href":"https://api.github.com/repos/TimoRoots/TargetMVD/pulls/10"}}},"pull_request":{"url":"https://api.github.com/repos/TimoRoots/TargetMVD/pulls/10","id":234041602,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM0MDQxNjAy","html_url":"https://github.com/TimoRoots/TargetMVD/pull/10","diff_url":"https://github.com/TimoRoots/TargetMVD/pull/10.diff","patch_url":"https://github.com/TimoRoots/TargetMVD/pull/10.patch","issue_url":"https://api.github.com/repos/TimoRoots/TargetMVD/issues/10","number":10,"state":"open","locked":false,"title":"Get matches","user":{"login":"TimoRoots","id":43894144,"node_id":"MDQ6VXNlcjQzODk0MTQ0","avatar_url":"https://avatars1.githubusercontent.com/u/43894144?v=4","gravatar_id":"","url":"https://api.github.com/users/TimoRoots","html_url":"https://github.com/TimoRoots","followers_url":"https://api.github.com/users/TimoRoots/followers","following_url":"https://api.github.com/users/TimoRoots/following{/other_user}","gists_url":"https://api.github.com/users/TimoRoots/gists{/gist_id}","starred_url":"https://api.github.com/users/TimoRoots/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimoRoots/subscriptions","organizations_url":"https://api.github.com/users/TimoRoots/orgs","repos_url":"https://api.github.com/users/TimoRoots/repos","events_url":"https://api.github.com/users/TimoRoots/events{/privacy}","received_events_url":"https://api.github.com/users/TimoRoots/received_events","type":"User","site_admin":false},"body":"https://trello.com/c/pCXLZIXi/11-3-as-a-user-i-should-be-able-to-see-all-my-compatible-targets-so-i-can-start-a-conversation-with-any-of-my-compatible-users\r\n\r\nAdd Match model,\r\nAdd Match controller,\r\nModify Target controller for support matches,\r\nModify Target model,\r\nAdd matches scss,\r\nAdd matches js,\r\nModify submit and display js,\r\nAdd Matches partial,\r\nModify Home partial,\r\nModify Target controller spec.\r\n","created_at":"2018-11-27T19:59:53Z","updated_at":"2018-11-28T19:13:30Z","closed_at":null,"merged_at":null,"merge_commit_sha":"dddc4bb10356360e9501e65010d1cbd9f8d11358","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/TimoRoots/TargetMVD/pulls/10/commits","review_comments_url":"https://api.github.com/repos/TimoRoots/TargetMVD/pulls/10/comments","review_comment_url":"https://api.github.com/repos/TimoRoots/TargetMVD/pulls/comments{/number}","comments_url":"https://api.github.com/repos/TimoRoots/TargetMVD/issues/10/comments","statuses_url":"https://api.github.com/repos/TimoRoots/TargetMVD/statuses/30bbd5c9a96bfb027929066489e63af758f84d3c","head":{"label":"TimoRoots:get-matches","ref":"get-matches","sha":"30bbd5c9a96bfb027929066489e63af758f84d3c","user":{"login":"TimoRoots","id":43894144,"node_id":"MDQ6VXNlcjQzODk0MTQ0","avatar_url":"https://avatars1.githubusercontent.com/u/43894144?v=4","gravatar_id":"","url":"https://api.github.com/users/TimoRoots","html_url":"https://github.com/TimoRoots","followers_url":"https://api.github.com/users/TimoRoots/followers","following_url":"https://api.github.com/users/TimoRoots/following{/other_user}","gists_url":"https://api.github.com/users/TimoRoots/gists{/gist_id}","starred_url":"https://api.github.com/users/TimoRoots/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimoRoots/subscriptions","organizations_url":"https://api.github.com/users/TimoRoots/orgs","repos_url":"https://api.github.com/users/TimoRoots/repos","events_url":"https://api.github.com/users/TimoRoots/events{/privacy}","received_events_url":"https://api.github.com/users/TimoRoots/received_events","type":"User","site_admin":false},"repo":{"id":154695405,"node_id":"MDEwOlJlcG9zaXRvcnkxNTQ2OTU0MDU=","name":"TargetMVD","full_name":"TimoRoots/TargetMVD","private":false,"owner":{"login":"TimoRoots","id":43894144,"node_id":"MDQ6VXNlcjQzODk0MTQ0","avatar_url":"https://avatars1.githubusercontent.com/u/43894144?v=4","gravatar_id":"","url":"https://api.github.com/users/TimoRoots","html_url":"https://github.com/TimoRoots","followers_url":"https://api.github.com/users/TimoRoots/followers","following_url":"https://api.github.com/users/TimoRoots/following{/other_user}","gists_url":"https://api.github.com/users/TimoRoots/gists{/gist_id}","starred_url":"https://api.github.com/users/TimoRoots/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimoRoots/subscriptions","organizations_url":"https://api.github.com/users/TimoRoots/orgs","repos_url":"https://api.github.com/users/TimoRoots/repos","events_url":"https://api.github.com/users/TimoRoots/events{/privacy}","received_events_url":"https://api.github.com/users/TimoRoots/received_events","type":"User","site_admin":false},"html_url":"https://github.com/TimoRoots/TargetMVD","description":null,"fork":false,"url":"https://api.github.com/repos/TimoRoots/TargetMVD","forks_url":"https://api.github.com/repos/TimoRoots/TargetMVD/forks","keys_url":"https://api.github.com/repos/TimoRoots/TargetMVD/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TimoRoots/TargetMVD/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TimoRoots/TargetMVD/teams","hooks_url":"https://api.github.com/repos/TimoRoots/TargetMVD/hooks","issue_events_url":"https://api.github.com/repos/TimoRoots/TargetMVD/issues/events{/number}","events_url":"https://api.github.com/repos/TimoRoots/TargetMVD/events","assignees_url":"https://api.github.com/repos/TimoRoots/TargetMVD/assignees{/user}","branches_url":"https://api.github.com/repos/TimoRoots/TargetMVD/branches{/branch}","tags_url":"https://api.github.com/repos/TimoRoots/TargetMVD/tags","blobs_url":"https://api.github.com/repos/TimoRoots/TargetMVD/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TimoRoots/TargetMVD/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TimoRoots/TargetMVD/git/refs{/sha}","trees_url":"https://api.github.com/repos/TimoRoots/TargetMVD/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TimoRoots/TargetMVD/statuses/{sha}","languages_url":"https://api.github.com/repos/TimoRoots/TargetMVD/languages","stargazers_url":"https://api.github.com/repos/TimoRoots/TargetMVD/stargazers","contributors_url":"https://api.github.com/repos/TimoRoots/TargetMVD/contributors","subscribers_url":"https://api.github.com/repos/TimoRoots/TargetMVD/subscribers","subscription_url":"https://api.github.com/repos/TimoRoots/TargetMVD/subscription","commits_url":"https://api.github.com/repos/TimoRoots/TargetMVD/commits{/sha}","git_commits_url":"https://api.github.com/repos/TimoRoots/TargetMVD/git/commits{/sha}","comments_url":"https://api.github.com/repos/TimoRoots/TargetMVD/comments{/number}","issue_comment_url":"https://api.github.com/repos/TimoRoots/TargetMVD/issues/comments{/number}","contents_url":"https://api.github.com/repos/TimoRoots/TargetMVD/contents/{+path}","compare_url":"https://api.github.com/repos/TimoRoots/TargetMVD/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TimoRoots/TargetMVD/merges","archive_url":"https://api.github.com/repos/TimoRoots/TargetMVD/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TimoRoots/TargetMVD/downloads","issues_url":"https://api.github.com/repos/TimoRoots/TargetMVD/issues{/number}","pulls_url":"https://api.github.com/repos/TimoRoots/TargetMVD/pulls{/number}","milestones_url":"https://api.github.com/repos/TimoRoots/TargetMVD/milestones{/number}","notifications_url":"https://api.github.com/repos/TimoRoots/TargetMVD/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TimoRoots/TargetMVD/labels{/name}","releases_url":"https://api.github.com/repos/TimoRoots/TargetMVD/releases{/id}","deployments_url":"https://api.github.com/repos/TimoRoots/TargetMVD/deployments","created_at":"2018-10-25T15:33:46Z","updated_at":"2018-11-21T17:24:14Z","pushed_at":"2018-11-28T18:47:13Z","git_url":"git://github.com/TimoRoots/TargetMVD.git","ssh_url":"git@github.com:TimoRoots/TargetMVD.git","clone_url":"https://github.com/TimoRoots/TargetMVD.git","svn_url":"https://github.com/TimoRoots/TargetMVD","homepage":null,"size":301,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"TimoRoots:master","ref":"master","sha":"05127a42075e447225aa1ac5b47b306b7bf29432","user":{"login":"TimoRoots","id":43894144,"node_id":"MDQ6VXNlcjQzODk0MTQ0","avatar_url":"https://avatars1.githubusercontent.com/u/43894144?v=4","gravatar_id":"","url":"https://api.github.com/users/TimoRoots","html_url":"https://github.com/TimoRoots","followers_url":"https://api.github.com/users/TimoRoots/followers","following_url":"https://api.github.com/users/TimoRoots/following{/other_user}","gists_url":"https://api.github.com/users/TimoRoots/gists{/gist_id}","starred_url":"https://api.github.com/users/TimoRoots/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimoRoots/subscriptions","organizations_url":"https://api.github.com/users/TimoRoots/orgs","repos_url":"https://api.github.com/users/TimoRoots/repos","events_url":"https://api.github.com/users/TimoRoots/events{/privacy}","received_events_url":"https://api.github.com/users/TimoRoots/received_events","type":"User","site_admin":false},"repo":{"id":154695405,"node_id":"MDEwOlJlcG9zaXRvcnkxNTQ2OTU0MDU=","name":"TargetMVD","full_name":"TimoRoots/TargetMVD","private":false,"owner":{"login":"TimoRoots","id":43894144,"node_id":"MDQ6VXNlcjQzODk0MTQ0","avatar_url":"https://avatars1.githubusercontent.com/u/43894144?v=4","gravatar_id":"","url":"https://api.github.com/users/TimoRoots","html_url":"https://github.com/TimoRoots","followers_url":"https://api.github.com/users/TimoRoots/followers","following_url":"https://api.github.com/users/TimoRoots/following{/other_user}","gists_url":"https://api.github.com/users/TimoRoots/gists{/gist_id}","starred_url":"https://api.github.com/users/TimoRoots/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TimoRoots/subscriptions","organizations_url":"https://api.github.com/users/TimoRoots/orgs","repos_url":"https://api.github.com/users/TimoRoots/repos","events_url":"https://api.github.com/users/TimoRoots/events{/privacy}","received_events_url":"https://api.github.com/users/TimoRoots/received_events","type":"User","site_admin":false},"html_url":"https://github.com/TimoRoots/TargetMVD","description":null,"fork":false,"url":"https://api.github.com/repos/TimoRoots/TargetMVD","forks_url":"https://api.github.com/repos/TimoRoots/TargetMVD/forks","keys_url":"https://api.github.com/repos/TimoRoots/TargetMVD/keys{/key_id}","collaborators_url":"https://api.github.com/repos/TimoRoots/TargetMVD/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/TimoRoots/TargetMVD/teams","hooks_url":"https://api.github.com/repos/TimoRoots/TargetMVD/hooks","issue_events_url":"https://api.github.com/repos/TimoRoots/TargetMVD/issues/events{/number}","events_url":"https://api.github.com/repos/TimoRoots/TargetMVD/events","assignees_url":"https://api.github.com/repos/TimoRoots/TargetMVD/assignees{/user}","branches_url":"https://api.github.com/repos/TimoRoots/TargetMVD/branches{/branch}","tags_url":"https://api.github.com/repos/TimoRoots/TargetMVD/tags","blobs_url":"https://api.github.com/repos/TimoRoots/TargetMVD/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/TimoRoots/TargetMVD/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/TimoRoots/TargetMVD/git/refs{/sha}","trees_url":"https://api.github.com/repos/TimoRoots/TargetMVD/git/trees{/sha}","statuses_url":"https://api.github.com/repos/TimoRoots/TargetMVD/statuses/{sha}","languages_url":"https://api.github.com/repos/TimoRoots/TargetMVD/languages","stargazers_url":"https://api.github.com/repos/TimoRoots/TargetMVD/stargazers","contributors_url":"https://api.github.com/repos/TimoRoots/TargetMVD/contributors","subscribers_url":"https://api.github.com/repos/TimoRoots/TargetMVD/subscribers","subscription_url":"https://api.github.com/repos/TimoRoots/TargetMVD/subscription","commits_url":"https://api.github.com/repos/TimoRoots/TargetMVD/commits{/sha}","git_commits_url":"https://api.github.com/repos/TimoRoots/TargetMVD/git/commits{/sha}","comments_url":"https://api.github.com/repos/TimoRoots/TargetMVD/comments{/number}","issue_comment_url":"https://api.github.com/repos/TimoRoots/TargetMVD/issues/comments{/number}","contents_url":"https://api.github.com/repos/TimoRoots/TargetMVD/contents/{+path}","compare_url":"https://api.github.com/repos/TimoRoots/TargetMVD/compare/{base}...{head}","merges_url":"https://api.github.com/repos/TimoRoots/TargetMVD/merges","archive_url":"https://api.github.com/repos/TimoRoots/TargetMVD/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/TimoRoots/TargetMVD/downloads","issues_url":"https://api.github.com/repos/TimoRoots/TargetMVD/issues{/number}","pulls_url":"https://api.github.com/repos/TimoRoots/TargetMVD/pulls{/number}","milestones_url":"https://api.github.com/repos/TimoRoots/TargetMVD/milestones{/number}","notifications_url":"https://api.github.com/repos/TimoRoots/TargetMVD/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/TimoRoots/TargetMVD/labels{/name}","releases_url":"https://api.github.com/repos/TimoRoots/TargetMVD/releases{/id}","deployments_url":"https://api.github.com/repos/TimoRoots/TargetMVD/deployments","created_at":"2018-10-25T15:33:46Z","updated_at":"2018-11-21T17:24:14Z","pushed_at":"2018-11-28T18:47:13Z","git_url":"git://github.com/TimoRoots/TargetMVD.git","ssh_url":"git@github.com:TimoRoots/TargetMVD.git","clone_url":"https://github.com/TimoRoots/TargetMVD.git","svn_url":"https://github.com/TimoRoots/TargetMVD","homepage":null,"size":301,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":null,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/TimoRoots/TargetMVD/pulls/10"},"html":{"href":"https://github.com/TimoRoots/TargetMVD/pull/10"},"issue":{"href":"https://api.github.com/repos/TimoRoots/TargetMVD/issues/10"},"comments":{"href":"https://api.github.com/repos/TimoRoots/TargetMVD/issues/10/comments"},"review_comments":{"href":"https://api.github.com/repos/TimoRoots/TargetMVD/pulls/10/comments"},"review_comment":{"href":"https://api.github.com/repos/TimoRoots/TargetMVD/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/TimoRoots/TargetMVD/pulls/10/commits"},"statuses":{"href":"https://api.github.com/repos/TimoRoots/TargetMVD/statuses/30bbd5c9a96bfb027929066489e63af758f84d3c"}},"author_association":"OWNER"}}
{"actor":{"display_login":"vitogit"}}