feat(user): 添加用户分页列表接口及通用查询封装

This commit is contained in:
unclesam committed 2026-07-07 23:42:14 +08:00
1 parent 50dc1b0f09
commit 1bca4808e9
11 files changed
+165 -10

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
package user_ser
import (
"EnGin/internal/db"
"EnGin/internal/ent"
"EnGin/internal/ent/user"
"EnGin/internal/service/common"
"context"
"entgo.io/ent/dialect/sql"
)
func GetUserListWithPage(ctx context.Context, usernameKey string, page, limit int) ([]*ent.User, int, error) {
return common.QueryList(ctx, db.Client.User.Query(), common.QueryOptions[*ent.UserQuery]{
Page: page,
Limit: limit,
Query: func(q *ent.UserQuery) *ent.UserQuery {
// 模糊匹配(编译期安全,杜绝拼写错误)
if usernameKey != "" {
q = q.Where(user.UsernameContains(usernameKey))
}
// 预加载关联角色,并按照创建时间倒序
return q.WithRoles().Order(user.ByCreatedAt(sql.OrderDesc()))
},
})
}