Skip to content

Commit

Permalink
Merge branch 'main' of github.com:CloudStriver/cloudmind-core-api int…
Browse files Browse the repository at this point in the history
…o main
  • Loading branch information
Lansongxx committed Apr 15, 2024
2 parents c2c6de3 + 3a43fcc commit 28d0ba8
Show file tree
Hide file tree
Showing 9 changed files with 1,041 additions and 934 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

### ✨ Features | 新功能

* 完善查询用户评论列表中的评论信息


## 2024-04-12

### ✨ Features | 新功能

* 新增评论区评论块列表查询


Expand Down
901 changes: 463 additions & 438 deletions biz/application/dto/cloudmind/core_api/common.pb.go

Large diffs are not rendered by default.

832 changes: 416 additions & 416 deletions biz/application/dto/cloudmind/core_api/platform.pb.go

Large diffs are not rendered by default.

169 changes: 94 additions & 75 deletions biz/application/dto/platform/common.pb.go

Large diffs are not rendered by default.

23 changes: 19 additions & 4 deletions biz/application/service/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func (s *CommentService) GetComment(ctx context.Context, req *core_api.GetCommen
CreateAt: res.CreateTime,
Author: &core_api.SimpleUser{},
CommentRelation: &core_api.CommentRelation{},
ItemType: core_api.TargetType(res.Type),
}

