正在显示
10 个修改的文件
包含
341 行增加
和
1 行删除
@@ -55,7 +55,7 @@ type ( | @@ -55,7 +55,7 @@ type ( | ||
55 | CountRead int `json:"countRead"` // 浏览数量 | 55 | CountRead int `json:"countRead"` // 浏览数量 |
56 | Show int `json:"show"` // 评论的展示状态(0显示、1不显示) | 56 | Show int `json:"show"` // 评论的展示状态(0显示、1不显示) |
57 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) | 57 | Edit int `json:"edit"` // 文章是否存在变更记录 (0 不存在 1存在) |
58 | - MeLoveFlag int `json:"meLoveFlag"` //当前人员对文章的点赞标识 | 58 | + MeLoveFlag int `json:"meLoveFlag"` //当前人员对文章的点赞标识 |
59 | } | 59 | } |
60 | ArticleSection { | 60 | ArticleSection { |
61 | Id int64 `json:"id"` //段落id | 61 | Id int64 `json:"id"` //段落id |
@@ -23,6 +23,14 @@ service Core { | @@ -23,6 +23,14 @@ service Core { | ||
23 | @doc "小程序填写文章的评论" | 23 | @doc "小程序填写文章的评论" |
24 | @handler MiniCreateArticleComment | 24 | @handler MiniCreateArticleComment |
25 | post /article_comment (MiniCreateArticleCommentRequest) returns (MiniCreateArticleCommentResponse) | 25 | post /article_comment (MiniCreateArticleCommentRequest) returns (MiniCreateArticleCommentResponse) |
26 | + | ||
27 | + @doc "小程序展示文章的评论列表" | ||
28 | + @handler MiniListArticleComment | ||
29 | + post /article_comment/list (MiniListArticleCommentRequest) returns (MiniListArticleCommentResponse) | ||
30 | + | ||
31 | + @doc "小程序展示单个文章的评论" | ||
32 | + @handler MiniGetArticleComment | ||
33 | + get /article_comment/:id (MiniGetArticleCommentRequest) returns (MiniGetArticleCommentResponse) | ||
26 | } | 34 | } |
27 | 35 | ||
28 | // | 36 | // |
@@ -72,5 +80,56 @@ type ( | @@ -72,5 +80,56 @@ type ( | ||
72 | CountUserLove int `json:"countUserLove"` // 用户点赞数量 | 80 | CountUserLove int `json:"countUserLove"` // 用户点赞数量 |
73 | CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | 81 | CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 |
74 | AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 | 82 | AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 |
83 | + CreatedAt int64 `json:"createdAt"` // | ||
84 | + } | ||
85 | +) | ||
86 | + | ||
87 | +// 小程序获取文章的评论列表 | ||
88 | +type ( | ||
89 | + MiniListArticleCommentRequest { | ||
90 | + Page int64 `json:"page"` | ||
91 | + Size int64 `json:"size"` | ||
92 | + CompanyId int64 `json:",optional"` | ||
93 | + SectionId int64 `json:"sectionId"` | ||
94 | + } | ||
95 | + MiniListArticleCommentResponse { | ||
96 | + Total int64 `json:"total"` | ||
97 | + List []ArticleCommentAndReply `json:"list"` | ||
98 | + } | ||
99 | + | ||
100 | + ArticleCommentAndReply { | ||
101 | + Comment ArticleCommentItem `json:"comment"` //评论 | ||
102 | + Reply []ArticleCommentItem `json:"reply"` //回复的评论 | ||
103 | + TotalReply int64 `json:"totalReply"` //回复的评论数量 | ||
104 | + } | ||
105 | + | ||
106 | + ArticleCommentItem { | ||
107 | + Id int64 `json:"id"` | ||
108 | + Pid int64 `json:"pid"` | ||
109 | + TopId int64 `json:"topId"` | ||
110 | + ArtitcleId int64 `json:"articleId"` // 文章id | ||
111 | + SectionId int64 `json:"sectionId"` // 段落id | ||
112 | + FromUserId int64 `json:"fromUserId"` // 填写评论的人 | ||
113 | + FromUser CommentAuthor `json:"fromUser"` // 填写评论的人 | ||
114 | + ToUserId int64 `json:"toUserId"` // 回复哪个人 | ||
115 | + ToUser CommentAuthor `json:"toUser"` // 回复哪个人 | ||
116 | + SectionContent string `json:"sectionContent"` // 引用的文章内容文本 | ||
117 | + CountReply int `json:"countReply"` // 回复数量 | ||
118 | + CountUserLove int `json:"countUserLove"` // 用户点赞数量 | ||
119 | + CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | ||
120 | + AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 | ||
121 | + CreatedAt int64 `json:"createdAt"` // | ||
122 | + MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 | ||
123 | + } | ||
124 | +) | ||
125 | + | ||
126 | +// 小程序获取单个文章的评论 | ||
127 | +type ( | ||
128 | + MiniGetArticleCommentRequest { | ||
129 | + CommentId int64 `json:"commentId"` | ||
130 | + CompanyId int64 `json:",optional"` | ||
131 | + } | ||
132 | + MiniGetArticleCommentResponse { | ||
133 | + ArticleCommentAndReply | ||
75 | } | 134 | } |
76 | ) | 135 | ) |
1 | +package comment | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
12 | +) | ||
13 | + | ||
14 | +func MiniGetArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | + return func(w http.ResponseWriter, r *http.Request) { | ||
16 | + var req types.MiniGetArticleCommentRequest | ||
17 | + if err := httpx.Parse(r, &req); err != nil { | ||
18 | + httpx.ErrorCtx(r.Context(), w, err) | ||
19 | + return | ||
20 | + } | ||
21 | + | ||
22 | + l := comment.NewMiniGetArticleCommentLogic(r.Context(), svcCtx) | ||
23 | + token := contextdata.GetUserTokenFromCtx(r.Context()) | ||
24 | + req.CompanyId = token.CompanyId | ||
25 | + resp, err := l.MiniGetArticleComment(&req) | ||
26 | + result.HttpResult(r, w, resp, err) | ||
27 | + } | ||
28 | +} |
1 | +package comment | ||
2 | + | ||
3 | +import ( | ||
4 | + "net/http" | ||
5 | + | ||
6 | + "github.com/zeromicro/go-zero/rest/httpx" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
10 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/contextdata" | ||
11 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result" | ||
12 | +) | ||
13 | + | ||
14 | +func MiniListArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
15 | + return func(w http.ResponseWriter, r *http.Request) { | ||
16 | + var req types.MiniListArticleCommentRequest | ||
17 | + if err := httpx.Parse(r, &req); err != nil { | ||
18 | + httpx.ErrorCtx(r.Context(), w, err) | ||
19 | + return | ||
20 | + } | ||
21 | + l := comment.NewMiniListArticleCommentLogic(r.Context(), svcCtx) | ||
22 | + token := contextdata.GetUserTokenFromCtx(r.Context()) | ||
23 | + req.CompanyId = token.CompanyId | ||
24 | + resp, err := l.MiniListArticleComment(&req) | ||
25 | + result.HttpResult(r, w, resp, err) | ||
26 | + } | ||
27 | +} |
@@ -30,6 +30,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -30,6 +30,16 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
30 | Path: "/article_comment", | 30 | Path: "/article_comment", |
31 | Handler: comment.MiniCreateArticleCommentHandler(serverCtx), | 31 | Handler: comment.MiniCreateArticleCommentHandler(serverCtx), |
32 | }, | 32 | }, |
33 | + { | ||
34 | + Method: http.MethodPost, | ||
35 | + Path: "/article_comment/list", | ||
36 | + Handler: comment.MiniListArticleCommentHandler(serverCtx), | ||
37 | + }, | ||
38 | + { | ||
39 | + Method: http.MethodGet, | ||
40 | + Path: "/article_comment/:id", | ||
41 | + Handler: comment.MiniGetArticleCommentHandler(serverCtx), | ||
42 | + }, | ||
33 | }, | 43 | }, |
34 | rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), | 44 | rest.WithJwt(serverCtx.Config.MiniAuth.AccessSecret), |
35 | rest.WithPrefix("/v1/mini"), | 45 | rest.WithPrefix("/v1/mini"), |
@@ -193,6 +193,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | @@ -193,6 +193,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | ||
193 | CountUserLove: 0, | 193 | CountUserLove: 0, |
194 | CountAdminLove: 0, | 194 | CountAdminLove: 0, |
195 | AtWho: []types.CommentAuthor{}, | 195 | AtWho: []types.CommentAuthor{}, |
196 | + CreatedAt: newComment.CreatedAt, | ||
196 | } | 197 | } |
197 | 198 | ||
198 | for _, val := range newComment.AtWho { | 199 | for _, val := range newComment.AtWho { |
1 | +package comment | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
8 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/interanl/pkg/domain" | ||
9 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/xerr" | ||
10 | + | ||
11 | + "github.com/zeromicro/go-zero/core/logx" | ||
12 | +) | ||
13 | + | ||
14 | +type MiniGetArticleCommentLogic struct { | ||
15 | + logx.Logger | ||
16 | + ctx context.Context | ||
17 | + svcCtx *svc.ServiceContext | ||
18 | +} | ||
19 | + | ||
20 | +func NewMiniGetArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniGetArticleCommentLogic { | ||
21 | + return &MiniGetArticleCommentLogic{ | ||
22 | + Logger: logx.WithContext(ctx), | ||
23 | + ctx: ctx, | ||
24 | + svcCtx: svcCtx, | ||
25 | + } | ||
26 | +} | ||
27 | + | ||
28 | +func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArticleCommentRequest) (resp *types.MiniGetArticleCommentResponse, err error) { | ||
29 | + var conn = l.svcCtx.DefaultDBConn() | ||
30 | + //获取主评论 | ||
31 | + commentInfo, err := l.svcCtx.ArticleCommentRepository.FindOne(l.ctx, conn, req.CommentId) | ||
32 | + if err != nil { | ||
33 | + return nil, xerr.NewErrMsgErr("获取评论信息失败", err) | ||
34 | + } | ||
35 | + if commentInfo.CompanyId != req.CompanyId { | ||
36 | + return nil, xerr.NewErrMsg("没有查看权限") | ||
37 | + } | ||
38 | + queryOption := domain.NewQueryOptions().MustWithKV("topId", commentInfo.Id).WithFindOnly() | ||
39 | + //获取回复的评论 | ||
40 | + _, replyCommenList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption) | ||
41 | + | ||
42 | + if err != nil { | ||
43 | + return nil, xerr.NewErrMsgErr("获取评论信息失败", err) | ||
44 | + } | ||
45 | + //TODO 获取我点赞的评论 | ||
46 | + | ||
47 | + //混合数据 | ||
48 | + commentResp := types.ArticleCommentItem{ | ||
49 | + Id: commentInfo.Id, | ||
50 | + Pid: commentInfo.Pid, | ||
51 | + TopId: commentInfo.TopId, | ||
52 | + ArtitcleId: commentInfo.ArticleId, | ||
53 | + SectionId: commentInfo.ArticleId, | ||
54 | + FromUserId: commentInfo.FromUserId, | ||
55 | + FromUser: types.CommentAuthor{ | ||
56 | + Id: commentInfo.FromUser.Id, | ||
57 | + Name: commentInfo.FromUser.Name, | ||
58 | + Avatar: commentInfo.FromUser.Avatar, | ||
59 | + Position: commentInfo.FromUser.Position, | ||
60 | + Company: commentInfo.FromUser.Company, | ||
61 | + }, | ||
62 | + ToUserId: commentInfo.ToUserId, | ||
63 | + ToUser: types.CommentAuthor{ | ||
64 | + Id: commentInfo.ToUser.Id, | ||
65 | + Name: commentInfo.ToUser.Name, | ||
66 | + Avatar: commentInfo.ToUser.Avatar, | ||
67 | + Position: commentInfo.ToUser.Position, | ||
68 | + Company: commentInfo.ToUser.Company, | ||
69 | + }, | ||
70 | + SectionContent: commentInfo.SectionContent, | ||
71 | + CountReply: commentInfo.CountReply, | ||
72 | + CountUserLove: commentInfo.CountUserLove, | ||
73 | + CountAdminLove: commentInfo.CountAdminLove, | ||
74 | + AtWho: []types.CommentAuthor{}, | ||
75 | + CreatedAt: commentInfo.CreatedAt, | ||
76 | + } | ||
77 | + for _, val := range commentInfo.AtWho { | ||
78 | + commentResp.AtWho = append(commentResp.AtWho, types.CommentAuthor{ | ||
79 | + Id: val.Id, | ||
80 | + Name: val.Name, | ||
81 | + Avatar: val.Avatar, | ||
82 | + Position: val.Position, | ||
83 | + Company: val.Company, | ||
84 | + }) | ||
85 | + } | ||
86 | + allReply := []types.ArticleCommentItem{} | ||
87 | + for _, val := range replyCommenList { | ||
88 | + reply := types.ArticleCommentItem{ | ||
89 | + Id: val.Id, | ||
90 | + Pid: val.Pid, | ||
91 | + TopId: val.TopId, | ||
92 | + ArtitcleId: val.ArticleId, | ||
93 | + SectionId: val.ArticleId, | ||
94 | + FromUserId: val.FromUserId, | ||
95 | + FromUser: types.CommentAuthor{ | ||
96 | + Id: val.FromUser.Id, | ||
97 | + Name: val.FromUser.Name, | ||
98 | + Avatar: val.FromUser.Avatar, | ||
99 | + Position: val.FromUser.Position, | ||
100 | + Company: val.FromUser.Company, | ||
101 | + }, | ||
102 | + ToUserId: val.ToUserId, | ||
103 | + ToUser: types.CommentAuthor{ | ||
104 | + Id: val.ToUser.Id, | ||
105 | + Name: val.ToUser.Name, | ||
106 | + Avatar: val.ToUser.Avatar, | ||
107 | + Position: val.ToUser.Position, | ||
108 | + Company: val.ToUser.Company, | ||
109 | + }, | ||
110 | + SectionContent: val.SectionContent, | ||
111 | + CountReply: val.CountReply, | ||
112 | + CountUserLove: val.CountUserLove, | ||
113 | + CountAdminLove: val.CountAdminLove, | ||
114 | + AtWho: []types.CommentAuthor{}, | ||
115 | + CreatedAt: val.CreatedAt, | ||
116 | + } | ||
117 | + for _, val2 := range val.AtWho { | ||
118 | + reply.AtWho = append(reply.AtWho, types.CommentAuthor{ | ||
119 | + Id: val2.Id, | ||
120 | + Name: val2.Name, | ||
121 | + Avatar: val2.Avatar, | ||
122 | + Position: val2.Position, | ||
123 | + Company: val2.Company, | ||
124 | + }) | ||
125 | + } | ||
126 | + } | ||
127 | + resp = &types.MiniGetArticleCommentResponse{ | ||
128 | + ArticleCommentAndReply: types.ArticleCommentAndReply{ | ||
129 | + Comment: commentResp, | ||
130 | + Reply: allReply, | ||
131 | + TotalReply: int64(len(replyCommenList)), | ||
132 | + }, | ||
133 | + } | ||
134 | + return | ||
135 | +} |
1 | +package comment | ||
2 | + | ||
3 | +import ( | ||
4 | + "context" | ||
5 | + | ||
6 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" | ||
7 | + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/types" | ||
8 | + | ||
9 | + "github.com/zeromicro/go-zero/core/logx" | ||
10 | +) | ||
11 | + | ||
12 | +type MiniListArticleCommentLogic struct { | ||
13 | + logx.Logger | ||
14 | + ctx context.Context | ||
15 | + svcCtx *svc.ServiceContext | ||
16 | +} | ||
17 | + | ||
18 | +func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniListArticleCommentLogic { | ||
19 | + return &MiniListArticleCommentLogic{ | ||
20 | + Logger: logx.WithContext(ctx), | ||
21 | + ctx: ctx, | ||
22 | + svcCtx: svcCtx, | ||
23 | + } | ||
24 | +} | ||
25 | + | ||
26 | +func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) { | ||
27 | + // todo: add your logic here and delete this line | ||
28 | + | ||
29 | + return | ||
30 | +} |
@@ -41,6 +41,53 @@ type MiniCreateArticleCommentResponse struct { | @@ -41,6 +41,53 @@ type MiniCreateArticleCommentResponse struct { | ||
41 | CountUserLove int `json:"countUserLove"` // 用户点赞数量 | 41 | CountUserLove int `json:"countUserLove"` // 用户点赞数量 |
42 | CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | 42 | CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 |
43 | AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 | 43 | AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 |
44 | + CreatedAt int64 `json:"createdAt"` // | ||
45 | +} | ||
46 | + | ||
47 | +type MiniListArticleCommentRequest struct { | ||
48 | + Page int64 `json:"page"` | ||
49 | + Size int64 `json:"size"` | ||
50 | + CompanyId int64 `json:",optional"` | ||
51 | + SectionId int64 `json:"sectionId"` | ||
52 | +} | ||
53 | + | ||
54 | +type MiniListArticleCommentResponse struct { | ||
55 | + Total int64 `json:"total"` | ||
56 | + List []ArticleCommentAndReply `json:"list"` | ||
57 | +} | ||
58 | + | ||
59 | +type ArticleCommentAndReply struct { | ||
60 | + Comment ArticleCommentItem `json:"comment"` //评论 | ||
61 | + Reply []ArticleCommentItem `json:"reply"` //回复的评论 | ||
62 | + TotalReply int64 `json:"totalReply"` //回复的评论数量 | ||
63 | +} | ||
64 | + | ||
65 | +type ArticleCommentItem struct { | ||
66 | + Id int64 `json:"id"` | ||
67 | + Pid int64 `json:"pid"` | ||
68 | + TopId int64 `json:"topId"` | ||
69 | + ArtitcleId int64 `json:"articleId"` // 文章id | ||
70 | + SectionId int64 `json:"sectionId"` // 段落id | ||
71 | + FromUserId int64 `json:"fromUserId"` // 填写评论的人 | ||
72 | + FromUser CommentAuthor `json:"fromUser"` // 填写评论的人 | ||
73 | + ToUserId int64 `json:"toUserId"` // 回复哪个人 | ||
74 | + ToUser CommentAuthor `json:"toUser"` // 回复哪个人 | ||
75 | + SectionContent string `json:"sectionContent"` // 引用的文章内容文本 | ||
76 | + CountReply int `json:"countReply"` // 回复数量 | ||
77 | + CountUserLove int `json:"countUserLove"` // 用户点赞数量 | ||
78 | + CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 | ||
79 | + AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 | ||
80 | + CreatedAt int64 `json:"createdAt"` // | ||
81 | + MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 | ||
82 | +} | ||
83 | + | ||
84 | +type MiniGetArticleCommentRequest struct { | ||
85 | + CommentId int64 `json:"commentId"` | ||
86 | + CompanyId int64 `json:",optional"` | ||
87 | +} | ||
88 | + | ||
89 | +type MiniGetArticleCommentResponse struct { | ||
90 | + ArticleCommentAndReply | ||
44 | } | 91 | } |
45 | 92 | ||
46 | type MessageSystemRequest struct { | 93 | type MessageSystemRequest struct { |
@@ -120,6 +120,9 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans | @@ -120,6 +120,9 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans | ||
120 | ) | 120 | ) |
121 | queryFunc := func() (interface{}, error) { | 121 | queryFunc := func() (interface{}, error) { |
122 | tx = tx.Model(&ms).Order("id desc") | 122 | tx = tx.Model(&ms).Order("id desc") |
123 | + if v, ok := queryOptions["topId"]; ok { | ||
124 | + tx = tx.Where("top_id", v) | ||
125 | + } | ||
123 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | 126 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { |
124 | return dms, tx.Error | 127 | return dms, tx.Error |
125 | } | 128 | } |
-
请 注册 或 登录 后发表评论