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

Function apiV2CreateSpell

internal/web/api_v2_spells.go:48–74  ·  view source on GitHub ↗

POST /admin/api/v2/spells

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

Source from the content-addressed store, hash-verified

46
47// POST /admin/api/v2/spells
48func apiV2CreateSpell(w http.ResponseWriter, r *http.Request) {
49 var spec spells.SpellData
50 if err := json.NewDecoder(r.Body).Decode(&spec); err != nil {
51 writeAPIError(w, http.StatusBadRequest, "malformed request body: "+err.Error())
52 return
53 }
54
55 if spec.SpellId == "" {
56 writeAPIError(w, http.StatusBadRequest, "SpellId is required")
57 return
58 }
59
60 if existing := spells.GetSpell(spec.SpellId); existing != nil {
61 writeAPIError(w, http.StatusConflict, "spell already exists: "+spec.SpellId)
62 return
63 }
64
65 if err := spells.SaveSpellSpec(&spec); err != nil {
66 writeAPIError(w, http.StatusInternalServerError, err.Error())
67 return
68 }
69
70 writeJSON(w, http.StatusCreated, APIResponse[*spells.SpellData]{
71 Success: true,
72 Data: &spec,
73 })
74}
75
76// PATCH /admin/api/v2/spells/{spellId}
77func apiV2PatchSpell(w http.ResponseWriter, r *http.Request) {

Callers

nothing calls this directly

Calls 4

GetSpellFunction · 0.92
SaveSpellSpecFunction · 0.92
writeAPIErrorFunction · 0.85
writeJSONFunction · 0.85

Tested by

no test coverage detected