_ = mr.Finish(func() error {
Expand All @@ -87,6 +88,11 @@ func (s *CommentService) GetComment(ctx context.Context, req *core_api.GetCommen

func (s *CommentService) GetComments(ctx context.Context, req *core_api.GetCommentsReq) (resp *core_api.GetCommentsResp, err error) {
resp = new(core_api.GetCommentsResp)
userData, err := adaptor.ExtractUserMeta(ctx)
if err != nil || userData.GetUserId() == "" {
return resp, consts.ErrNotAuthentication
}

var res *platform.GetCommentListResp
p := convertor.MakePaginationOptions(req.Limit, req.Offset, req.LastToken, req.Backward)
if res, err = s.Platform.GetCommentList(ctx, &platform.GetCommentListReq{
Expand Down Expand Up @@ -120,6 +126,14 @@ func (s *CommentService) GetComments(ctx context.Context, req *core_api.GetComme
}, func() error {
s.CommentDomainService.LoadLabels(ctx, &c.Labels, item.Labels) // 标签集
return nil
}, func() error {
switch item.Type {
case int64(core_api.TargetType_FileType):
s.CommentDomainService.LoadFile(ctx, &c.ItemTitle, &c.ItemUserId, item.SubjectId)
case int64(core_api.TargetType_PostType):
s.CommentDomainService.LoadPost(ctx, &c.ItemTitle, &c.ItemUserId, item.SubjectId)
}
return nil
})
return c
})
Expand All @@ -141,9 +155,9 @@ func (s *CommentService) GetCommentBlocks(ctx context.Context, req *core_api.Get
}

resp.CommentBlocks = lo.Map(res.CommentBlocks, func(item *platform.CommentBlock, _ int) *core_api.CommentBlock {
var rootComment *core_api.Comment
var rootComment *core_api.CommentNode
if item.RootComment != nil {
rootComment = convertor.CommentToCoreComment(item.RootComment)
rootComment = convertor.CommentToCoreCommentNode(item.RootComment)
_ = mr.Finish(func() error {
s.CommentDomainService.LoadLikeCount(ctx, &rootComment.Like, rootComment.CommentId) // 点赞量
return nil
Expand All @@ -161,8 +175,8 @@ func (s *CommentService) GetCommentBlocks(ctx context.Context, req *core_api.Get
return nil
})
}
comments := lo.Map(item.ReplyList.Comments, func(comment *platform.Comment, _ int) *core_api.Comment {
c := convertor.CommentToCoreComment(comment)
comments := lo.Map(item.ReplyList.Comments, func(comment *platform.Comment, _ int) *core_api.CommentNode {
c := convertor.CommentToCoreCommentNode(comment)
_ = mr.Finish(func() error {
s.CommentDomainService.LoadLikeCount(ctx, &c.Like, c.CommentId) // 点赞量
return nil
Expand Down Expand Up @@ -215,6 +229,7 @@ func (s *CommentService) CreateComment(ctx context.Context, req *core_api.Create
AtUserId: req.AtUserId,
Content: req.Content,
Meta: req.Meta,
Type: int64(req.ItemType),
}); err != nil {
return resp, err
}
Expand Down
18 changes: 18 additions & 0 deletions biz/domain/service/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

type ICommentDomainService interface {
LoadAuthor(ctx context.Context, c *core_api.SimpleUser, userId string)
LoadFile(ctx context.Context, description, userId *string, id string)
LoadPost(ctx context.Context, title, userId *string, id string)
LoadLikeCount(ctx context.Context, c *int64, id string)
LoadHateCount(ctx context.Context, c *int64, id string)
LoadLiked(ctx context.Context, c *core_api.CommentRelation, id, userId string)
Expand Down Expand Up @@ -40,6 +42,22 @@ func (s *CommentDomainService) LoadAuthor(ctx context.Context, c *core_api.Simpl
}
}

func (s *CommentDomainService) LoadFile(ctx context.Context, description, userId *string, id string) {
getRes, err := s.CloudMindUser.GetPublicFile(ctx, &content.GetPublicFileReq{FileId: id})
if err == nil {
*description = getRes.Description
*userId = getRes.UserId
}
}

func (s *CommentDomainService) LoadPost(ctx context.Context, title, userId *string, id string) {
getRes, err := s.CloudMindUser.GetPost(ctx, &content.GetPostReq{PostId: id})
if err == nil {
*title = getRes.Title
*userId = getRes.UserId
}
}

func (s *CommentDomainService) LoadLikeCount(ctx context.Context, c *int64, id string) {
getRelationCountResp, err := s.Platform.GetRelationCount(ctx, &platform.GetRelationCountReq{
RelationFilterOptions: &platform.GetRelationCountReq_ToFilterOptions{
Expand Down
19 changes: 19 additions & 0 deletions biz/infrastructure/convertor/convertor.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,25 @@ func CommentToCoreComment(req *platform.Comment) *core_api.Comment {
CreateTime: req.CreateTime,
Author: &core_api.SimpleUser{},
CommentRelation: &core_api.CommentRelation{},
ItemType: core_api.TargetType(req.Type),
}
}

func CommentToCoreCommentNode(req *platform.Comment) *core_api.CommentNode {
return &core_api.CommentNode{
CommentId: req.CommentId,
SubjectId: req.SubjectId,
RootId: req.RootId,
FatherId: req.FatherId,
Count: req.Count,
State: req.State,
Attrs: req.Attrs,
AtUserId: req.AtUserId,
Content: req.Content,
Meta: req.Meta,
CreateTime: req.CreateTime,
Author: &core_api.SimpleUser{},
CommentRelation: &core_api.CommentRelation{},
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
github.com/CloudStriver/cloudmind-mq v1.0.12-0.20240406143558-b7090c0fbb80
github.com/CloudStriver/go-pkg v0.0.0-20240329084540-20ca37a52fea
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240413084243-a8d7e75059be
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240414104057-eaf6315cb043
github.com/bytedance/sonic v1.10.2
github.com/cloudwego/hertz v0.7.3
github.com/golang-jwt/jwt/v4 v4.5.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ github.com/CloudStriver/go-pkg v0.0.0-20240329084540-20ca37a52fea h1:f+wmV1f8yaO
github.com/CloudStriver/go-pkg v0.0.0-20240329084540-20ca37a52fea/go.mod h1:SsAxWs5EIcaDE/0e5buoFOWsM4lTvFZhySkV68+RT3g=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240413084243-a8d7e75059be h1:HddeenNcxzNp1CCpxmFRxJlZjKEy8M//Clb7T38gef0=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240413084243-a8d7e75059be/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240414082236-a2f4391d68a2 h1:ZlZ3HnW1/rdTPwuoB2ynmj9rnAEmHBouHzguxMnN4pc=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240414082236-a2f4391d68a2/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240414104057-eaf6315cb043 h1:l6TWqGYAQVmWoWAmCywgKxw0lOi+p++pWiCkDIsXaNU=
github.com/CloudStriver/service-idl-gen-go v0.0.0-20240414104057-eaf6315cb043/go.mod h1:chtR82RvfrjUujTGWROSCNAwF9Lh/U959k34bXIDvBI=
github.com/DATA-DOG/go-sqlmock v1.5.0/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
Expand Down

0 comments on commit 28d0ba8

Please sign in to comment.