mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-10-15 01:21:00 +00:00
The string was spelled out at each site that raises it, and once more in the test file that asserts on it. A test holding its own copy cannot tell the difference between the handler answering something else and the message having been reworded: it goes on asserting a string the server no longer sends, and goes on passing. The three copies in app/other/models/tools are left alone; they are raised from a different layer and nothing asserts on them.
59 lines
1.9 KiB
Go
59 lines
1.9 KiB
Go
package tools
|
||
|
||
import (
|
||
"github.com/gin-gonic/gin"
|
||
_ "github.com/go-admin-team/go-admin-core/v2/response"
|
||
"github.com/go-admin-team/go-admin-core/v2/sdk/pkg"
|
||
|
||
"go-admin/app/other/models/tools"
|
||
)
|
||
|
||
// emptyTableNameMsg is what the generator's endpoints answer with when the
|
||
// request named no table. Declared once because the tests assert on it: spelled
|
||
// out again at each site, a reworded message would leave them asserting on a
|
||
// string the server no longer sends, and still passing.
|
||
const emptyTableNameMsg = "table name cannot be empty!"
|
||
|
||
// GetDBColumnList 分页列表数据
|
||
// @Summary 分页列表数据 / page list data
|
||
// @Description 数据库表列分页列表 / database table column page list
|
||
// @Tags 工具 / 生成工具
|
||
// @Param tableName query string false "tableName / 数据表名称"
|
||
// @Param pageSize query int false "pageSize / 页条数"
|
||
// @Param pageIndex query int false "pageIndex / 页码"
|
||
// @Success 200 {object} response.Response "{"code": 200, "data": [...]}"
|
||
// @Router /api/v1/db/columns/page [get]
|
||
func (e Gen) GetDBColumnList(c *gin.Context) {
|
||
e.Context = c
|
||
log := e.GetLogger()
|
||
var data tools.DBColumns
|
||
var err error
|
||
var pageSize = 10
|
||
var pageIndex = 1
|
||
|
||
if size := c.Request.FormValue("pageSize"); size != "" {
|
||
pageSize, err = pkg.StringToInt(size)
|
||
}
|
||
|
||
if index := c.Request.FormValue("pageIndex"); index != "" {
|
||
pageIndex, err = pkg.StringToInt(index)
|
||
}
|
||
|
||
db, err := pkg.GetOrm(c)
|
||
if err != nil {
|
||
log.Errorf("get db connection error, %s", err.Error())
|
||
e.Error(500, err, "数据库连接获取失败")
|
||
return
|
||
}
|
||
|
||
data.TableName = c.Request.FormValue("tableName")
|
||
pkg.Assert(data.TableName != "", emptyTableNameMsg, 500)
|
||
result, count, err := data.GetPage(db, pageSize, pageIndex)
|
||
if err != nil {
|
||
log.Errorf("GetPage error, %s", err.Error())
|
||
e.Error(500, err, "")
|
||
return
|
||
}
|
||
e.PageOK(result, count, pageIndex, pageSize, "查询成功")
|
||
}
|