mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-29 09:43:10 -06:00
Co-authored-by: Tommie Gannert <tommie@gannert.se> Co-authored-by: Dan Peleg <dan@globekeeper.com>
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package inthttp
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
"github.com/matrix-org/dendrite/internal/httputil"
|
|
"github.com/matrix-org/dendrite/pushserver/api"
|
|
"github.com/matrix-org/util"
|
|
)
|
|
|
|
// AddRoutes adds the PushserverInternalAPI handlers to the http.ServeMux.
|
|
// nolint: gocyclo
|
|
func AddRoutes(r api.PushserverInternalAPI, internalAPIMux *mux.Router) {
|
|
|
|
internalAPIMux.Handle(PerformPusherSetPath,
|
|
httputil.MakeInternalAPI("performPusherSet", func(req *http.Request) util.JSONResponse {
|
|
request := api.PerformPusherSetRequest{}
|
|
response := struct{}{}
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
}
|
|
if err := r.PerformPusherSet(req.Context(), &request, &response); err != nil {
|
|
return util.ErrorResponse(err)
|
|
}
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
}),
|
|
)
|
|
internalAPIMux.Handle(PerformPusherDeletionPath,
|
|
httputil.MakeInternalAPI("performPusherDeletion", func(req *http.Request) util.JSONResponse {
|
|
request := api.PerformPusherDeletionRequest{}
|
|
response := struct{}{}
|
|
if err := json.NewDecoder(req.Body).Decode(&request); err != nil {
|
|
return util.MessageResponse(http.StatusBadRequest, err.Error())
|
|
}
|
|
if err := r.PerformPusherDeletion(req.Context(), &request, &response); err != nil {
|
|
return util.ErrorResponse(err)
|
|
}
|
|
return util.JSONResponse{Code: http.StatusOK, JSON: &response}
|
|
}),
|
|
)
|
|
|
|
}
|