From 6f3f6af94cda27c218633e3cfb83b0bdd02f560b Mon Sep 17 00:00:00 2001 From: Francesco Ilario Date: Fri, 11 Oct 2024 17:41:25 +0200 Subject: [PATCH] enable patch endpoint Signed-off-by: Francesco Ilario --- server/rest/server.go | 17 +++++++++++++++-- server/rest/workspace/patch.go | 4 ++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/server/rest/server.go b/server/rest/server.go index ee3f29ce..4384a1ea 100644 --- a/server/rest/server.go +++ b/server/rest/server.go @@ -27,10 +27,11 @@ func New( listHandle workspace.ListWorkspaceQueryHandlerFunc, createHandle workspace.CreateWorkspaceCommandHandlerFunc, updateHandle workspace.UpdateWorkspaceCommandHandlerFunc, + patchHandle workspace.PatchWorkspaceCommandHandlerFunc, ) *http.Server { return &http.Server{ Addr: addr, - Handler: buildServerHandler(logger, cache, readHandle, listHandle, createHandle, updateHandle), + Handler: buildServerHandler(logger, cache, readHandle, listHandle, createHandle, updateHandle, patchHandle), ReadHeaderTimeout: 3 * time.Second, } } @@ -42,10 +43,11 @@ func buildServerHandler( listHandle workspace.ListWorkspaceQueryHandlerFunc, createHandle workspace.CreateWorkspaceCommandHandlerFunc, updateHandle workspace.UpdateWorkspaceCommandHandlerFunc, + patchHandle workspace.PatchWorkspaceCommandHandlerFunc, ) http.Handler { mux := http.NewServeMux() addHealthz(mux) - addWorkspaces(mux, cache, readHandle, listHandle, createHandle, updateHandle) + addWorkspaces(mux, cache, readHandle, listHandle, createHandle, updateHandle, patchHandle) mux.HandleFunc("GET /", func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) }) @@ -66,6 +68,7 @@ func addWorkspaces( listHandle workspace.ListWorkspaceQueryHandlerFunc, _ workspace.CreateWorkspaceCommandHandlerFunc, updateHandle workspace.UpdateWorkspaceCommandHandlerFunc, + patchHandle workspace.PatchWorkspaceCommandHandlerFunc, ) { // Read mux.Handle(fmt.Sprintf("GET %s/{name}", NamespacedWorkspacesPrefix), @@ -100,6 +103,16 @@ func addWorkspaces( marshal.DefaultUnmarshalerProvider, )))) + // Patch + mux.Handle(fmt.Sprintf("PATCH %s/{name}", NamespacedWorkspacesPrefix), + withAuthHeaderInfo( + withUserSignupAuth(cache, + workspace.NewPatchWorkspaceHandler( + workspace.MapPatchWorkspaceHttp, + patchHandle, + marshal.DefaultMarshalerProvider, + )))) + // Create // mux.Handle(fmt.Sprintf("POST %s", NamespacedWorkspacesPrefix), // withAuthHeaderInfo( diff --git a/server/rest/workspace/patch.go b/server/rest/workspace/patch.go index 1a79a1da..80a7407d 100644 --- a/server/rest/workspace/patch.go +++ b/server/rest/workspace/patch.go @@ -47,12 +47,12 @@ func NewDefaultPatchWorkspaceHandler( // NewPatchWorkspaceHandler creates a PatchWorkspaceHandler func NewPatchWorkspaceHandler( mapperFunc PatchWorkspaceMapperFunc, - queryHandler PatchWorkspaceCommandHandlerFunc, + commandHandler PatchWorkspaceCommandHandlerFunc, marshalerProvider marshal.MarshalerProvider, ) *PatchWorkspaceHandler { return &PatchWorkspaceHandler{ MapperFunc: mapperFunc, - CommandHandler: queryHandler, + CommandHandler: commandHandler, MarshalerProvider: marshalerProvider, } }