aboutsummaryrefslogtreecommitdiff
path: root/userapi/inthttp
diff options
context:
space:
mode:
authorKegsay <kegan@matrix.org>2020-06-16 17:05:38 +0100
committerGitHub <noreply@github.com>2020-06-16 17:05:38 +0100
commit83391da0e04dda7a52589ee7ec6df2b615571894 (patch)
tree0a0ffcc5b7209600eaf042ee317a0681e0bd7f59 /userapi/inthttp
parent1942928ee5e0398beed45c8b1c63d7b13e89b646 (diff)
Make syncapi use userapi (#1136)
* Make syncapi use userapi * Unbreak things * Fix tests * Lint
Diffstat (limited to 'userapi/inthttp')
-rw-r--r--userapi/inthttp/client.go9
-rw-r--r--userapi/inthttp/server.go13
2 files changed, 22 insertions, 0 deletions
diff --git a/userapi/inthttp/client.go b/userapi/inthttp/client.go
index 638a7e9b..48e6d7d7 100644
--- a/userapi/inthttp/client.go
+++ b/userapi/inthttp/client.go
@@ -29,6 +29,7 @@ const (
QueryProfilePath = "/userapi/queryProfile"
QueryAccessTokenPath = "/userapi/queryAccessToken"
QueryDevicesPath = "/userapi/queryDevices"
+ QueryAccountDataPath = "/userapi/queryAccountData"
)
// NewUserAPIClient creates a UserInternalAPI implemented by talking to a HTTP POST API.
@@ -82,3 +83,11 @@ func (h *httpUserInternalAPI) QueryDevices(ctx context.Context, req *api.QueryDe
apiURL := h.apiURL + QueryDevicesPath
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
}
+
+func (h *httpUserInternalAPI) QueryAccountData(ctx context.Context, req *api.QueryAccountDataRequest, res *api.QueryAccountDataResponse) error {
+ span, ctx := opentracing.StartSpanFromContext(ctx, "QueryAccountData")
+ defer span.Finish()
+
+ apiURL := h.apiURL + QueryAccountDataPath
+ return httputil.PostJSON(ctx, span, h.httpClient, apiURL, req, res)
+}
diff --git a/userapi/inthttp/server.go b/userapi/inthttp/server.go
index 19b0e40b..8bf2efc0 100644
--- a/userapi/inthttp/server.go
+++ b/userapi/inthttp/server.go
@@ -64,4 +64,17 @@ func AddRoutes(internalAPIMux *mux.Router, s api.UserInternalAPI) {
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
}),
)
+ internalAPIMux.Handle(QueryAccountDataPath,
+ httputil.MakeInternalAPI("queryAccountData", func(req *http.Request) util.JSONResponse {
+ request := api.QueryAccountDataRequest{}
+ response := api.QueryAccountDataResponse{}
+ if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
+ return util.MessageResponse(http.StatusBadRequest, err.Error())
+ }
+ if err := s.QueryAccountData(req.Context(), &request, &response); err != nil {
+ return util.ErrorResponse(err)
+ }
+ return util.JSONResponse{Code: http.StatusOK, JSON: &response}
+ }),
+ )
}