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

Function apiV1CreateColorPattern

internal/web/api_v1_colorpatterns.go:21–50  ·  view source on GitHub ↗

POST /admin/api/v1/colorpatterns Body: {"name": "flame", "colors": [1, 2, 3]}

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

Source from the content-addressed store, hash-verified

19// POST /admin/api/v1/colorpatterns
20// Body: {"name": "flame", "colors": [1, 2, 3]}
21func apiV1CreateColorPattern(w http.ResponseWriter, r *http.Request) {
22 var body struct {
23 Name string `json:"name"`
24 Colors []int `json:"colors"`
25 }
26 if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
27 writeAPIError(w, http.StatusBadRequest, "malformed request body: "+err.Error())
28 return
29 }
30 if body.Name == "" {
31 writeAPIError(w, http.StatusBadRequest, "name is required")
32 return
33 }
34 for i, c := range body.Colors {
35 if c < 0 || c > 255 {
36 writeAPIError(w, http.StatusBadRequest, fmt.Sprintf("color value at index %d out of range 0-255: %d", i, c))
37 return
38 }
39 }
40 existing := colorpatterns.GetAllColorPatterns()
41 if _, ok := existing[body.Name]; ok {
42 writeAPIError(w, http.StatusConflict, "color pattern already exists: "+body.Name)
43 return
44 }
45 if err := colorpatterns.SaveColorPattern(body.Name, body.Colors); err != nil {
46 writeAPIError(w, http.StatusInternalServerError, err.Error())
47 return
48 }
49 writeJSON(w, http.StatusOK, APIResponse[struct{}]{Success: true})
50}
51
52// PATCH /admin/api/v1/colorpatterns
53// Body: {"patternName": [1,2,3], ...} - updates or creates each named pattern.

Callers

nothing calls this directly

Calls 4

GetAllColorPatternsFunction · 0.92
SaveColorPatternFunction · 0.92
writeAPIErrorFunction · 0.85
writeJSONFunction · 0.85

Tested by

no test coverage detected