MCPcopy Create free account
hub / github.com/GoMudEngine/GoMud / apiV1PatchMutator

Function apiV1PatchMutator

internal/web/api_v1_mutators.go:56–84  ·  view source on GitHub ↗

PATCH /admin/api/v1/mutators/{mutatorId}

(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

54
55// PATCH /admin/api/v1/mutators/{mutatorId}
56func apiV1PatchMutator(w http.ResponseWriter, r *http.Request) {
57 mutatorId := r.PathValue("mutatorId")
58
59 existing := mutators.GetMutatorSpec(mutatorId)
60 if existing == nil {
61 writeAPIError(w, http.StatusNotFound, "mutator not found: "+mutatorId)
62 return
63 }
64
65 updated := *existing
66 // Nil out map fields that must be fully replaced (not merged) by the JSON decode.
67 updated.Exits = nil
68 if err := json.NewDecoder(r.Body).Decode(&updated); err != nil {
69 writeAPIError(w, http.StatusBadRequest, "malformed request body: "+err.Error())
70 return
71 }
72
73 updated.MutatorId = mutatorId
74
75 if err := mutators.SaveMutatorSpec(&updated); err != nil {
76 writeAPIError(w, http.StatusInternalServerError, err.Error())
77 return
78 }
79
80 writeJSON(w, http.StatusOK, APIResponse[*mutators.MutatorSpec]{
81 Success: true,
82 Data: &updated,
83 })
84}
85
86// DELETE /admin/api/v1/mutators/{mutatorId}
87func apiV1DeleteMutator(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 4

GetMutatorSpecFunction · 0.92
SaveMutatorSpecFunction · 0.92
writeAPIErrorFunction · 0.85
writeJSONFunction · 0.85

Tested by

no test coverage detected