{"action":"created","comment":{"url":"https://api.github.com/repos/alphagov/publishing-api/pulls/comments/25176636","id":25176636,"diff_hunk":"@@ -13,54 +14,69 @@ import (\n )\n \n type ContentStoreController struct {\n-\tarbiter      *urlarbiter.URLArbiter\n-\tcontentStore *contentstore.ContentStoreClient\n+\tarbiter           *urlarbiter.URLArbiter\n+\tliveContentStore  *contentstore.ContentStoreClient\n+\tdraftContentStore *contentstore.ContentStoreClient\n }\n \n type ContentStoreRequest struct {\n \tPublishingApp string `json:\"publishing_app\"`\n }\n \n-func NewContentStoreController(arbiterURL, contentStoreURL string) *ContentStoreController {\n+func NewContentStoreController(arbiterURL, liveContentStoreURL, draftContentStoreURL string) *ContentStoreController {\n \treturn &ContentStoreController{\n-\t\tarbiter:      urlarbiter.NewURLArbiter(arbiterURL),\n-\t\tcontentStore: contentstore.NewClient(contentStoreURL),\n+\t\tarbiter:           urlarbiter.NewURLArbiter(arbiterURL),\n+\t\tliveContentStore:  contentstore.NewClient(liveContentStoreURL),\n+\t\tdraftContentStore: contentstore.NewClient(draftContentStoreURL),\n \t}\n }\n \n-func (cs *ContentStoreController) PutContentStoreRequest(w http.ResponseWriter, r *http.Request) {\n-\turlParameters := mux.Vars(r)\n+func (controller *ContentStoreController) PutDraftContentStoreRequest(w http.ResponseWriter, r *http.Request) {\n+\tcontroller.registerWithURLArbiterAndForward(w, r, func(path string, requestBody []byte) {\n+\t\tcontroller.doDraftContentStoreRequest(\"PUT\", strings.Replace(path, \"draft-\", \"\", -1), requestBody, w)\n+\t})\n+}\n \n-\trequestBody, err := ioutil.ReadAll(r.Body)\n-\tif err != nil {\n-\t\trenderer.JSON(w, http.StatusInternalServerError, err)\n-\t\treturn\n-\t}\n+func (controller *ContentStoreController) PutContentStoreRequest(w http.ResponseWriter, r *http.Request) {\n+\tcontroller.registerWithURLArbiterAndForward(w, r, func(path string, requestBody []byte) {\n+\t\t// TODO: PUT to both content stores concurrently\n+\t\t// for now, we ignore the response from draft content store for storing live content, hence `w` is nil\n+\t\tcontroller.doContentStoreRequest(\"PUT\", path, requestBody, w)\n+\t\tcontroller.doDraftContentStoreRequest(\"PUT\", path, requestBody, nil)\n+\t})\n+}\n \n-\tvar contentStoreRequest *ContentStoreRequest\n-\tif err := json.Unmarshal(requestBody, &contentStoreRequest); err != nil {\n-\t\tswitch err.(type) {\n-\t\tcase *json.SyntaxError:\n-\t\t\trenderer.JSON(w, http.StatusBadRequest, err)\n-\t\tdefault:\n-\t\t\trenderer.JSON(w, http.StatusInternalServerError, err)\n-\t\t}\n-\t\treturn\n-\t}\n+func (controller *ContentStoreController) PutPublishIntentRequest(w http.ResponseWriter, r *http.Request) {\n+\tcontroller.registerWithURLArbiterAndForward(w, r, func(path string, requestBody []byte) {\n+\t\tcontroller.doContentStoreRequest(\"PUT\", path, requestBody, w)\n+\t})\n+}\n \n-\tif !cs.registerWithURLArbiter(urlParameters[\"base_path\"], contentStoreRequest.PublishingApp, w) {\n-\t\t// errors already written to ResponseWriter\n-\t\treturn\n-\t}\n+func (controller *ContentStoreController) GetContentStoreRequest(w http.ResponseWriter, r *http.Request) {\n+\tcontroller.doContentStoreRequest(\"GET\", r.URL.Path, nil, w)\n+}\n+\n+func (controller *ContentStoreController) DeleteContentStoreRequest(w http.ResponseWriter, r *http.Request) {\n+\tcontroller.doContentStoreRequest(\"DELETE\", r.URL.Path, nil, w)\n+}\n+\n+func (controller *ContentStoreController) registerWithURLArbiterAndForward(w http.ResponseWriter, r *http.Request,\n+\tafterRegister func(path string, requestBody []byte)) {\n \n-\tcs.doContentStoreRequest(\"PUT\", r.URL.Path, requestBody, w)\n+\turlParameters := mux.Vars(r)\n+\tif requestBody, contentStoreRequest := controller.readRequest(w, r); contentStoreRequest != nil {\n+\t\tif !controller.registerWithURLArbiter(urlParameters[\"base_path\"], contentStoreRequest.PublishingApp, w) {\n+\t\t\treturn\n+\t\t}\n+\t\tafterRegister(r.URL.Path, requestBody)\n+\t}\n }\n \n // Register the given path and publishing app with the URL arbiter.  Returns\n // true on success.  On failure, writes an error to the ResponseWriter, and\n // returns false\n-func (cs *ContentStoreController) registerWithURLArbiter(path, publishingApp string, w http.ResponseWriter) bool {\n-\turlArbiterResponse, err := cs.arbiter.Register(path, publishingApp)\n+func (controller *ContentStoreController) registerWithURLArbiter(path, publishingApp string, w http.ResponseWriter) bool {","path":"content_store_controller.go","position":102,"original_position":102,"commit_id":"44b1a4918265d06ecbb7f2ccd65a690b03d3c577","original_commit_id":"44b1a4918265d06ecbb7f2ccd65a690b03d3c577","user":{"login":"alext","id":5560,"avatar_url":"https://avatars.githubusercontent.com/u/5560?v=3","gravatar_id":"","url":"https://api.github.com/users/alext","html_url":"https://github.com/alext","followers_url":"https://api.github.com/users/alext/followers","following_url":"https://api.github.com/users/alext/following{/other_user}","gists_url":"https://api.github.com/users/alext/gists{/gist_id}","starred_url":"https://api.github.com/users/alext/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alext/subscriptions","organizations_url":"https://api.github.com/users/alext/orgs","repos_url":"https://api.github.com/users/alext/repos","events_url":"https://api.github.com/users/alext/events{/privacy}","received_events_url":"https://api.github.com/users/alext/received_events","type":"User","site_admin":false},"body":"Is it worth calling the `path` parameter `basePath` to make it clear that it's the base path of the item without any prefix components etc.","created_at":"2015-02-23T16:20:04Z","updated_at":"2015-02-23T16:20:04Z","html_url":"https://github.com/alphagov/publishing-api/pull/22#discussion_r25176636","pull_request_url":"https://api.github.com/repos/alphagov/publishing-api/pulls/22","_links":{"self":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/comments/25176636"},"html":{"href":"https://github.com/alphagov/publishing-api/pull/22#discussion_r25176636"},"pull_request":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/22"}}},"pull_request":{"url":"https://api.github.com/repos/alphagov/publishing-api/pulls/22","id":29802523,"html_url":"https://github.com/alphagov/publishing-api/pull/22","diff_url":"https://github.com/alphagov/publishing-api/pull/22.diff","patch_url":"https://github.com/alphagov/publishing-api/pull/22.patch","issue_url":"https://api.github.com/repos/alphagov/publishing-api/issues/22","number":22,"state":"open","locked":false,"title":"Allow publishing applications to store draft content","user":{"login":"vinayvinay","id":230074,"avatar_url":"https://avatars.githubusercontent.com/u/230074?v=3","gravatar_id":"","url":"https://api.github.com/users/vinayvinay","html_url":"https://github.com/vinayvinay","followers_url":"https://api.github.com/users/vinayvinay/followers","following_url":"https://api.github.com/users/vinayvinay/following{/other_user}","gists_url":"https://api.github.com/users/vinayvinay/gists{/gist_id}","starred_url":"https://api.github.com/users/vinayvinay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vinayvinay/subscriptions","organizations_url":"https://api.github.com/users/vinayvinay/orgs","repos_url":"https://api.github.com/users/vinayvinay/repos","events_url":"https://api.github.com/users/vinayvinay/events{/privacy}","received_events_url":"https://api.github.com/users/vinayvinay/received_events","type":"User","site_admin":false},"body":"https://trello.com/c/PbCzGBIB\r\n\r\n#### Need\r\nContent designers need a way to preview content they're drafting. When draft content is saved, publishing applications should be able to push that draft content to a draft instance of the content store, from where it can be previewed.\r\n\r\n#### Implementation\r\n0. Publishing API exposes a `/draft-content` endpoint, where publishing applications can dump the draft content item JSON and expect it to appear on the draft site. [see discussion](https://gov-uk.atlassian.net/wiki/display/PUB/Routing+requests+between+draft+and+live+content+stores#).\r\n0. Publishing API registers the base path of the draft content with url-arbiter (https://github.com/alphagov/publishing-api/commit/1949fcb041f91bee268ee5630aee1275c1aaf566), and then forwards the request only to the draft content store (https://github.com/alphagov/publishing-api/commit/877fed430bea2d308f6fe24b4374852839480a8d).\r\n0. Publishing API also forwards a copy of the live content item received at `/content` endpoint to the draft content store: https://github.com/alphagov/publishing-api/commit/b01dfc3ade44008f240df7ba3c119b47a5d9b59f.","created_at":"2015-02-23T11:45:23Z","updated_at":"2015-02-23T16:20:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c381cb78c2c9e3ecadc6ba7d384e3d6484a320df","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alphagov/publishing-api/pulls/22/commits","review_comments_url":"https://api.github.com/repos/alphagov/publishing-api/pulls/22/comments","review_comment_url":"https://api.github.com/repos/alphagov/publishing-api/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alphagov/publishing-api/issues/22/comments","statuses_url":"https://api.github.com/repos/alphagov/publishing-api/statuses/44b1a4918265d06ecbb7f2ccd65a690b03d3c577","head":{"label":"alphagov:draft-content-store","ref":"draft-content-store","sha":"44b1a4918265d06ecbb7f2ccd65a690b03d3c577","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":27546098,"name":"publishing-api","full_name":"alphagov/publishing-api","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/publishing-api","description":"An application to forward requests to multiple content-stores based on their state.","fork":false,"url":"https://api.github.com/repos/alphagov/publishing-api","forks_url":"https://api.github.com/repos/alphagov/publishing-api/forks","keys_url":"https://api.github.com/repos/alphagov/publishing-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/publishing-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/publishing-api/teams","hooks_url":"https://api.github.com/repos/alphagov/publishing-api/hooks","issue_events_url":"https://api.github.com/repos/alphagov/publishing-api/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/publishing-api/events","assignees_url":"https://api.github.com/repos/alphagov/publishing-api/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/publishing-api/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/publishing-api/tags","blobs_url":"https://api.github.com/repos/alphagov/publishing-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/publishing-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/publishing-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/publishing-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/publishing-api/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/publishing-api/languages","stargazers_url":"https://api.github.com/repos/alphagov/publishing-api/stargazers","contributors_url":"https://api.github.com/repos/alphagov/publishing-api/contributors","subscribers_url":"https://api.github.com/repos/alphagov/publishing-api/subscribers","subscription_url":"https://api.github.com/repos/alphagov/publishing-api/subscription","commits_url":"https://api.github.com/repos/alphagov/publishing-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/publishing-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/publishing-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/publishing-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/publishing-api/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/publishing-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/publishing-api/merges","archive_url":"https://api.github.com/repos/alphagov/publishing-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/publishing-api/downloads","issues_url":"https://api.github.com/repos/alphagov/publishing-api/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/publishing-api/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/publishing-api/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/publishing-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/publishing-api/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/publishing-api/releases{/id}","created_at":"2014-12-04T15:15:43Z","updated_at":"2015-02-23T10:50:57Z","pushed_at":"2015-02-23T11:37:02Z","git_url":"git://github.com/alphagov/publishing-api.git","ssh_url":"git@github.com:alphagov/publishing-api.git","clone_url":"https://github.com/alphagov/publishing-api.git","svn_url":"https://github.com/alphagov/publishing-api","homepage":"","size":727,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"base":{"label":"alphagov:master","ref":"master","sha":"2bbee590a6282302a43f176997170ad15058ddc9","user":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"repo":{"id":27546098,"name":"publishing-api","full_name":"alphagov/publishing-api","owner":{"login":"alphagov","id":596977,"avatar_url":"https://avatars.githubusercontent.com/u/596977?v=3","gravatar_id":"","url":"https://api.github.com/users/alphagov","html_url":"https://github.com/alphagov","followers_url":"https://api.github.com/users/alphagov/followers","following_url":"https://api.github.com/users/alphagov/following{/other_user}","gists_url":"https://api.github.com/users/alphagov/gists{/gist_id}","starred_url":"https://api.github.com/users/alphagov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alphagov/subscriptions","organizations_url":"https://api.github.com/users/alphagov/orgs","repos_url":"https://api.github.com/users/alphagov/repos","events_url":"https://api.github.com/users/alphagov/events{/privacy}","received_events_url":"https://api.github.com/users/alphagov/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/alphagov/publishing-api","description":"An application to forward requests to multiple content-stores based on their state.","fork":false,"url":"https://api.github.com/repos/alphagov/publishing-api","forks_url":"https://api.github.com/repos/alphagov/publishing-api/forks","keys_url":"https://api.github.com/repos/alphagov/publishing-api/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alphagov/publishing-api/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alphagov/publishing-api/teams","hooks_url":"https://api.github.com/repos/alphagov/publishing-api/hooks","issue_events_url":"https://api.github.com/repos/alphagov/publishing-api/issues/events{/number}","events_url":"https://api.github.com/repos/alphagov/publishing-api/events","assignees_url":"https://api.github.com/repos/alphagov/publishing-api/assignees{/user}","branches_url":"https://api.github.com/repos/alphagov/publishing-api/branches{/branch}","tags_url":"https://api.github.com/repos/alphagov/publishing-api/tags","blobs_url":"https://api.github.com/repos/alphagov/publishing-api/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alphagov/publishing-api/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alphagov/publishing-api/git/refs{/sha}","trees_url":"https://api.github.com/repos/alphagov/publishing-api/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alphagov/publishing-api/statuses/{sha}","languages_url":"https://api.github.com/repos/alphagov/publishing-api/languages","stargazers_url":"https://api.github.com/repos/alphagov/publishing-api/stargazers","contributors_url":"https://api.github.com/repos/alphagov/publishing-api/contributors","subscribers_url":"https://api.github.com/repos/alphagov/publishing-api/subscribers","subscription_url":"https://api.github.com/repos/alphagov/publishing-api/subscription","commits_url":"https://api.github.com/repos/alphagov/publishing-api/commits{/sha}","git_commits_url":"https://api.github.com/repos/alphagov/publishing-api/git/commits{/sha}","comments_url":"https://api.github.com/repos/alphagov/publishing-api/comments{/number}","issue_comment_url":"https://api.github.com/repos/alphagov/publishing-api/issues/comments{/number}","contents_url":"https://api.github.com/repos/alphagov/publishing-api/contents/{+path}","compare_url":"https://api.github.com/repos/alphagov/publishing-api/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alphagov/publishing-api/merges","archive_url":"https://api.github.com/repos/alphagov/publishing-api/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alphagov/publishing-api/downloads","issues_url":"https://api.github.com/repos/alphagov/publishing-api/issues{/number}","pulls_url":"https://api.github.com/repos/alphagov/publishing-api/pulls{/number}","milestones_url":"https://api.github.com/repos/alphagov/publishing-api/milestones{/number}","notifications_url":"https://api.github.com/repos/alphagov/publishing-api/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alphagov/publishing-api/labels{/name}","releases_url":"https://api.github.com/repos/alphagov/publishing-api/releases{/id}","created_at":"2014-12-04T15:15:43Z","updated_at":"2015-02-23T10:50:57Z","pushed_at":"2015-02-23T11:37:02Z","git_url":"git://github.com/alphagov/publishing-api.git","ssh_url":"git@github.com:alphagov/publishing-api.git","clone_url":"https://github.com/alphagov/publishing-api.git","svn_url":"https://github.com/alphagov/publishing-api","homepage":"","size":727,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/22"},"html":{"href":"https://github.com/alphagov/publishing-api/pull/22"},"issue":{"href":"https://api.github.com/repos/alphagov/publishing-api/issues/22"},"comments":{"href":"https://api.github.com/repos/alphagov/publishing-api/issues/22/comments"},"review_comments":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/22/comments"},"review_comment":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alphagov/publishing-api/pulls/22/commits"},"statuses":{"href":"https://api.github.com/repos/alphagov/publishing-api/statuses/44b1a4918265d06ecbb7f2ccd65a690b03d3c577"}}}}