From 6c8f0b26971f5f3761067aaafe3fbf56621ddaaf Mon Sep 17 00:00:00 2001 From: b5 Date: Mon, 29 Oct 2018 09:15:42 -0400 Subject: [PATCH] feat(api published): GET /publish/ now lists published datasets --- api/dataset_test.go | 1 + api/datasets.go | 18 +++++++++++++++++- api/testdata/api.snapshot | Bin 177768 -> 178788 bytes 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/api/dataset_test.go b/api/dataset_test.go index 9c01b781d..b1e92aa4f 100644 --- a/api/dataset_test.go +++ b/api/dataset_test.go @@ -71,6 +71,7 @@ func TestDatasetHandlers(t *testing.T) { publishCases := []handlerTestCase{ {"OPTIONS", "/", nil}, + {"GET", "/publish/", nil}, {"POST", "/publish/me/cities", nil}, {"DELETE", "/publish/me/cities", nil}, } diff --git a/api/datasets.go b/api/datasets.go index 41f6026fb..38b77f1e9 100644 --- a/api/datasets.go +++ b/api/datasets.go @@ -187,7 +187,7 @@ func (h *DatasetHandlers) PublishHandler(w http.ResponseWriter, r *http.Request) case "OPTIONS": util.EmptyOkHandler(w, r) case "GET": - // TODO - this should list published datasets + h.listPublishedHandler(w, r) case "POST": h.publishHandler(w, r, true) case "DELETE": @@ -254,6 +254,22 @@ func (h *DatasetHandlers) listHandler(w http.ResponseWriter, r *http.Request) { } } +func (h *DatasetHandlers) listPublishedHandler(w http.ResponseWriter, r *http.Request) { + args := lib.ListParamsFromRequest(r) + args.OrderBy = "created" + args.Published = true + + res := []repo.DatasetRef{} + if err := h.List(&args, &res); err != nil { + log.Infof("error listing datasets: %s", err.Error()) + util.WriteErrResponse(w, http.StatusInternalServerError, err) + return + } + if err := util.WritePageResponse(w, res, r, args.Page()); err != nil { + log.Infof("error list datasests response: %s", err.Error()) + } +} + func (h *DatasetHandlers) getHandler(w http.ResponseWriter, r *http.Request) { res := &repo.DatasetRef{} args, err := DatasetRefFromPath(r.URL.Path) diff --git a/api/testdata/api.snapshot b/api/testdata/api.snapshot index fced1f8513448fa1b53f714ab0099971ba57d581..ae5b32bdd9c351b5419387cba9cbb87ea5cfd633 100755 GIT binary patch delta 80 zcmaFyhU>`}u7(!IElhVbdE8w?6!Z&9lX5bPGo~9ZW~!PVf0<|cQl#$85xbY=V&wi=>h=dQ5@m` delta 35 rcmaFzh3mx|u7(!IElhVbx1ZEv`p-1|gAWt?bbCW4!R_x2m`XbVE6@)5