pull/351/head
wangchuxiao 2 years ago
parent 49f05d334d
commit 9f4c367249

@ -596,6 +596,7 @@ func (s *adminCMSServer) GetUserFriends(_ context.Context, req *pbAdminCMS.GetUs
friend, err := imdb.GetFriendByIDCMS(req.UserID, req.FriendUserID)
if err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err, req.UserID, req.FriendUserID)
return resp, nil
}
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserID, req.FriendUserID)
@ -604,14 +605,17 @@ func (s *adminCMSServer) GetUserFriends(_ context.Context, req *pbAdminCMS.GetUs
return resp, nil
}
friendList = append(friendList, friend)
resp.FriendNums = 1
} else {
friendList, err = imdb.GetUserFriendsCMS(req.UserID, req.FriendUserName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
var count int64
friendList, count, err = imdb.GetUserFriendsCMS(req.UserID, req.FriendUserName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
if err != nil {
log.NewError(req.OperationID, utils.GetSelfFuncName(), err.Error(), req.UserID, req.FriendUserName, req.Pagination.PageNumber, req.Pagination.ShowNumber)
resp.CommonResp.ErrCode = constant.ErrDB.ErrCode
resp.CommonResp.ErrMsg = err.Error()
return resp, nil
}
resp.FriendNums = int32(count)
}
for _, v := range friendList {
friendInfo := &server_api_params.FriendInfo{}

@ -59,7 +59,7 @@ type FriendUser struct {
Nickname string `gorm:"column:name;size:255"`
}
func GetUserFriendsCMS(ownerUserID, friendUserName string, pageNumber, showNumber int32) (friendUserList []*FriendUser, err error) {
func GetUserFriendsCMS(ownerUserID, friendUserName string, pageNumber, showNumber int32) (friendUserList []*FriendUser, count int64, err error) {
db := db.DB.MysqlDB.DefaultGormDB().Table("friends").
Select("friends.*, users.name").
Where("friends.owner_user_id=?", ownerUserID).Limit(int(showNumber)).
@ -68,6 +68,9 @@ func GetUserFriendsCMS(ownerUserID, friendUserName string, pageNumber, showNumbe
if friendUserName != "" {
db = db.Where("users.name like ?", fmt.Sprintf("%%%s%%", friendUserName))
}
if err = db.Count(&count).Error; err != nil {
return
}
err = db.Find(&friendUserList).Error
return
}

Loading…
Cancel
Save