Skip to content

Commit

Permalink
feat(api published): GET /publish/ now lists published datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
b5 committed Oct 29, 2018
1 parent 3d1b4bf commit 6c8f0b2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions api/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
}
Expand Down
18 changes: 17 additions & 1 deletion api/datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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)
Expand Down
Binary file modified api/testdata/api.snapshot
Binary file not shown.

0 comments on commit 6c8f0b2

Please sign in to comment.