Skip to content

Commit

Permalink
Implement list rest query for ownership
Browse files Browse the repository at this point in the history
  • Loading branch information
krhubert committed Feb 11, 2020
1 parent e980d85 commit 03a506f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
31 changes: 27 additions & 4 deletions x/ownership/client/rest/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,41 @@ import (
"fmt"
"net/http"

"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/cosmos/cosmos-sdk/types/rest"
"github.com/gorilla/mux"
"github.com/mesg-foundation/engine/x/ownership/internal/types"
)

func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router) {
r.HandleFunc(
"/ownership/parameters",
"/ownership/list",
queryParamsHandlerFn(cliCtx),
).Methods("GET")
).Methods(http.MethodGet)
r.HandleFunc(
"/ownership/parameters",
queryListHandlerFn(cliCtx),
).Methods(http.MethodGet)
}

func queryListHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cliCtx, ok := rest.ParseQueryHeightOrReturnBadRequest(w, cliCtx, r)
if !ok {
return
}

route := fmt.Sprintf("custom/%s/list", types.QuerierRoute)

res, height, err := cliCtx.QueryWithData(route, nil)
if err != nil {
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
return
}

cliCtx = cliCtx.WithHeight(height)
rest.PostProcessResponse(w, cliCtx, res)
}
}

func queryParamsHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
Expand Down
3 changes: 1 addition & 2 deletions x/ownership/client/rest/rest.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package rest

import (
"github.com/gorilla/mux"

"github.com/cosmos/cosmos-sdk/client/context"
"github.com/gorilla/mux"
)

// RegisterRoutes registers ownership-related REST handlers to a router
Expand Down

0 comments on commit 03a506f

Please sign in to comment.