|
|
|
@ -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 用户登录
|
|
|
|
|