From 795bb5b6f8a64047a2cbe37ddaed75f52fe070e7 Mon Sep 17 00:00:00 2001 From: SUMUKHA-PK Date: Mon, 11 Mar 2019 10:26:12 +0530 Subject: [PATCH] Some progress in building roomtags --- .../clientapi/routing/room_tagging.go | 32 ++++++------------- .../dendrite/clientapi/routing/routing.go | 25 +++++++++++++++ 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/room_tagging.go b/src/github.com/matrix-org/dendrite/clientapi/routing/room_tagging.go index 7a59fd041..f9c3134b7 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/room_tagging.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/room_tagging.go @@ -14,31 +14,19 @@ package routing -const pathPrefixR0 = "/_matrix/client/r0" +import "net/http" -func TagRoom( - req *http.Request -) util.JSONResponse { +// GetTag implements GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags +func GetTag(req *http.Request, userId string, roomId string) { - r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter() +} +// PutTag implements GET /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} +func PutTag(req *http.Request, userId string, roomId string, tag string) { - r0mux.Handle("/user/{userId}/rooms/{roomId}/tags", - common.MakeAuthAPI("account_3pid", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - return GetTag() - }), - ).Methods(http.MethodGet, http.MethodOptions) +} - r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}", - common.MakeAuthAPI("account_3pid", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - return PutTag() - }), - ).Methods(http.MethodPut, http.MethodOptions) +// DeleteTag implements DELETE /_matrix/client/r0/user/{userId}/rooms/{roomId}/tags/{tag} +func DeleteTag(req *http.Request, userId string, roomId string, tag string) { - r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}", - common.MakeAuthAPI("account_3pid", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { - return DeleteTag() - }), - ).Methods(http.MethodDelete, http.MethodOptions) - -} \ No newline at end of file +} diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go index 1d95ffe72..19473d752 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go @@ -406,4 +406,29 @@ func Setup( }} }), ).Methods(http.MethodGet, http.MethodOptions) + + r0mux.Handle("/user/{userId}/rooms/{roomId}/tags", + common.MakeAuthAPI("account_3pid", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + // When a GET tag request is done, obtain all data of user from here and provide a JSON response. + // MakeAuthAPI will convert it to a HTTP response and reflect it on the browser. + vars := mux.Vars(req) + return GetTag(req, vars["userId"], vars["roomId"]) + }), + ).Methods(http.MethodGet, http.MethodOptions) + + r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}", + common.MakeAuthAPI("account_3pid", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + // When a PUT tag request is done, obtain all data of user from here and provide a JSON response. + // MakeAuthAPI will convert it to a HTTP response and reflect it on the browser. + return PutTag(req, vars["userId"], vars["roomId"], vars["tag"]) + }), + ).Methods(http.MethodPut, http.MethodOptions) + + r0mux.Handle("/user/{userId}/rooms/{roomId}/tags/{tag}", + common.MakeAuthAPI("account_3pid", authData, func(req *http.Request, device *authtypes.Device) util.JSONResponse { + // When a DELETE tag request is done, obtain all data of user from here and provide a JSON response. + // MakeAuthAPI will convert it to a HTTP response and reflect it on the browser. + return DeleteTagreq, (vars["userId"], vars["roomId"], vars["tag"]) + }), + ).Methods(http.MethodDelete, http.MethodOptions) }