78 lines
2.1 KiB
Go
78 lines
2.1 KiB
Go
package system
|
|
|
|
import (
|
|
"kra/pkg/response"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type AutoCodeApi struct{}
|
|
|
|
// GetDB 获取当前所有数据库
|
|
// @Summary 获取当前所有数据库
|
|
// @Tags AutoCode
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Success 200 {object} response.Response{data=map[string]interface{}}
|
|
// @Router /autoCode/getDB [get]
|
|
func (api *AutoCodeApi) GetDB(c *gin.Context) {
|
|
dbs, err := autoCodeUsecase.GetDB(c.Request.Context())
|
|
if err != nil {
|
|
response.FailWithMessage("获取失败: "+err.Error(), c)
|
|
return
|
|
}
|
|
response.OkWithDetailed(gin.H{"dbs": dbs}, "获取成功", c)
|
|
}
|
|
|
|
// GetTables 获取当前数据库所有表
|
|
// @Summary 获取当前数据库所有表
|
|
// @Tags AutoCode
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param dbName query string false "数据库名"
|
|
// @Success 200 {object} response.Response{data=map[string]interface{}}
|
|
// @Router /autoCode/getTables [get]
|
|
func (api *AutoCodeApi) GetTables(c *gin.Context) {
|
|
dbName := c.Query("dbName")
|
|
if dbName == "" {
|
|
response.FailWithMessage("数据库名不能为空", c)
|
|
return
|
|
}
|
|
|
|
tables, err := autoCodeUsecase.GetTables(c.Request.Context(), dbName)
|
|
if err != nil {
|
|
response.FailWithMessage("查询table失败: "+err.Error(), c)
|
|
return
|
|
}
|
|
response.OkWithDetailed(gin.H{"tables": tables}, "获取成功", c)
|
|
}
|
|
|
|
// GetColumn 获取当前表所有字段
|
|
// @Summary 获取当前表所有字段
|
|
// @Tags AutoCode
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param dbName query string false "数据库名"
|
|
// @Param tableName query string true "表名"
|
|
// @Success 200 {object} response.Response{data=map[string]interface{}}
|
|
// @Router /autoCode/getColumn [get]
|
|
func (api *AutoCodeApi) GetColumn(c *gin.Context) {
|
|
dbName := c.Query("dbName")
|
|
tableName := c.Query("tableName")
|
|
if tableName == "" {
|
|
response.FailWithMessage("表名不能为空", c)
|
|
return
|
|
}
|
|
if dbName == "" {
|
|
response.FailWithMessage("数据库名不能为空", c)
|
|
return
|
|
}
|
|
|
|
columns, err := autoCodeUsecase.GetColumn(c.Request.Context(), tableName, dbName)
|
|
if err != nil {
|
|
response.FailWithMessage("获取失败: "+err.Error(), c)
|
|
return
|
|
}
|
|
response.OkWithDetailed(gin.H{"columns": columns}, "获取成功", c)
|
|
}
|