refactor(api): simplify request body parsing in ampcode handlers

This commit is contained in:
hkfires
2025-12-08 14:45:35 +08:00
parent 93a6e2d920
commit 05cfa16e5f
3 changed files with 53 additions and 33 deletions

View File

@@ -240,16 +240,6 @@ func (h *Handler) updateBoolField(c *gin.Context, set func(bool)) {
Value *bool `json:"value"`
}
if err := c.ShouldBindJSON(&body); err != nil || body.Value == nil {
var m map[string]any
if err2 := c.ShouldBindJSON(&m); err2 == nil {
for _, v := range m {
if b, ok := v.(bool); ok {
set(b)
h.persist(c)
return
}
}
}
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid body"})
return
}