From c0540a6483774ac96f96725dcd29e406cf84ddf2 Mon Sep 17 00:00:00 2001 From: hupeh Date: Mon, 2 Jan 2023 12:20:56 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20:sparkles:=20=E5=AE=8C=E6=88=90?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8=E7=9A=84?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/rts.go | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/app/rts.go b/app/rts.go index 5dafa6b..8c9c84f 100644 --- a/app/rts.go +++ b/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 用户登录