fix: unify handler response format in log, permission, webhook handlers

- log_handler.go: Fix GetMyLoginLogs/GetMyOperationLogs/GetLoginLogs/GetOperationLogs to use {code, message, data}
- permission_handler.go: Fix all error responses to use {code, message}
- webhook_handler.go: Add missing "message" field in success responses, wrap data in data object with list/total/page/page_size
- webhook_handler_test.go: Update test to match new response format

Standardize all JSON responses to {code: 0, message: "success", data: ...} for success
and {code: XXX, message: "..."} for errors.
This commit is contained in:
2026-04-11 13:12:27 +08:00
parent b6aff65975
commit e00af0bce4
4 changed files with 66 additions and 48 deletions

View File

@@ -35,7 +35,7 @@ func (h *WebhookHandler) CreateWebhook(c *gin.Context) {
return
}
c.JSON(http.StatusCreated, gin.H{"code": 0, "data": webhook})
c.JSON(http.StatusCreated, gin.H{"code": 0, "message": "success", "data": webhook})
}
func (h *WebhookHandler) ListWebhooks(c *gin.Context) {
@@ -59,11 +59,14 @@ func (h *WebhookHandler) ListWebhooks(c *gin.Context) {
}
c.JSON(http.StatusOK, gin.H{
"code": 0,
"data": webhooks,
"total": total,
"page": page,
"page_size": pageSize,
"code": 0,
"message": "success",
"data": gin.H{
"list": webhooks,
"total": total,
"page": page,
"page_size": pageSize,
},
})
}
@@ -121,5 +124,5 @@ func (h *WebhookHandler) GetWebhookDeliveries(c *gin.Context) {
return
}
c.JSON(http.StatusOK, gin.H{"code": 0, "data": deliveries})
c.JSON(http.StatusOK, gin.H{"code": 0, "message": "success", "data": gin.H{"deliveries": deliveries}})
}