POST /admin/api/v2/spells
(w http.ResponseWriter, r *http.Request)
| 46 | |
| 47 | // POST /admin/api/v2/spells |
| 48 | func 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} |
| 77 | func apiV2PatchSpell(w http.ResponseWriter, r *http.Request) { |
nothing calls this directly
no test coverage detected