order test
This commit is contained in:
@@ -45,11 +45,6 @@ func DeleteApi(c *gin.Context) {
|
||||
}
|
||||
}
|
||||
|
||||
type AuthAndPathIn struct {
|
||||
AuthorityId string `json:"authorityId"`
|
||||
ApiIds []uint `json:"apiIds"`
|
||||
}
|
||||
|
||||
//条件搜索后端看此api
|
||||
|
||||
// @Tags SysApi
|
||||
@@ -65,10 +60,12 @@ func GetApiList(c *gin.Context) {
|
||||
type searchParams struct {
|
||||
model.SysApi
|
||||
model.PageInfo
|
||||
OrderKey string `json:"orderKey"`
|
||||
Desc bool `json:"desc"`
|
||||
}
|
||||
var sp searchParams
|
||||
_ = c.ShouldBindJSON(&sp)
|
||||
err, list, total := sp.SysApi.GetInfoList(sp.PageInfo)
|
||||
err, list, total := sp.SysApi.GetInfoList(sp.PageInfo, sp.OrderKey, sp.Desc)
|
||||
if err != nil {
|
||||
response.Result(response.ERROR, gin.H{}, fmt.Sprintf("获取数据失败,%v", err), c)
|
||||
} else {
|
||||
|
@@ -101,7 +101,7 @@ func (a *SysApi) GetAllApis() (err error, apis []SysApi) {
|
||||
// @return err error
|
||||
// @return list interface{}
|
||||
// @return total int
|
||||
func (a *SysApi) GetInfoList(info PageInfo) (err error, list interface{}, total int) {
|
||||
func (a *SysApi) GetInfoList(info PageInfo, Order string, Desc bool) (err error, list interface{}, total int) {
|
||||
limit := info.PageSize
|
||||
offset := info.PageSize * (info.Page - 1)
|
||||
db := global.GVA_DB
|
||||
@@ -128,7 +128,12 @@ func (a *SysApi) GetInfoList(info PageInfo) (err error, list interface{}, total
|
||||
if err != nil {
|
||||
return err, apiList, total
|
||||
} else {
|
||||
err = db.Limit(limit).Offset(offset).Order("api_group", true).Find(&apiList).Error
|
||||
db = db.Limit(limit).Offset(offset)
|
||||
if Order != "" {
|
||||
err = db.Order(Order+" desc", true).Find(&apiList).Error
|
||||
} else {
|
||||
err = db.Order("api_group", true).Find(&apiList).Error
|
||||
}
|
||||
}
|
||||
return err, apiList, total
|
||||
}
|
||||
|
Reference in New Issue
Block a user