feat: 完成查询用户列表的路由函数

main
熊二 2 years ago
parent 8151116592
commit c0540a6483
  1. 21
      app/rts.go

@ -146,7 +146,26 @@ func DeleteUser(w *ResponseWriter, r *Request) {
// ListUser 用户列表
func ListUser(w *ResponseWriter, r *Request) {
search := func(db *gorm.DB) *gorm.DB {
return db.
Model(&User{}).
Scopes(Search(r, "name", "name LIKE ?")).
Scopes(Paginate(r))
}
var userList []User
var total int64
var err error
if err = DB.Scopes(search).Count(&total).Error; err == nil {
err = DB.Scopes(search).Find(&userList).Error
}
if err != nil {
w.Fail(http.StatusInternalServerError, 1, err.Error())
} else {
w.Ok(map[string]any{
"list": userList,
"total": total,
})
}
}
// Login 用户登录

Loading…
Cancel
Save