mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-03 02:42:19 +08:00
fix pageFindUser
This commit is contained in:
parent
fa9cf44eb0
commit
920d215576
3
go.mod
3
go.mod
@ -156,3 +156,6 @@ require (
|
|||||||
golang.org/x/crypto v0.14.0 // indirect
|
golang.org/x/crypto v0.14.0 // indirect
|
||||||
gopkg.in/ini.v1 v1.67.0 // indirect
|
gopkg.in/ini.v1 v1.67.0 // indirect
|
||||||
)
|
)
|
||||||
|
replace (
|
||||||
|
github.com/OpenIMSDK/protocol v0.0.47 => github.com/AndrewZuo01/protocol v0.0.0-20240112093520-fd9c53e27b94
|
||||||
|
)
|
||||||
@ -229,11 +229,20 @@ func (s *userServer) AccountCheck(ctx context.Context, req *pbuser.AccountCheckR
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPaginationUsersReq) (resp *pbuser.GetPaginationUsersResp, err error) {
|
func (s *userServer) GetPaginationUsers(ctx context.Context, req *pbuser.GetPaginationUsersReq) (resp *pbuser.GetPaginationUsersResp, err error) {
|
||||||
|
if req.UserID == "" && req.UserName == "" {
|
||||||
total, users, err := s.PageFindUser(ctx, constant.IMOrdinaryUser, constant.AppOrdinaryUsers, req.Pagination)
|
total, users, err := s.PageFindUser(ctx, constant.IMOrdinaryUser, constant.AppOrdinaryUsers, req.Pagination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &pbuser.GetPaginationUsersResp{Total: int32(total), Users: convert.UsersDB2Pb(users)}, err
|
return &pbuser.GetPaginationUsersResp{Total: int32(total), Users: convert.UsersDB2Pb(users)}, err
|
||||||
|
} else {
|
||||||
|
total, users, err := s.PageFindUserWithKeyword(ctx, constant.IMOrdinaryUser, constant.AppOrdinaryUsers, req.UserID, req.UserName, req.Pagination)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &pbuser.GetPaginationUsersResp{Total: int32(total), Users: convert.UsersDB2Pb(users)}, err
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *userServer) UserRegister(ctx context.Context, req *pbuser.UserRegisterReq) (resp *pbuser.UserRegisterResp, err error) {
|
func (s *userServer) UserRegister(ctx context.Context, req *pbuser.UserRegisterReq) (resp *pbuser.UserRegisterResp, err error) {
|
||||||
|
|||||||
@ -50,6 +50,8 @@ type UserDatabase interface {
|
|||||||
UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
|
UpdateByMap(ctx context.Context, userID string, args map[string]any) (err error)
|
||||||
// FindUser
|
// FindUser
|
||||||
PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
|
PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
|
||||||
|
//FindUser with keyword
|
||||||
|
PageFindUserWithKeyword(ctx context.Context, level1 int64, level2 int64, userID string, userName string, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
|
||||||
// Page If not found, no error is returned
|
// Page If not found, no error is returned
|
||||||
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
|
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error)
|
||||||
// IsExist true as long as one exists
|
// IsExist true as long as one exists
|
||||||
@ -188,6 +190,9 @@ func (u *userDatabase) Page(ctx context.Context, pagination pagination.Paginatio
|
|||||||
func (u *userDatabase) PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
|
func (u *userDatabase) PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
|
||||||
return u.userDB.PageFindUser(ctx, level1, level2, pagination)
|
return u.userDB.PageFindUser(ctx, level1, level2, pagination)
|
||||||
}
|
}
|
||||||
|
func (u *userDatabase) PageFindUserWithKeyword(ctx context.Context, level1 int64, level2 int64, userID, userName string, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
|
||||||
|
return u.userDB.PageFindUserWithKeyword(ctx, level1, level2, userID, userName, pagination)
|
||||||
|
}
|
||||||
|
|
||||||
// IsExist Does userIDs exist? As long as there is one, it will be true.
|
// IsExist Does userIDs exist? As long as there is one, it will be true.
|
||||||
func (u *userDatabase) IsExist(ctx context.Context, userIDs []string) (exist bool, err error) {
|
func (u *userDatabase) IsExist(ctx context.Context, userIDs []string) (exist bool, err error) {
|
||||||
|
|||||||
@ -88,6 +88,29 @@ func (u *UserMgo) PageFindUser(ctx context.Context, level1 int64, level2 int64,
|
|||||||
|
|
||||||
return mgoutil.FindPage[*relation.UserModel](ctx, u.coll, query, pagination)
|
return mgoutil.FindPage[*relation.UserModel](ctx, u.coll, query, pagination)
|
||||||
}
|
}
|
||||||
|
func (u *UserMgo) PageFindUserWithKeyword(ctx context.Context, level1 int64, level2 int64, userID string, userName string, pagination pagination.Pagination) (count int64, users []*relation.UserModel, err error) {
|
||||||
|
// Initialize the base query with level conditions
|
||||||
|
query := bson.M{
|
||||||
|
"$and": []bson.M{
|
||||||
|
{"app_manager_level": bson.M{"$in": []int64{level1, level2}}},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add userID and userName conditions to the query if they are provided
|
||||||
|
if userID != "" || userName != "" {
|
||||||
|
userConditions := []bson.M{}
|
||||||
|
if userID != "" {
|
||||||
|
userConditions = append(userConditions, bson.M{"user_id": userID})
|
||||||
|
}
|
||||||
|
if userName != "" {
|
||||||
|
userConditions = append(userConditions, bson.M{"nickname": userName})
|
||||||
|
}
|
||||||
|
query["$and"] = append(query["$and"].([]bson.M), bson.M{"$or": userConditions})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Perform the paginated search
|
||||||
|
return mgoutil.FindPage[*relation.UserModel](ctx, u.coll, query, pagination)
|
||||||
|
}
|
||||||
|
|
||||||
func (u *UserMgo) GetAllUserID(ctx context.Context, pagination pagination.Pagination) (int64, []string, error) {
|
func (u *UserMgo) GetAllUserID(ctx context.Context, pagination pagination.Pagination) (int64, []string, error) {
|
||||||
return mgoutil.FindPage[string](ctx, u.coll, bson.M{}, pagination, options.Find().SetProjection(bson.M{"_id": 0, "user_id": 1}))
|
return mgoutil.FindPage[string](ctx, u.coll, bson.M{}, pagination, options.Find().SetProjection(bson.M{"_id": 0, "user_id": 1}))
|
||||||
|
|||||||
@ -57,6 +57,7 @@ type UserModelInterface interface {
|
|||||||
TakeByNickname(ctx context.Context, nickname string) (user []*UserModel, err error)
|
TakeByNickname(ctx context.Context, nickname string) (user []*UserModel, err error)
|
||||||
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
|
Page(ctx context.Context, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
|
||||||
PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
|
PageFindUser(ctx context.Context, level1 int64, level2 int64, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
|
||||||
|
PageFindUserWithKeyword(ctx context.Context, level1 int64, level2 int64, userID, userName string, pagination pagination.Pagination) (count int64, users []*UserModel, err error)
|
||||||
Exist(ctx context.Context, userID string) (exist bool, err error)
|
Exist(ctx context.Context, userID string) (exist bool, err error)
|
||||||
GetAllUserID(ctx context.Context, pagination pagination.Pagination) (count int64, userIDs []string, err error)
|
GetAllUserID(ctx context.Context, pagination pagination.Pagination) (count int64, userIDs []string, err error)
|
||||||
GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error)
|
GetUserGlobalRecvMsgOpt(ctx context.Context, userID string) (opt int, err error)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user