Skip to content

Commit

Permalink
fix: 添加用户搜索缺少的信息,实现用户点赞/收藏/评论时给作者增加热度 (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lansongxx authored Apr 11, 2024
1 parent eca2e4e commit 1b33685
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 12 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

## 2024-04-11

### 🐛 Bug Fixes | Bug 修复

* 添加用户搜索缺少的信息

* 实现用户点赞/收藏/评论时给作者增加热度

## 2024-04-10

### ✨ Features | 新功能
Expand All @@ -9,6 +17,8 @@

* 修复帖子修改不填标签500的BUG

* 添加搜索用户缺少的信息

## 2024-04-09

### ✨ Features | 新功能
Expand Down
34 changes: 31 additions & 3 deletions biz/application/service/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ func (s *UserService) GetUserDetail(ctx context.Context, _ *core_api.GetUserDeta

func (s *UserService) SearchUser(ctx context.Context, req *core_api.SearchUserReq) (resp *core_api.SearchUserResp, err error) {
resp = new(core_api.SearchUserResp)
userData, err := adaptor.ExtractUserMeta(ctx)
if err != nil {
return resp, consts.ErrNotAuthentication
}

users, err := s.CloudMindContent.GetUsers(ctx, &content.GetUsersReq{
SearchOption: &content.SearchOption{
Expand All @@ -209,9 +213,33 @@ func (s *UserService) SearchUser(ctx context.Context, req *core_api.SearchUserRe
if err != nil {
return resp, err
}
resp.Users = lo.Map[*content.User, *core_api.User](users.Users, func(user *content.User, _ int) *core_api.User {
return convertor.UserDetailToUser(user)
})
resp.Users = make([]*core_api.User, 0, len(users.Users))

if err = mr.Finish(lo.Map[*content.User](users.Users, func(user *content.User, i int) func() error {
return func() error {
resp.Users[i] = &core_api.User{
UserId: user.UserId,
Name: user.Name,
Url: user.Url,
Labels: user.Labels,
Description: user.Description,
}
if err = mr.Finish(func() error {
if userData.GetUserId() != user.UserId && userData.GetUserId() != "" {
s.UserDomainService.LoadFollowed(ctx, &resp.Users[i].Followed, userData.UserId, user.UserId)
}
return nil
}, func() error {
s.UserDomainService.LoadFollowedCount(ctx, &resp.Users[i].FollowedCount, user.UserId)
return nil
}); err != nil {
return err
}
return nil
}
})...); err != nil {
return resp, err
}
resp.LastToken = users.LastToken
return resp, nil
}
10 changes: 10 additions & 0 deletions biz/domain/service/relation.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ func (s *RelationDomainService) CreateRelation(ctx context.Context, r *core_api.
return err
}

if r.RelationType == core_api.RelationType_LikeRelationType || r.RelationType == core_api.RelationType_CollectRelationType || r.RelationType == core_api.RelationType_CommentRelationType {
if _, err = s.CloudMindContent.IncrHotValue(ctx, &content.IncrHotValueReq{
Action: content.Action(r.RelationType),
HotId: userId,
TargetType: content.TargetType_UserType,
}); err != nil {
return err
}

}
// 创建通知
msg, _ := sonic.Marshal(Msg{
FromName: userinfo.Name,
Expand Down
9 changes: 0 additions & 9 deletions biz/infrastructure/convertor/convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,6 @@ func CoreSubjectToSubject(req *core_api.Subject) *platform.Subject {
}
}

func UserDetailToUser(req *content.User) *core_api.User {
return &core_api.User{
UserId: req.UserId,
Name: req.Name,
Url: req.Url,
Labels: req.Labels,
}
}

func MakePaginationOptions(limit, offset *int64, lastToken *string, backward *bool) *basic.PaginationOptions {
return &basic.PaginationOptions{
Limit: limit,
Expand Down

0 comments on commit 1b33685

Please sign in to comment.