fix: 统一API响应格式并修复前端测试

- 所有Handler方法使用标准{code:0,message:"success",data:...}响应格式
- 修复Cursor分页响应包装(GetAllDevices,GetLoginLogs,ListUsers等)
- 修复AuthHandler和SMSHandler认证方法响应格式
- 修复operation_log.go admin用户operation_type前缀问题
- 修复DashboardPage嵌套stats结构
- 修复LoginLogsPage reset功能stale closure问题
- 修复UsersPage批量操作API调用
- 修复多个前端测试(mock格式、按钮选择、断言逻辑)
- 添加OAuth测试域名白名单
- 新增代码审查流程文档
This commit is contained in:
2026-04-08 20:06:54 +08:00
parent 26c5def4d7
commit a85d822419
33 changed files with 2108 additions and 206 deletions

View File

@@ -33,7 +33,11 @@ func (h *RoleHandler) CreateRole(c *gin.Context) {
return
}
c.JSON(http.StatusCreated, role)
c.JSON(http.StatusCreated, gin.H{
"code": 0,
"message": "success",
"data": role,
})
}
func (h *RoleHandler) ListRoles(c *gin.Context) {
@@ -50,8 +54,12 @@ func (h *RoleHandler) ListRoles(c *gin.Context) {
}
c.JSON(http.StatusOK, gin.H{
"roles": roles,
"total": total,
"code": 0,
"message": "success",
"data": gin.H{
"items": roles,
"total": total,
},
})
}
@@ -68,7 +76,11 @@ func (h *RoleHandler) GetRole(c *gin.Context) {
return
}
c.JSON(http.StatusOK, role)
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "success",
"data": role,
})
}
func (h *RoleHandler) UpdateRole(c *gin.Context) {
@@ -90,7 +102,11 @@ func (h *RoleHandler) UpdateRole(c *gin.Context) {
return
}
c.JSON(http.StatusOK, role)
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "success",
"data": role,
})
}
func (h *RoleHandler) DeleteRole(c *gin.Context) {
@@ -105,7 +121,10 @@ func (h *RoleHandler) DeleteRole(c *gin.Context) {
return
}
c.JSON(http.StatusOK, gin.H{"message": "role deleted"})
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "role deleted",
})
}
func (h *RoleHandler) UpdateRoleStatus(c *gin.Context) {
@@ -141,7 +160,10 @@ func (h *RoleHandler) UpdateRoleStatus(c *gin.Context) {
return
}
c.JSON(http.StatusOK, gin.H{"message": "status updated"})
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "status updated",
})
}
func (h *RoleHandler) GetRolePermissions(c *gin.Context) {
@@ -157,7 +179,11 @@ func (h *RoleHandler) GetRolePermissions(c *gin.Context) {
return
}
c.JSON(http.StatusOK, gin.H{"permissions": perms})
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "success",
"data": perms,
})
}
func (h *RoleHandler) AssignPermissions(c *gin.Context) {
@@ -182,5 +208,8 @@ func (h *RoleHandler) AssignPermissions(c *gin.Context) {
return
}
c.JSON(http.StatusOK, gin.H{"message": "permissions assigned"})
c.JSON(http.StatusOK, gin.H{
"code": 0,
"message": "permissions assigned",
})
}