Skip to content

Commit

Permalink
Merge pull request #23 from zxhchime/master
Browse files Browse the repository at this point in the history
fix: http 好友列表
  • Loading branch information
zxhchime authored Feb 20, 2023
2 parents b2cc41d + e9b56ab commit 780cdf3
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 19 deletions.
30 changes: 29 additions & 1 deletion biz/handler/relation/friend_list_service.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 47 additions & 18 deletions kitex_server/relationservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/ClubWeGo/douyin/biz/model/relation"
relationserver "github.com/ClubWeGo/relationmicro/kitex_gen/relation"
"github.com/prometheus/common/log"
"strconv"
)

// 响应码
Expand Down Expand Up @@ -98,20 +99,14 @@ func Follow(myUid int64, targetUid int64, actionType int32) error {
func GetFollowList(myUid int64, targetUid int64) ([]*core.User, error) {
resp, err := Relationclient.GetFollowListMethod(context.Background(), &relationserver.GetFollowListReq{MyId: &myUid, TargetId: targetUid})
if err != nil {
log.Errorf("rpc请求relation服务失败,详情:%s", err)
log.Errorf("GetFollowList rpc请求relation服务失败,详情:%s", err)
return nil, fmt.Errorf("本次请求失败,请稍后重试")
}
switch resp.StatusCode {
case SUCCESS:
userList := make([]*core.User, len(resp.UserList))
for i, user := range resp.GetUserList() {
userList[i] = &core.User{
ID: user.Id,
Name: user.Name,
FollowCount: user.FollowCount,
FollowerCount: user.FollowerCount,
IsFollow: user.IsFollow,
}
userList[i] = ConvertCoreUser(user)
}
return userList, nil
case ERROR:
Expand All @@ -130,20 +125,14 @@ func GetFollowList(myUid int64, targetUid int64) ([]*core.User, error) {
func GetFollowerList(myUid int64, targetUid int64) ([]*core.User, error) {
resp, err := Relationclient.GetFollowerListMethod(context.Background(), &relationserver.GetFollowerListReq{MyId: &myUid, TargetId: targetUid})
if err != nil {
log.Errorf("rpc请求relation服务失败,详情:%s", err)
log.Errorf("GetFollowerList rpc请求relation服务失败,详情:%s", err)
return nil, fmt.Errorf("本次请求失败,请稍后重试")
}
switch resp.StatusCode {
case SUCCESS:
userList := make([]*core.User, len(resp.UserList))
for i, user := range resp.GetUserList() {
userList[i] = &core.User{
ID: user.Id,
Name: user.Name,
FollowCount: user.FollowCount,
FollowerCount: user.FollowerCount,
IsFollow: user.IsFollow,
}
userList[i] = ConvertCoreUser(user)
}
return userList, nil
case ERROR:
Expand All @@ -158,8 +147,30 @@ func GetFollowerList(myUid int64, targetUid int64) ([]*core.User, error) {
return nil, fmt.Errorf("本次请求失败,请稍后重试")
}

func GetFriendList() {

// 好友列表
func GetFriendList(myUid int64, targetUid int64) ([]*core.User, error) {
resp, err := Relationclient.GetFriendListMethod(context.Background(), &relationserver.GetFriendListReq{MyUid: &myUid, TargetUid: targetUid})
if err != nil {
log.Errorf("GetFriendList rpc请求relation服务失败,详情:%s", err)
return nil, fmt.Errorf("本次请求失败,请稍后重试")
}
switch resp.StatusCode {
case SUCCESS:
userList := make([]*core.User, len(resp.FriendList))
for i, user := range resp.GetFriendList() {
userList[i] = ConvertCoreUser(user)
}
return userList, nil
case ERROR:
log.Errorf("relation服务异常,详情:%s", *resp.Msg)
break
case VERIFY:
log.Errorf("relation服务参数校验异常,详情:%s", *resp.Msg)
break
default:
break
}
return nil, fmt.Errorf("本次请求失败,请稍后重试")
}

// 校验关注参数
Expand All @@ -181,3 +192,21 @@ func VerifyFollowParam(myUid int64, targetUid int64, actionType int32) *string {
func GetIsFollowSetByUserIdSet(idSet []int64) (isFollowSet []int64, err error) {
return []int64{}, nil
}

// kitex relationserver 数据传输 user -> kitex 回显 core.User
func ConvertCoreUser(user *relationserver.User) *core.User {
totalFavourited := strconv.FormatInt(*user.TotalFavorited, 10)
return &core.User{
ID: user.Id,
Name: user.Name,
FollowCount: *user.FollowCount,
FollowerCount: *user.FollowerCount,
IsFollow: user.IsFollow,
Avatar: *user.Avatar,
BackgroundImage: *user.BackgroundImage,
Signature: *user.Signature,
TotalFavourited: totalFavourited,
WorkCount: *user.WorkCount,
FavoriteCount: *user.FavoriteCount,
}
}

0 comments on commit 780cdf3

Please sign in to comment.