Skip to content

Commit

Permalink
完善评论rpc逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
wt993638658 committed Feb 22, 2023
1 parent de9b4ce commit b7f3ea2
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 13 deletions.
25 changes: 20 additions & 5 deletions biz/handler/interaction/comment_list_server.go

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

30 changes: 26 additions & 4 deletions biz/handler/interaction/comment_server.go

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

45 changes: 41 additions & 4 deletions kitex_server/interaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,22 @@ func AddFavorite(ctx context.Context, uid int64, vid int64) (*interaction.Favori
StatusMsg: resp.BaseResp.StatusMsg,
}, nil
}

func CommentAction(ctx context.Context, uid int64, vid int64, req interaction.CommentReq) (*interaction.CommentResp, error) {
resp, err := CommentClient.CommentMethod(ctx, &comment.CommentReq{
UserId: uid,
VideoId: vid,
ActionType: req.ActionType,
CommentText: req.CommentText,
CommentId: req.CommentID,
})
if err != nil {
return nil, errno.RPCErr
}
return &interaction.CommentResp{
StatusCode: resp.StatusCode,
StatusMsg: &resp.StatusMsg,
}, nil
}
func DeleteFavorite(ctx context.Context, uid int64, vid int64) (*interaction.FavoriteResp, error) {
resp, err := FavoriteClient.FavoriteMethod(ctx, &favorite.FavoriteReq{
UserId: uid,
Expand All @@ -49,15 +64,15 @@ func GetFavoriteList(ctx context.Context, uid int64) (favorites *interaction.Fav
UserId: uid,
})
if err != nil {
return nil, errno.RPCErr.WithMessage(err.Error())
return nil, err
}
favoriteIdList := favoriteListRes.VideoIdList
videosResp, err := Videoclient.GetVideoSetByIdSetMethod(
ctx, &videomicro.GetVideoSetByIdSetReq{
IdSet: favoriteIdList,
})
if err != nil {
return nil, errno.RPCErr.WithMessage(err.Error())
return nil, err
}
videos := videosResp.VideoSet
videoIdList := make([]int64, 0)
Expand All @@ -66,6 +81,10 @@ func GetFavoriteList(ctx context.Context, uid int64) (favorites *interaction.Fav
videoIdList = append(videoIdList, v.Id)
authorIdList = append(authorIdList, v.AuthorId)
}

if err != nil {
return nil, err
}
resp, err := Userclient.GetUserSetByIdSetMethod(ctx, &usermicro.GetUserSetByIdSetReq{
IdSet: authorIdList,
})
Expand All @@ -79,14 +98,32 @@ func GetFavoriteList(ctx context.Context, uid int64) (favorites *interaction.Fav
}
isFollowMap, err := GetIsFollowMapByUserIdSet(uid, authorIdList)
if err != nil {
return nil, errno.RPCErr.WithMessage(err.Error())
return nil, err
}
return &interaction.FavoriteListResp{
StatusCode: favoriteListRes.BaseResp.StatusCode,
StatusMsg: favoriteListRes.BaseResp.StatusMsg,
VideoList: pack.Videos(videos, authors, isFavoriteMap, isFollowMap),
}, nil
}
func GetCommentList(ctx context.Context, uid int64, req interaction.CommentListReq) (favorites *interaction.CommentListResp, err error) {
resp, err := CommentClient.CommentListMethod(ctx, &comment.CommentListReq{
UserId: uid,
VideoId: req.VideoID,
})
if err != nil {
return nil, errno.RPCErr
}
comments, err := pack.Commentlist(resp.CommentList)
if err != nil {
return nil, errno.RPCErr
}
return &interaction.CommentListResp{
StatusCode: resp.StatusCode,
StatusMsg: &resp.StatusMsg,
CommentList: comments,
}, nil
}

func GetFavoriteRelation(ctx context.Context, uid int64, vid int64) (bool, error) {
res, err := FavoriteClient.FavoriteRelationMethod(ctx, &favorite.FavoriteRelationReq{
Expand Down
26 changes: 26 additions & 0 deletions pack/comment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package pack

import (
"github.com/ClubWeGo/commentmicro/kitex_gen/comment"
"github.com/ClubWeGo/douyin/biz/model/core"
"github.com/ClubWeGo/douyin/biz/model/interaction"
)

func Commentlist(cs []*comment.Comment) ([]*interaction.Comment, error) {
comments := make([]*interaction.Comment, 0)
for _, v := range cs {
comments = append(comments, &interaction.Comment{
ID: v.Id,
User: &core.User{
ID: v.Id,
Name: v.User.Name,
FollowCount: *v.User.FollowCount,
FollowerCount: *v.User.FollowerCount,
IsFollow: v.User.IsFollow,
},
Content: v.Content,
CreateDate: v.CreateDate,
})
}
return comments, nil
}

0 comments on commit b7f3ea2

Please sign in to comment.