diff --git a/api/api.go b/api/api.go index 9d101d5a8..93d12668d 100644 --- a/api/api.go +++ b/api/api.go @@ -228,6 +228,7 @@ func NewServerRoutes(s *Server) *http.ServeMux { m.Handle("/diff", s.middleware(dsh.DiffHandler)) m.Handle("/body/", s.middleware(dsh.BodyHandler)) m.Handle("/unpack/", s.middleware(dsh.UnpackHandler)) + m.Handle("/publish/", s.middleware(dsh.PublishHandler)) renderh := NewRenderHandlers(s.qriNode.Repo) m.Handle("/render/", s.middleware(renderh.RenderHandler)) diff --git a/api/dataset_test.go b/api/dataset_test.go index bf0ec8092..9c01b781d 100644 --- a/api/dataset_test.go +++ b/api/dataset_test.go @@ -69,6 +69,13 @@ func TestDatasetHandlers(t *testing.T) { } runHandlerTestCases(t, "export", h.ZipDatasetHandler, exportCases) + publishCases := []handlerTestCase{ + {"OPTIONS", "/", nil}, + {"POST", "/publish/me/cities", nil}, + {"DELETE", "/publish/me/cities", nil}, + } + runHandlerTestCases(t, "publish", h.PublishHandler, publishCases) + // TODO: Perhaps add an option to runHandlerTestCases to set Content-Type, then combine // `runHandlerZipPostTestCases` with `runHandlerTestCases`. unpackCases := []handlerTestCase{ diff --git a/api/datasets.go b/api/datasets.go index 11f80661c..41f6026fb 100644 --- a/api/datasets.go +++ b/api/datasets.go @@ -181,6 +181,22 @@ func (h *DatasetHandlers) UnpackHandler(w http.ResponseWriter, r *http.Request) } } +// PublishHandler works with dataset publicity +func (h *DatasetHandlers) PublishHandler(w http.ResponseWriter, r *http.Request) { + switch r.Method { + case "OPTIONS": + util.EmptyOkHandler(w, r) + case "GET": + // TODO - this should list published datasets + case "POST": + h.publishHandler(w, r, true) + case "DELETE": + h.publishHandler(w, r, false) + default: + util.NotFoundHandler(w, r) + } +} + // ZipDatasetHandler is the endpoint for getting a zip archive of a dataset func (h *DatasetHandlers) ZipDatasetHandler(w http.ResponseWriter, r *http.Request) { switch r.Method { @@ -705,6 +721,22 @@ func (h DatasetHandlers) bodyHandler(w http.ResponseWriter, r *http.Request) { } } +func (h DatasetHandlers) publishHandler(w http.ResponseWriter, r *http.Request, publish bool) { + ref, err := DatasetRefFromPath(r.URL.Path[len("/publish"):]) + if err != nil { + util.WriteErrResponse(w, http.StatusBadRequest, err) + return + } + + ref.Published = publish + var ok bool + if err := h.DatasetRequests.SetPublishStatus(&ref, &ok); err != nil { + util.WriteErrResponse(w, http.StatusInternalServerError, err) + return + } + util.WriteResponse(w, ref) +} + func (h DatasetHandlers) unpackHandler(w http.ResponseWriter, r *http.Request, postData []byte) { zr, err := zip.NewReader(bytes.NewReader(postData), int64(len(postData))) if err != nil { diff --git a/api/testdata/api.snapshot b/api/testdata/api.snapshot index d53ee4cae..fced1f851 100755 Binary files a/api/testdata/api.snapshot and b/api/testdata/api.snapshot differ diff --git a/repo/fs/refstore.go b/repo/fs/refstore.go index 1a9e3b98c..4f4f81547 100644 --- a/repo/fs/refstore.go +++ b/repo/fs/refstore.go @@ -64,6 +64,7 @@ func (n Refstore) PutRef(p repo.DatasetRef) (err error) { } } + // TODO - move this up into base package if n.index != nil { batch := n.index.NewBatch() err = batch.Index(p.Path, ds)