Skip to content

Commit

Permalink
Merge pull request #1586 from qri-io/change-reports
Browse files Browse the repository at this point in the history
feat(api): change report API
  • Loading branch information
b5 authored Dec 9, 2020
2 parents 30e8406 + 9fb1b53 commit 8945a9f
Show file tree
Hide file tree
Showing 9 changed files with 1,328 additions and 2 deletions.
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func NewServerRoutes(s Server) *http.ServeMux {
m.Handle("/get/", s.middleware(dsh.GetHandler))
m.Handle("/rename", s.middleware(dsh.RenameHandler))
m.Handle("/diff", s.middleware(dsh.DiffHandler))
m.Handle("/changes", s.middleware(dsh.ChangesHandler))
// Deprecated, use /get/username/name?component=body or /get/username/name/body.csv
m.Handle("/body/", s.middleware(dsh.BodyHandler))
m.Handle("/stats/", s.middleware(dsh.StatsHandler))
Expand Down
38 changes: 38 additions & 0 deletions api/datasets.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,20 @@ func (h *DatasetHandlers) DiffHandler(w http.ResponseWriter, r *http.Request) {
}
}

// ChangesHandler is a dataset single endpoint
func (h *DatasetHandlers) ChangesHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodPost, http.MethodGet:
if h.ReadOnly {
readOnlyResponse(w, "/changereport")
return
}
h.changesHandler(w, r)
default:
util.NotFoundHandler(w, r)
}
}

// PeerListHandler is a dataset list endpoint
func (h *DatasetHandlers) PeerListHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method {
Expand Down Expand Up @@ -340,6 +354,30 @@ func (h *DatasetHandlers) diffHandler(w http.ResponseWriter, r *http.Request) {
util.WritePageResponse(w, res, r, util.Page{})
}

func (h *DatasetHandlers) changesHandler(w http.ResponseWriter, r *http.Request) {
req := &lib.ChangeReportParams{}
switch r.Header.Get("Content-Type") {
case "application/json":
if err := json.NewDecoder(r.Body).Decode(req); err != nil {
util.WriteErrResponse(w, http.StatusBadRequest, fmt.Errorf("error decoding body into params: %s", err.Error()))
return
}
default:
req = &lib.ChangeReportParams{
LeftRefstr: r.FormValue("left_path"),
RightRefstr: r.FormValue("right_path"),
}
}

res := &lib.ChangeReport{}
if err := h.ChangeReport(req, res); err != nil {
util.WriteErrResponse(w, http.StatusInternalServerError, fmt.Errorf("error generating change report: %s", err.Error()))
return
}

util.WritePageResponse(w, res, r, util.Page{})
}

func (h *DatasetHandlers) peerListHandler(w http.ResponseWriter, r *http.Request) {
log.Info(r.URL.Path)
p := lib.ListParamsFromRequest(r)
Expand Down
Loading

0 comments on commit 8945a9f

Please sign in to comment.