mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-04-26 19:46:57 +08:00
Error code standardization
This commit is contained in:
parent
be1bf240ad
commit
6201e5c206
@ -25,7 +25,7 @@ func (f *FriendChecker) GetFriendsInfo(ctx context.Context, ownerUserID, friendU
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
r, err := friend.NewFriendClient(cc).GetPaginationFriends(ctx, &friend.GetPaginationFriendsReq{OwnerUserID: ownerUserID, FriendUserIDs: []string{friendUserID}})
|
r, err := friend.NewFriendClient(cc).GetDesignatedFriends(ctx, &friend.GetDesignatedFriendsReq{OwnerUserID: ownerUserID, FriendUserIDs: []string{friendUserID}})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -67,7 +67,7 @@ func (f *FriendChecker) GetAllPageFriends(ctx context.Context, ownerUserID strin
|
|||||||
if tmp.Total == int32(len(resp)) {
|
if tmp.Total == int32(len(resp)) {
|
||||||
return resp, nil
|
return resp, nil
|
||||||
}
|
}
|
||||||
return nil, constant.ErrData.Wrap("total != resp, but result is nil")
|
return nil, constant.ErrData.Wrap("The total number of results and expectations are different, but result is nil")
|
||||||
}
|
}
|
||||||
resp = append(resp, tmp.FriendsInfo...)
|
resp = append(resp, tmp.FriendsInfo...)
|
||||||
page++
|
page++
|
||||||
|
@ -126,8 +126,8 @@ func (u *UserDatabase) UpdateByMap(ctx context.Context, userID string, args map[
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取,如果没找到,不返回错误
|
// 获取,如果没找到,不返回错误
|
||||||
func (u *UserDatabase) Page(ctx context.Context, showNumber, pageNumber int32) (users []*relation.UserModel, count int64, err error) {
|
func (u *UserDatabase) Page(ctx context.Context, pageNumber, showNumber int32) (users []*relation.UserModel, count int64, err error) {
|
||||||
return u.userDB.Page(ctx, showNumber, pageNumber)
|
return u.userDB.Page(ctx, pageNumber, showNumber)
|
||||||
}
|
}
|
||||||
|
|
||||||
// userIDs是否存在 只要有一个存在就为true
|
// userIDs是否存在 只要有一个存在就为true
|
||||||
@ -142,6 +142,21 @@ func (u *UserDatabase) IsExist(ctx context.Context, userIDs []string) (exist boo
|
|||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *UserDatabase) GetAllUserID(ctx context.Context) ([]string, error) {
|
func (u *UserDatabase) GetAllUserID(ctx context.Context) (userIDs []string, err error) {
|
||||||
return u.userDB.GetAllUserID(ctx)
|
pageNumber := int32(0)
|
||||||
|
for {
|
||||||
|
tmp, total, err := u.userDB.PageUserID(ctx, pageNumber, constant.ShowNumber)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(tmp) == 0 {
|
||||||
|
if total == int64(len(userIDs)) {
|
||||||
|
return userIDs, nil
|
||||||
|
}
|
||||||
|
return nil, constant.ErrData.Wrap("The total number of results and expectations are different, but result is nil")
|
||||||
|
}
|
||||||
|
userIDs = append(userIDs, tmp...)
|
||||||
|
pageNumber++
|
||||||
|
}
|
||||||
|
return userIDs, nil
|
||||||
}
|
}
|
||||||
|
@ -73,11 +73,14 @@ func (u *UserGorm) Page(ctx context.Context, pageNumber, showNumber int32) (user
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 获取所有用户ID
|
// 获取所有用户ID
|
||||||
func (u *UserGorm) GetAllUserID(ctx context.Context) (userIDs []string, err error) {
|
func (u *UserGorm) PageUserID(ctx context.Context, pageNumber, showNumber int32) (userIDs []string, count int64, err error) {
|
||||||
defer func() {
|
defer func() {
|
||||||
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "userIDs", userIDs)
|
tracelog.SetCtxDebug(ctx, utils.GetFuncName(1), err, "pageNumber", pageNumber, "showNumber", showNumber, "userIDs", userIDs, "count", count)
|
||||||
}()
|
}()
|
||||||
|
err = utils.Wrap(u.DB.Model(&relation.UserModel{}).Count(&count).Error, "")
|
||||||
err = u.DB.Pluck("user_id", &userIDs).Error
|
if err != nil {
|
||||||
return userIDs, err
|
return
|
||||||
|
}
|
||||||
|
err = u.DB.Limit(int(showNumber)).Offset(int(pageNumber*showNumber)).Pluck("user_id", &userIDs).Error
|
||||||
|
return userIDs, count, err
|
||||||
}
|
}
|
||||||
|
@ -38,5 +38,5 @@ type UserModelInterface interface {
|
|||||||
Take(ctx context.Context, userID string) (user *UserModel, err error)
|
Take(ctx context.Context, userID string) (user *UserModel, err error)
|
||||||
// 获取用户信息 不存在,不返回错误
|
// 获取用户信息 不存在,不返回错误
|
||||||
Page(ctx context.Context, pageNumber, showNumber int32) (users []*UserModel, count int64, err error)
|
Page(ctx context.Context, pageNumber, showNumber int32) (users []*UserModel, count int64, err error)
|
||||||
GetAllUserID(ctx context.Context) (userIDs []string, err error)
|
PageUserID(ctx context.Context, pageNumber, showNumber int32) (userIDs []string, count int64, err error)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user