PATCH /admin/api/v1/colorpatterns Body: {"patternName": [1,2,3], ...} - updates or creates each named pattern.
(w http.ResponseWriter, r *http.Request)
| 52 | // PATCH /admin/api/v1/colorpatterns |
| 53 | // Body: {"patternName": [1,2,3], ...} - updates or creates each named pattern. |
| 54 | func apiV1PatchColorPatterns(w http.ResponseWriter, r *http.Request) { |
| 55 | var patches map[string][]int |
| 56 | if err := json.NewDecoder(r.Body).Decode(&patches); err != nil { |
| 57 | writeAPIError(w, http.StatusBadRequest, "malformed request body: "+err.Error()) |
| 58 | return |
| 59 | } |
| 60 | for name, colors := range patches { |
| 61 | for i, c := range colors { |
| 62 | if c < 0 || c > 255 { |
| 63 | writeAPIError(w, http.StatusBadRequest, fmt.Sprintf("color value at index %d of pattern %q out of range 0-255: %d", i, name, c)) |
| 64 | return |
| 65 | } |
| 66 | } |
| 67 | if err := colorpatterns.SaveColorPattern(name, colors); err != nil { |
| 68 | writeAPIError(w, http.StatusInternalServerError, err.Error()) |
| 69 | return |
| 70 | } |
| 71 | } |
| 72 | writeJSON(w, http.StatusOK, APIResponse[struct{}]{Success: true}) |
| 73 | } |
| 74 | |
| 75 | // DELETE /admin/api/v1/colorpatterns |
| 76 | // Body: {"name": "patternName"} |
nothing calls this directly
no test coverage detected