feat: Go后端补全所有缺失API接口,消除前端404报错
新增接口: - GET /instances/accessible — 查询页实例列表(按access_type筛选) - GET /instances/:id/databases — 数据库列表(placeholder) - GET /instances/:id/databases/:db/tables — 表列表(placeholder) - POST /instances/test-connection — 新实例连接测试 - CRUD /instance-groups — 完整实例组管理(创建/更新/删除/查询单个) - /instance-groups/:id/instances — 实例分配/移除 - /instance-groups/:id/users — 用户分配 - PUT /instance-groups/users/:userId/groups — 用户组更新 - GET/PUT /ldap-config — LDAP配置读写 - POST /ldap-config/test — LDAP连接测试(placeholder) - POST /ldap-config/ou-list — OU列表(placeholder) - POST /ldap-config/user-list — 用户列表(placeholder) - PUT /settings — 批量更新设置 - GET /settings/cleanup/preview — 清理预览 - POST /settings/cleanup/run — 执行清理 修复: - ListSettings 返回按group分组的dict(前端期望格式) - ListInstanceGroups 返回enriched数据(含实例/用户计数) - 前端所有页面0个404错误,查询页实例下拉框正常显示
This commit is contained in:
1 parent
26148d0ca7
commit
622923821b
5 files changed
+526
-4
No files matched your search
@@ -0,0 +1,111 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"sql-platform/internal/model"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// GET /api/v1/ldap-config
|
||||
func GetLDAPConfig(c *gin.Context) {
|
||||
var configs []model.LDAPConfig
|
||||
model.DB.Order("id").Find(&configs)
|
||||
if len(configs) == 0 {
|
||||
c.JSON(http.StatusOK, nil)
|
||||
return
|
||||
}
|
||||
// mask password
|
||||
configs[0].AdminPassword = "******"
|
||||
c.JSON(http.StatusOK, configs[0])
|
||||
}
|
||||
|
||||
// PUT /api/v1/ldap-config
|
||||
func UpdateLDAPConfig(c *gin.Context) {
|
||||
var input map[string]interface{}
|
||||
if err := c.ShouldBindJSON(&input); err != nil {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"detail": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
var configs []model.LDAPConfig
|
||||
model.DB.Order("id").Find(&configs)
|
||||
|
||||
if len(configs) == 0 {
|
||||
// create new
|
||||
config := model.LDAPConfig{}
|
||||
if v, ok := input["ldap_host"].(string); ok {
|
||||
config.LDAPHost = v
|
||||
}
|
||||
if v, ok := input["base_dn"].(string); ok {
|
||||
config.BaseDN = v
|
||||
}
|
||||
if v, ok := input["admin_dn"].(string); ok {
|
||||
config.AdminDN = v
|
||||
}
|
||||
if v, ok := input["admin_password"].(string); ok && v != "******" {
|
||||
config.AdminPassword = v
|
||||
}
|
||||
if v, ok := input["search_filter"].(string); ok {
|
||||
config.SearchFilter = &v
|
||||
}
|
||||
if v, ok := input["user_mapping"].(string); ok {
|
||||
config.UserMapping = &v
|
||||
}
|
||||
if v, ok := input["ldap_port"].(float64); ok {
|
||||
port := int(v)
|
||||
config.LDAPPort = &port
|
||||
}
|
||||
if v, ok := input["use_ldaps"].(bool); ok {
|
||||
config.UseLDAPS = &v
|
||||
}
|
||||
model.DB.Create(&config)
|
||||
c.JSON(http.StatusOK, config)
|
||||
} else {
|
||||
// update existing
|
||||
if pw, ok := input["admin_password"].(string); ok && pw == "******" {
|
||||
delete(input, "admin_password")
|
||||
}
|
||||
model.DB.Model(&configs[0]).Updates(input)
|
||||
model.DB.First(&configs[0], configs[0].ID)
|
||||
configs[0].AdminPassword = "******"
|
||||
c.JSON(http.StatusOK, configs[0])
|
||||
}
|
||||
}
|
||||
|
||||
// POST /api/v1/ldap-config/test
|
||||
func TestLDAPConnection(c *gin.Context) {
|
||||
// TODO: actual LDAP connection test
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"success": true,
|
||||
"message": "LDAP connection test (placeholder)",
|
||||
})
|
||||
}
|
||||
|
||||
// POST /api/v1/ldap-config/ou-list
|
||||
func ListLDAPOUs(c *gin.Context) {
|
||||
// TODO: actual LDAP OU list
|
||||
c.JSON(http.StatusOK, []interface{}{})
|
||||
}
|
||||
|
||||
// POST /api/v1/ldap-config/user-list
|
||||
func ListLDAPUsers(c *gin.Context) {
|
||||
// TODO: actual LDAP user list
|
||||
c.JSON(http.StatusOK, []interface{}{})
|
||||
}
|
||||
|
||||
// POST /api/v1/ldap-config/create-ou
|
||||
func CreateLDAPOU(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "OU created (placeholder)"})
|
||||
}
|
||||
|
||||
// POST /api/v1/ldap-config/create-user
|
||||
func CreateLDAPUser(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "User created (placeholder)"})
|
||||
}
|
||||
|
||||
// POST /api/v1/ldap-config/batch-import-ldap
|
||||
func BatchImportLDAP(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{"message": "Batch import (placeholder)", "count": 0})
|
||||
}
|
||||
Reference in new issue
Block a user