{"action":"created","comment":{"url":"https://api.github.com/repos/finagle/finch/pulls/comments/34933202","id":34933202,"diff_hunk":"@@ -0,0 +1,238 @@\n+package io.finch.petstore\n+\n+import com.twitter.finagle.Service\n+import com.twitter.finagle.httpx.{Request, Response}\n+import com.twitter.util.{Future}\n+import io.finch.argonaut._\n+import io.finch.request._\n+import io.finch.response._\n+import io.finch.route._\n+\n+/**\n+ * Provides the paths and endpoints for all the API's public service methods.\n+ */\n+object endpoint extends ErrorHandling {\n+\n+  /**\n+   * Private method that compiles all pet service endpoints.\n+   * @return Bundled compilation of all pet service endpoints.\n+   */\n+  private def petEndpts(db: PetstoreDb) =\n+    getPetEndpt(db) :+:\n+    addPetEndpt(db) :+:\n+    updatePetEndpt(db) :+:\n+    getPetsByStatusEndpt(db) :+:\n+    findPetsByTagEndpt(db) :+:\n+    deletePetEndpt(db) :+:\n+    updatePetViaFormEndpt(db) :+:\n+    uploadImageEndpt(db)\n+\n+  /**\n+   * Private method that compiles all store service endpoints.\n+   * @return Bundled compilation of all store service endpoints.\n+   */\n+  private def storeEndpts(db: PetstoreDb) =\n+    getInventoryEndpt(db) :+:\n+    addOrderEndpt(db) :+:\n+    deleteOrderEndpt(db) :+:\n+    findOrderEndpt(db)\n+\n+  /**\n+   * Private method that compiles all user service endpoints.\n+   * @return Bundled compilation of all user service endpoints.\n+   */\n+  private def userEndpts(db: PetstoreDb) =\n+    addUserEndpt(db) :+:\n+    addUsersViaList(db) :+:\n+    addUsersViaArray(db) :+:\n+    getUserEndpt(db) :+:\n+    deleteUserEndpt(db) :+:\n+    updateUserEndpt(db)\n+\n+  /**\n+   * Compiles together all the endpoints relating to public service methods.\n+   * @return A service that contains all provided endpoints of the API.\n+   */\n+  def makeService(db: PetstoreDb): Service[Request, Response] = handleExceptions andThen (\n+    petEndpts(db) :+:\n+    storeEndpts(db) :+:\n+    userEndpts(db)\n+  ).toService\n+\n+  /**\n+   * The long passed in the path becomes the ID of the Pet fetched.\n+   * @return A Router that contains the Pet fetched.\n+   */\n+  def getPetEndpt(db: PetstoreDb): Router[Future[Pet]] = Get / \"pet\" / long /> {petId: Long =>\n+    db.getPet(petId)\n+  }\n+\n+  /**\n+   * The pet to be added must be passed in the body.\n+   * @return A Router that contains a RequestReader of the ID of the Pet added.\n+   */\n+  def addPetEndpt(db: PetstoreDb): Router[RequestReader[Long]] = Post / \"pet\" />{\n+    body.as[Pet].embedFlatMap {pet =>\n+      for{\n+        realId <- db.addPet(pet)\n+      }yield realId\n+    }\n+  }\n+\n+  /**\n+   * The updated, better version of the current pet must be passed in the body.\n+   * @return A Router that contains a RequestReader of the updated Pet.\n+   */\n+  def updatePetEndpt(db: PetstoreDb): Router[RequestReader[Pet]] = Put / \"pet\" /> {\n+    body.as[Pet].embedFlatMap { pet =>\n+      for {\n+        _ <- db.updatePet(pet.copy(id = Some(pet.id.getOrElse(-1))))\n+        newPet <- db.getPet(pet.id.getOrElse(-1))\n+      } yield newPet\n+    }\n+  }\n+\n+  /**\n+   * The status is passed as a query parameter.\n+   * @return A Router that contains a RequestReader of the sequence of all Pets with the Status in question.\n+   */\n+  def getPetsByStatusEndpt(db: PetstoreDb): Router[RequestReader[Seq[Pet]]] = Get / \"pet\" / \"findByStatus\" />{\n+    (reader.statusReader).embedFlatMap{\n+      case s => db.getPetsByStatus(s)\n+    }\n+  }\n+\n+  /**\n+   * The tags are passed as query parameters.\n+   * @return A Router that contains a RequestReader of the sequence of all Pets with the given Tags.\n+   */\n+  def findPetsByTagEndpt(db: PetstoreDb): Router[RequestReader[Seq[Pet]]] = Get / \"pet\" / \"findByTags\" /> {\n+    reader.tagReader.embedFlatMap{\n+      db.findPetsByTag(_)\n+    }\n+  }\n+\n+  /**\n+   * The ID of the pet to delete is passed in the path.\n+   * @return A Router that contains a RequestReader of the deletePet result (true for success, false otherwise).\n+   */\n+  def deletePetEndpt(db: PetstoreDb): Router[Future[Response]] = Delete / \"pet\" / long /> { petId: Long =>\n+    db.deletePet(petId).map(_ => NoContent())\n+  }\n+\n+  /**\n+   * Endpoint for the updatePetViaForm (form data) service method. The pet's ID is passed in the path.\n+   * @return A Router that contains a RequestReader of the Pet that was updated.\n+   */\n+  def updatePetViaFormEndpt(db: PetstoreDb): Router[RequestReader[Pet]] = Post / \"pet\" / long /> {petId: Long =>\n+    (reader.nameReader :: reader.statusReader).asTuple.embedFlatMap{\n+      case (n, s) =>\n+        for{\n+          pet:Pet <- db.getPet(petId)\n+          newPet: Pet <- db.updatePetViaForm(petId, Some(n), Some(s))\n+        } yield newPet\n+    }\n+  }\n+\n+  /**\n+   * The ID of the pet corresponding to the image is passed in the path, whereas the image\n+   * file is passed as form data.\n+   * @return A Router that contains a RequestReader of the uploaded image's url.\n+   */\n+  def uploadImageEndpt(db: PetstoreDb): Router[RequestReader[String]] =\n+    Post / \"pet\" / long / \"uploadImage\" /> { petId: Long =>\n+      fileUpload(\"file\").embedFlatMap { upload =>\n+        db.addImage(petId, upload.get())\n+      }\n+    }\n+\n+  /**\n+   * @return A Router that contains a RequestReader of a Map reflecting the inventory.\n+   */\n+  def getInventoryEndpt(db: PetstoreDb): Router[Future[Inventory]] = Get / \"store\" / \"inventory\" /> {\n+    db.getInventory\n+  }\n+\n+  /**\n+   * The order to be added is passed in the body.\n+   * @return A Router that contains a RequestReader of the autogenerated ID for the added Order.\n+   */\n+  def addOrderEndpt(db: PetstoreDb): Router[RequestReader[Long]] = Post / \"store\" / \"order\" /> {\n+    body.as[Order].embedFlatMap{order =>\n+      db.addOrder(order)\n+    }\n+  }\n+\n+  /**\n+   * The ID of the order to be deleted is passed in the path.\n+   * @return A Router that contains a RequestReader of result of the deleteOrder method (true for success, false else).\n+   */\n+  def deleteOrderEndpt(db: PetstoreDb): Router[Future[Boolean]] = Delete / \"store\" / \"order\" / long /> {orderId: Long =>\n+    db.deleteOrder(orderId)\n+  }\n+\n+  /**\n+   * The ID of the order to be found is passed in the path.\n+   * @return A Router that contains a RequestReader of the Order in question.\n+   */\n+  def findOrderEndpt(db: PetstoreDb): Router[Future[Order]] = Get / \"store\" / \"order\" / long /> {orderId: Long =>\n+    db.findOrder(orderId)\n+  }\n+\n+  /**\n+   * The information of the added User is passed in the body.\n+   * @return A Router that contains a RequestReader of the username of the added User.\n+   */\n+  def addUserEndpt(db: PetstoreDb): Router[RequestReader[String]] = Post / \"user\" /> {\n+    body.as[User].embedFlatMap{newUser =>\n+      db.addUser(newUser)\n+    }\n+  }\n+\n+  /**\n+   * The list of Users is passed in the body.\n+   * @return A Router that contains a RequestReader of a sequence of the usernames of the Users added.\n+   */\n+  def addUsersViaList(db: PetstoreDb): Router[RequestReader[Seq[String]]] = Post / \"user\" / \"createWithList\" /> {\n+    body.as[Seq[User]].embedFlatMap{uList =>","path":"petstore/src/main/scala/io/finch/petstore/endpoint.scala","position":197,"original_position":197,"commit_id":"4a2d921c57b662b49c7bac41449731c97421f96e","original_commit_id":"4a2d921c57b662b49c7bac41449731c97421f96e","user":{"login":"vkostyukov","id":1098539,"avatar_url":"https://avatars.githubusercontent.com/u/1098539?v=3","gravatar_id":"","url":"https://api.github.com/users/vkostyukov","html_url":"https://github.com/vkostyukov","followers_url":"https://api.github.com/users/vkostyukov/followers","following_url":"https://api.github.com/users/vkostyukov/following{/other_user}","gists_url":"https://api.github.com/users/vkostyukov/gists{/gist_id}","starred_url":"https://api.github.com/users/vkostyukov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vkostyukov/subscriptions","organizations_url":"https://api.github.com/users/vkostyukov/orgs","repos_url":"https://api.github.com/users/vkostyukov/repos","events_url":"https://api.github.com/users/vkostyukov/events{/privacy}","received_events_url":"https://api.github.com/users/vkostyukov/received_events","type":"User","site_admin":false},"body":"Missing spaces before and after `{`.","created_at":"2015-07-17T21:35:06Z","updated_at":"2015-07-17T21:35:06Z","html_url":"https://github.com/finagle/finch/pull/352#discussion_r34933202","pull_request_url":"https://api.github.com/repos/finagle/finch/pulls/352","_links":{"self":{"href":"https://api.github.com/repos/finagle/finch/pulls/comments/34933202"},"html":{"href":"https://github.com/finagle/finch/pull/352#discussion_r34933202"},"pull_request":{"href":"https://api.github.com/repos/finagle/finch/pulls/352"}}},"pull_request":{"url":"https://api.github.com/repos/finagle/finch/pulls/352","id":40185595,"html_url":"https://github.com/finagle/finch/pull/352","diff_url":"https://github.com/finagle/finch/pull/352.diff","patch_url":"https://github.com/finagle/finch/pull/352.patch","issue_url":"https://api.github.com/repos/finagle/finch/issues/352","number":352,"state":"open","locked":false,"title":"Transferred working version of petstore project","user":{"login":"mimilei","id":1454638,"avatar_url":"https://avatars.githubusercontent.com/u/1454638?v=3","gravatar_id":"","url":"https://api.github.com/users/mimilei","html_url":"https://github.com/mimilei","followers_url":"https://api.github.com/users/mimilei/followers","following_url":"https://api.github.com/users/mimilei/following{/other_user}","gists_url":"https://api.github.com/users/mimilei/gists{/gist_id}","starred_url":"https://api.github.com/users/mimilei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mimilei/subscriptions","organizations_url":"https://api.github.com/users/mimilei/orgs","repos_url":"https://api.github.com/users/mimilei/repos","events_url":"https://api.github.com/users/mimilei/events{/privacy}","received_events_url":"https://api.github.com/users/mimilei/received_events","type":"User","site_admin":false},"body":"Here is the petstore project in all its hopefully-not-inconsequential glory. ","created_at":"2015-07-16T23:02:52Z","updated_at":"2015-07-17T21:35:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1182216c6ee319438de7598f056c628ca74d4d35","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/finagle/finch/pulls/352/commits","review_comments_url":"https://api.github.com/repos/finagle/finch/pulls/352/comments","review_comment_url":"https://api.github.com/repos/finagle/finch/pulls/comments{/number}","comments_url":"https://api.github.com/repos/finagle/finch/issues/352/comments","statuses_url":"https://api.github.com/repos/finagle/finch/statuses/4a2d921c57b662b49c7bac41449731c97421f96e","head":{"label":"mimilei:bestPetstoreEver","ref":"bestPetstoreEver","sha":"4a2d921c57b662b49c7bac41449731c97421f96e","user":{"login":"mimilei","id":1454638,"avatar_url":"https://avatars.githubusercontent.com/u/1454638?v=3","gravatar_id":"","url":"https://api.github.com/users/mimilei","html_url":"https://github.com/mimilei","followers_url":"https://api.github.com/users/mimilei/followers","following_url":"https://api.github.com/users/mimilei/following{/other_user}","gists_url":"https://api.github.com/users/mimilei/gists{/gist_id}","starred_url":"https://api.github.com/users/mimilei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mimilei/subscriptions","organizations_url":"https://api.github.com/users/mimilei/orgs","repos_url":"https://api.github.com/users/mimilei/repos","events_url":"https://api.github.com/users/mimilei/events{/privacy}","received_events_url":"https://api.github.com/users/mimilei/received_events","type":"User","site_admin":false},"repo":{"id":37077879,"name":"finch","full_name":"mimilei/finch","owner":{"login":"mimilei","id":1454638,"avatar_url":"https://avatars.githubusercontent.com/u/1454638?v=3","gravatar_id":"","url":"https://api.github.com/users/mimilei","html_url":"https://github.com/mimilei","followers_url":"https://api.github.com/users/mimilei/followers","following_url":"https://api.github.com/users/mimilei/following{/other_user}","gists_url":"https://api.github.com/users/mimilei/gists{/gist_id}","starred_url":"https://api.github.com/users/mimilei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mimilei/subscriptions","organizations_url":"https://api.github.com/users/mimilei/orgs","repos_url":"https://api.github.com/users/mimilei/repos","events_url":"https://api.github.com/users/mimilei/events{/privacy}","received_events_url":"https://api.github.com/users/mimilei/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mimilei/finch","description":"An idiomatic Scala version of finagle-http","fork":true,"url":"https://api.github.com/repos/mimilei/finch","forks_url":"https://api.github.com/repos/mimilei/finch/forks","keys_url":"https://api.github.com/repos/mimilei/finch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mimilei/finch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mimilei/finch/teams","hooks_url":"https://api.github.com/repos/mimilei/finch/hooks","issue_events_url":"https://api.github.com/repos/mimilei/finch/issues/events{/number}","events_url":"https://api.github.com/repos/mimilei/finch/events","assignees_url":"https://api.github.com/repos/mimilei/finch/assignees{/user}","branches_url":"https://api.github.com/repos/mimilei/finch/branches{/branch}","tags_url":"https://api.github.com/repos/mimilei/finch/tags","blobs_url":"https://api.github.com/repos/mimilei/finch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mimilei/finch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mimilei/finch/git/refs{/sha}","trees_url":"https://api.github.com/repos/mimilei/finch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mimilei/finch/statuses/{sha}","languages_url":"https://api.github.com/repos/mimilei/finch/languages","stargazers_url":"https://api.github.com/repos/mimilei/finch/stargazers","contributors_url":"https://api.github.com/repos/mimilei/finch/contributors","subscribers_url":"https://api.github.com/repos/mimilei/finch/subscribers","subscription_url":"https://api.github.com/repos/mimilei/finch/subscription","commits_url":"https://api.github.com/repos/mimilei/finch/commits{/sha}","git_commits_url":"https://api.github.com/repos/mimilei/finch/git/commits{/sha}","comments_url":"https://api.github.com/repos/mimilei/finch/comments{/number}","issue_comment_url":"https://api.github.com/repos/mimilei/finch/issues/comments{/number}","contents_url":"https://api.github.com/repos/mimilei/finch/contents/{+path}","compare_url":"https://api.github.com/repos/mimilei/finch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mimilei/finch/merges","archive_url":"https://api.github.com/repos/mimilei/finch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mimilei/finch/downloads","issues_url":"https://api.github.com/repos/mimilei/finch/issues{/number}","pulls_url":"https://api.github.com/repos/mimilei/finch/pulls{/number}","milestones_url":"https://api.github.com/repos/mimilei/finch/milestones{/number}","notifications_url":"https://api.github.com/repos/mimilei/finch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mimilei/finch/labels{/name}","releases_url":"https://api.github.com/repos/mimilei/finch/releases{/id}","created_at":"2015-06-08T16:11:13Z","updated_at":"2015-06-08T16:11:14Z","pushed_at":"2015-07-17T19:49:49Z","git_url":"git://github.com/mimilei/finch.git","ssh_url":"git@github.com:mimilei/finch.git","clone_url":"https://github.com/mimilei/finch.git","svn_url":"https://github.com/mimilei/finch","homepage":"","size":2838,"stargazers_count":0,"watchers_count":0,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"finagle:master","ref":"master","sha":"cee995a603ec28bfa71169c287f065bdbb7869fa","user":{"login":"finagle","id":7944306,"avatar_url":"https://avatars.githubusercontent.com/u/7944306?v=3","gravatar_id":"","url":"https://api.github.com/users/finagle","html_url":"https://github.com/finagle","followers_url":"https://api.github.com/users/finagle/followers","following_url":"https://api.github.com/users/finagle/following{/other_user}","gists_url":"https://api.github.com/users/finagle/gists{/gist_id}","starred_url":"https://api.github.com/users/finagle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/finagle/subscriptions","organizations_url":"https://api.github.com/users/finagle/orgs","repos_url":"https://api.github.com/users/finagle/repos","events_url":"https://api.github.com/users/finagle/events{/privacy}","received_events_url":"https://api.github.com/users/finagle/received_events","type":"Organization","site_admin":false},"repo":{"id":18798826,"name":"finch","full_name":"finagle/finch","owner":{"login":"finagle","id":7944306,"avatar_url":"https://avatars.githubusercontent.com/u/7944306?v=3","gravatar_id":"","url":"https://api.github.com/users/finagle","html_url":"https://github.com/finagle","followers_url":"https://api.github.com/users/finagle/followers","following_url":"https://api.github.com/users/finagle/following{/other_user}","gists_url":"https://api.github.com/users/finagle/gists{/gist_id}","starred_url":"https://api.github.com/users/finagle/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/finagle/subscriptions","organizations_url":"https://api.github.com/users/finagle/orgs","repos_url":"https://api.github.com/users/finagle/repos","events_url":"https://api.github.com/users/finagle/events{/privacy}","received_events_url":"https://api.github.com/users/finagle/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/finagle/finch","description":"An idiomatic Scala version of finagle-http","fork":false,"url":"https://api.github.com/repos/finagle/finch","forks_url":"https://api.github.com/repos/finagle/finch/forks","keys_url":"https://api.github.com/repos/finagle/finch/keys{/key_id}","collaborators_url":"https://api.github.com/repos/finagle/finch/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/finagle/finch/teams","hooks_url":"https://api.github.com/repos/finagle/finch/hooks","issue_events_url":"https://api.github.com/repos/finagle/finch/issues/events{/number}","events_url":"https://api.github.com/repos/finagle/finch/events","assignees_url":"https://api.github.com/repos/finagle/finch/assignees{/user}","branches_url":"https://api.github.com/repos/finagle/finch/branches{/branch}","tags_url":"https://api.github.com/repos/finagle/finch/tags","blobs_url":"https://api.github.com/repos/finagle/finch/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/finagle/finch/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/finagle/finch/git/refs{/sha}","trees_url":"https://api.github.com/repos/finagle/finch/git/trees{/sha}","statuses_url":"https://api.github.com/repos/finagle/finch/statuses/{sha}","languages_url":"https://api.github.com/repos/finagle/finch/languages","stargazers_url":"https://api.github.com/repos/finagle/finch/stargazers","contributors_url":"https://api.github.com/repos/finagle/finch/contributors","subscribers_url":"https://api.github.com/repos/finagle/finch/subscribers","subscription_url":"https://api.github.com/repos/finagle/finch/subscription","commits_url":"https://api.github.com/repos/finagle/finch/commits{/sha}","git_commits_url":"https://api.github.com/repos/finagle/finch/git/commits{/sha}","comments_url":"https://api.github.com/repos/finagle/finch/comments{/number}","issue_comment_url":"https://api.github.com/repos/finagle/finch/issues/comments{/number}","contents_url":"https://api.github.com/repos/finagle/finch/contents/{+path}","compare_url":"https://api.github.com/repos/finagle/finch/compare/{base}...{head}","merges_url":"https://api.github.com/repos/finagle/finch/merges","archive_url":"https://api.github.com/repos/finagle/finch/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/finagle/finch/downloads","issues_url":"https://api.github.com/repos/finagle/finch/issues{/number}","pulls_url":"https://api.github.com/repos/finagle/finch/pulls{/number}","milestones_url":"https://api.github.com/repos/finagle/finch/milestones{/number}","notifications_url":"https://api.github.com/repos/finagle/finch/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/finagle/finch/labels{/name}","releases_url":"https://api.github.com/repos/finagle/finch/releases{/id}","created_at":"2014-04-15T12:17:44Z","updated_at":"2015-07-16T21:55:28Z","pushed_at":"2015-07-17T19:49:49Z","git_url":"git://github.com/finagle/finch.git","ssh_url":"git@github.com:finagle/finch.git","clone_url":"https://github.com/finagle/finch.git","svn_url":"https://github.com/finagle/finch","homepage":"","size":5867,"stargazers_count":360,"watchers_count":360,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":43,"mirror_url":null,"open_issues_count":32,"forks":43,"open_issues":32,"watchers":360,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/finagle/finch/pulls/352"},"html":{"href":"https://github.com/finagle/finch/pull/352"},"issue":{"href":"https://api.github.com/repos/finagle/finch/issues/352"},"comments":{"href":"https://api.github.com/repos/finagle/finch/issues/352/comments"},"review_comments":{"href":"https://api.github.com/repos/finagle/finch/pulls/352/comments"},"review_comment":{"href":"https://api.github.com/repos/finagle/finch/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/finagle/finch/pulls/352/commits"},"statuses":{"href":"https://api.github.com/repos/finagle/finch/statuses/4a2d921c57b662b49c7bac41449731c97421f96e"}}}}