作者 tangxvhui

创建评论和评论详情,

@@ -52,9 +52,9 @@ type ( @@ -52,9 +52,9 @@ type (
52 type CommentAuthor { 52 type CommentAuthor {
53 Id int64 `json:"id"` // 人员id 53 Id int64 `json:"id"` // 人员id
54 Name string `json:"name"` // 人员的名字 54 Name string `json:"name"` // 人员的名字
55 - Avatar string `json:"avatar"` // 人员头像URL  
56 - Position string `json:"position"` // 职位  
57 - Company string `json:"company"` // 公司 55 + Avatar string `json:"avatar,optional"` // 人员头像URL
  56 + Position string `json:"position,optional"` // 职位
  57 + Company string `json:"company,optional"` // 公司
58 } 58 }
59 59
60 // 小程序填写文章的评论 60 // 小程序填写文章的评论
@@ -64,11 +64,15 @@ type ( @@ -64,11 +64,15 @@ type (
64 SectionId int64 `json:"sectionId"` // 段落id 64 SectionId int64 `json:"sectionId"` // 段落id
65 FromUserId int64 `json:",optional"` // 填写文章的人,服务端自动获取 65 FromUserId int64 `json:",optional"` // 填写文章的人,服务端自动获取
66 CompanyId int64 `json:",optional"` // 服务端自动获取 66 CompanyId int64 `json:",optional"` // 服务端自动获取
67 - Pid int64 `json:"commnet"` // 回复那个评论的id 67 + Pid int64 `json:"pid"` // 回复那个评论的id
68 Content string `json:"content"` // 评论的内容 68 Content string `json:"content"` // 评论的内容
69 - AtWho []int64 `json:"atWho"` // 填写评论时@的人 69 + AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
70 } 70 }
71 71
  72 + CommentAtWho {
  73 + Id int64 `json:"id"`
  74 + Name string `json:"name,optional"`
  75 + }
72 MiniCreateArticleCommentResponse { 76 MiniCreateArticleCommentResponse {
73 Id int64 `json:"id"` 77 Id int64 `json:"id"`
74 Pid int64 `json:"pid"` 78 Pid int64 `json:"pid"`
@@ -83,7 +87,7 @@ type ( @@ -83,7 +87,7 @@ type (
83 CountReply int `json:"countReply"` // 回复数量 87 CountReply int `json:"countReply"` // 回复数量
84 CountUserLove int `json:"countUserLove"` // 用户点赞数量 88 CountUserLove int `json:"countUserLove"` // 用户点赞数量
85 CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 89 CountAdminLove int `json:"countAdminLove"` // 运营点赞数量
86 - AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 90 + AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
87 CreatedAt int64 `json:"createdAt"` // 91 CreatedAt int64 `json:"createdAt"` //
88 } 92 }
89 ) 93 )
@@ -121,7 +125,7 @@ type ( @@ -121,7 +125,7 @@ type (
121 CountReply int `json:"countReply"` // 回复数量 125 CountReply int `json:"countReply"` // 回复数量
122 CountUserLove int `json:"countUserLove"` // 用户点赞数量 126 CountUserLove int `json:"countUserLove"` // 用户点赞数量
123 CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 127 CountAdminLove int `json:"countAdminLove"` // 运营点赞数量
124 - AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 128 + AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
125 CreatedAt int64 `json:"createdAt"` // 129 CreatedAt int64 `json:"createdAt"` //
126 MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞) 130 MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞)
127 } 131 }
@@ -130,7 +134,7 @@ type ( @@ -130,7 +134,7 @@ type (
130 // 小程序获取单个文章的评论 134 // 小程序获取单个文章的评论
131 type ( 135 type (
132 MiniGetArticleCommentRequest { 136 MiniGetArticleCommentRequest {
133 - CommentId int64 `path:"commentId"` 137 + CommentId int64 `path:"id"`
134 CompanyId int64 `path:",optional"` 138 CompanyId int64 `path:",optional"`
135 UserId int64 `path:",optional"` 139 UserId int64 `path:",optional"`
136 } 140 }
@@ -84,14 +84,17 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini @@ -84,14 +84,17 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
84 } 84 }
85 var atWhoList []*domain.User 85 var atWhoList []*domain.User
86 if len(req.AtWho) > 0 { 86 if len(req.AtWho) > 0 {
87 - queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", req.AtWho) 87 + uids := []int64{}
  88 + for _, val := range req.AtWho {
  89 + uids = append(uids, val.Id)
  90 + }
  91 + queryOption := domain.NewQueryOptions().WithFindOnly().WithKV("ids", uids)
88 _, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption) 92 _, atWhoList, err = l.svcCtx.UserRepository.Find(l.ctx, conn, queryOption)
89 if err != nil { 93 if err != nil {
90 return nil, xerr.NewErrMsgErr("检查@的人员失败", err) 94 return nil, xerr.NewErrMsgErr("检查@的人员失败", err)
91 } 95 }
92 } 96 }
93 // 处理文本内容 97 // 处理文本内容
94 - // content:=  
95 content := template.HTMLEscapeString(req.Content) 98 content := template.HTMLEscapeString(req.Content)
96 99
97 newComment := domain.ArticleComment{ 100 newComment := domain.ArticleComment{
@@ -178,7 +181,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini @@ -178,7 +181,7 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
178 Pid: newComment.Pid, 181 Pid: newComment.Pid,
179 TopId: newComment.TopId, 182 TopId: newComment.TopId,
180 ArtitcleId: newComment.ArticleId, 183 ArtitcleId: newComment.ArticleId,
181 - SectionId: newComment.ArticleId, 184 + SectionId: newComment.SectionId,
182 FromUserId: newComment.FromUserId, 185 FromUserId: newComment.FromUserId,
183 FromUser: types.CommentAuthor{ 186 FromUser: types.CommentAuthor{
184 Id: newComment.FromUser.Id, 187 Id: newComment.FromUser.Id,
@@ -199,17 +202,14 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini @@ -199,17 +202,14 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini
199 CountReply: 0, 202 CountReply: 0,
200 CountUserLove: 0, 203 CountUserLove: 0,
201 CountAdminLove: 0, 204 CountAdminLove: 0,
202 - AtWho: []types.CommentAuthor{}, 205 + AtWho: []types.CommentAtWho{},
203 CreatedAt: newComment.CreatedAt, 206 CreatedAt: newComment.CreatedAt,
204 } 207 }
205 208
206 for _, val := range newComment.AtWho { 209 for _, val := range newComment.AtWho {
207 - resp.AtWho = append(resp.AtWho, types.CommentAuthor{ 210 + resp.AtWho = append(resp.AtWho, types.CommentAtWho{
208 Id: val.Id, 211 Id: val.Id,
209 Name: val.Name, 212 Name: val.Name,
210 - Avatar: val.Avatar,  
211 - Position: val.Position,  
212 - Company: val.Company,  
213 }) 213 })
214 } 214 }
215 215
@@ -46,7 +46,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt @@ -46,7 +46,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
46 queryOption = domain.NewQueryOptions().WithFindOnly(). 46 queryOption = domain.NewQueryOptions().WithFindOnly().
47 MustWithKV("articleId", commentInfo.ArticleId). 47 MustWithKV("articleId", commentInfo.ArticleId).
48 MustWithKV("userId", req.UserId) 48 MustWithKV("userId", req.UserId)
49 - //TODO 获取我点赞的评论 49 + // 获取我点赞的评论
50 _, userFlagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption) 50 _, userFlagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption)
51 if err != nil { 51 if err != nil {
52 return nil, xerr.NewErrMsgErr("获取评论信息失败", err) 52 return nil, xerr.NewErrMsgErr("获取评论信息失败", err)
@@ -83,7 +83,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt @@ -83,7 +83,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
83 CountReply: commentInfo.CountReply, 83 CountReply: commentInfo.CountReply,
84 CountUserLove: commentInfo.CountUserLove, 84 CountUserLove: commentInfo.CountUserLove,
85 CountAdminLove: commentInfo.CountAdminLove, 85 CountAdminLove: commentInfo.CountAdminLove,
86 - AtWho: []types.CommentAuthor{}, 86 + AtWho: []types.CommentAtWho{},
87 CreatedAt: commentInfo.CreatedAt, 87 CreatedAt: commentInfo.CreatedAt,
88 MeLoveFlag: 0, 88 MeLoveFlag: 0,
89 } 89 }
@@ -91,12 +91,9 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt @@ -91,12 +91,9 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
91 commentResp.MeLoveFlag = 1 91 commentResp.MeLoveFlag = 1
92 } 92 }
93 for _, val := range commentInfo.AtWho { 93 for _, val := range commentInfo.AtWho {
94 - commentResp.AtWho = append(commentResp.AtWho, types.CommentAuthor{ 94 + commentResp.AtWho = append(commentResp.AtWho, types.CommentAtWho{
95 Id: val.Id, 95 Id: val.Id,
96 Name: val.Name, 96 Name: val.Name,
97 - Avatar: val.Avatar,  
98 - Position: val.Position,  
99 - Company: val.Company,  
100 }) 97 })
101 } 98 }
102 allReply := []types.ArticleCommentItem{} 99 allReply := []types.ArticleCommentItem{}
@@ -106,7 +103,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt @@ -106,7 +103,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
106 Pid: val.Pid, 103 Pid: val.Pid,
107 TopId: val.TopId, 104 TopId: val.TopId,
108 ArtitcleId: val.ArticleId, 105 ArtitcleId: val.ArticleId,
109 - SectionId: val.ArticleId, 106 + SectionId: val.SectionId,
110 FromUserId: val.FromUserId, 107 FromUserId: val.FromUserId,
111 FromUser: types.CommentAuthor{ 108 FromUser: types.CommentAuthor{
112 Id: val.FromUser.Id, 109 Id: val.FromUser.Id,
@@ -127,7 +124,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt @@ -127,7 +124,7 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
127 CountReply: val.CountReply, 124 CountReply: val.CountReply,
128 CountUserLove: val.CountUserLove, 125 CountUserLove: val.CountUserLove,
129 CountAdminLove: val.CountAdminLove, 126 CountAdminLove: val.CountAdminLove,
130 - AtWho: []types.CommentAuthor{}, 127 + AtWho: []types.CommentAtWho{},
131 CreatedAt: val.CreatedAt, 128 CreatedAt: val.CreatedAt,
132 MeLoveFlag: 0, 129 MeLoveFlag: 0,
133 } 130 }
@@ -135,14 +132,12 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt @@ -135,14 +132,12 @@ func (l *MiniGetArticleCommentLogic) MiniGetArticleComment(req *types.MiniGetArt
135 reply.MeLoveFlag = 1 132 reply.MeLoveFlag = 1
136 } 133 }
137 for _, val2 := range val.AtWho { 134 for _, val2 := range val.AtWho {
138 - reply.AtWho = append(reply.AtWho, types.CommentAuthor{ 135 + reply.AtWho = append(reply.AtWho, types.CommentAtWho{
139 Id: val2.Id, 136 Id: val2.Id,
140 Name: val2.Name, 137 Name: val2.Name,
141 - Avatar: val2.Avatar,  
142 - Position: val2.Position,  
143 - Company: val2.Company,  
144 }) 138 })
145 } 139 }
  140 + allReply = append(allReply, reply)
146 } 141 }
147 resp = &types.MiniGetArticleCommentResponse{ 142 resp = &types.MiniGetArticleCommentResponse{
148 ArticleCommentAndReply: types.ArticleCommentAndReply{ 143 ArticleCommentAndReply: types.ArticleCommentAndReply{
@@ -11,9 +11,9 @@ type MiniArticleCommentAtUserResponse struct { @@ -11,9 +11,9 @@ type MiniArticleCommentAtUserResponse struct {
11 type CommentAuthor struct { 11 type CommentAuthor struct {
12 Id int64 `json:"id"` // 人员id 12 Id int64 `json:"id"` // 人员id
13 Name string `json:"name"` // 人员的名字 13 Name string `json:"name"` // 人员的名字
14 - Avatar string `json:"avatar"` // 人员头像URL  
15 - Position string `json:"position"` // 职位  
16 - Company string `json:"company"` // 公司 14 + Avatar string `json:"avatar,optional"` // 人员头像URL
  15 + Position string `json:"position,optional"` // 职位
  16 + Company string `json:"company,optional"` // 公司
17 } 17 }
18 18
19 type MiniCreateArticleCommentRequest struct { 19 type MiniCreateArticleCommentRequest struct {
@@ -21,9 +21,14 @@ type MiniCreateArticleCommentRequest struct { @@ -21,9 +21,14 @@ type MiniCreateArticleCommentRequest struct {
21 SectionId int64 `json:"sectionId"` // 段落id 21 SectionId int64 `json:"sectionId"` // 段落id
22 FromUserId int64 `json:",optional"` // 填写文章的人,服务端自动获取 22 FromUserId int64 `json:",optional"` // 填写文章的人,服务端自动获取
23 CompanyId int64 `json:",optional"` // 服务端自动获取 23 CompanyId int64 `json:",optional"` // 服务端自动获取
24 - Pid int64 `json:"commnet"` // 回复那个评论的id 24 + Pid int64 `json:"pid"` // 回复那个评论的id
25 Content string `json:"content"` // 评论的内容 25 Content string `json:"content"` // 评论的内容
26 - AtWho []int64 `json:"atWho"` // 填写评论时@的人 26 + AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
  27 +}
  28 +
  29 +type CommentAtWho struct {
  30 + Id int64 `json:"id"`
  31 + Name string `json:"name,optional"`
27 } 32 }
28 33
29 type MiniCreateArticleCommentResponse struct { 34 type MiniCreateArticleCommentResponse struct {
@@ -40,7 +45,7 @@ type MiniCreateArticleCommentResponse struct { @@ -40,7 +45,7 @@ type MiniCreateArticleCommentResponse struct {
40 CountReply int `json:"countReply"` // 回复数量 45 CountReply int `json:"countReply"` // 回复数量
41 CountUserLove int `json:"countUserLove"` // 用户点赞数量 46 CountUserLove int `json:"countUserLove"` // 用户点赞数量
42 CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 47 CountAdminLove int `json:"countAdminLove"` // 运营点赞数量
43 - AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 48 + AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
44 CreatedAt int64 `json:"createdAt"` // 49 CreatedAt int64 `json:"createdAt"` //
45 } 50 }
46 51
@@ -76,13 +81,13 @@ type ArticleCommentItem struct { @@ -76,13 +81,13 @@ type ArticleCommentItem struct {
76 CountReply int `json:"countReply"` // 回复数量 81 CountReply int `json:"countReply"` // 回复数量
77 CountUserLove int `json:"countUserLove"` // 用户点赞数量 82 CountUserLove int `json:"countUserLove"` // 用户点赞数量
78 CountAdminLove int `json:"countAdminLove"` // 运营点赞数量 83 CountAdminLove int `json:"countAdminLove"` // 运营点赞数量
79 - AtWho []CommentAuthor `json:"atWho"` // 填写评论时@的人 84 + AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人
80 CreatedAt int64 `json:"createdAt"` // 85 CreatedAt int64 `json:"createdAt"` //
81 MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞) 86 MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞)
82 } 87 }
83 88
84 type MiniGetArticleCommentRequest struct { 89 type MiniGetArticleCommentRequest struct {
85 - CommentId int64 `path:"commentId"` 90 + CommentId int64 `path:"id"`
86 CompanyId int64 `path:",optional"` 91 CompanyId int64 `path:",optional"`
87 UserId int64 `path:",optional"` 92 UserId int64 `path:",optional"`
88 } 93 }
@@ -21,9 +21,13 @@ func (repository *ArticleCommentRepository) Insert(ctx context.Context, conn tra @@ -21,9 +21,13 @@ func (repository *ArticleCommentRepository) Insert(ctx context.Context, conn tra
21 m = &models.ArticleComment{} 21 m = &models.ArticleComment{}
22 tx = conn.DB() 22 tx = conn.DB()
23 ) 23 )
  24 + if len(dm.AtWho) == 0 {
  25 + dm.AtWho = make([]domain.UserSimple, 0)
  26 + }
24 if m, err = repository.DomainModelToModel(dm); err != nil { 27 if m, err = repository.DomainModelToModel(dm); err != nil {
25 return nil, err 28 return nil, err
26 } 29 }
  30 +
27 if tx = tx.Model(m).Save(m); tx.Error != nil { 31 if tx = tx.Model(m).Save(m); tx.Error != nil {
28 return nil, tx.Error 32 return nil, tx.Error
29 } 33 }
@@ -165,6 +169,7 @@ func (repository *ArticleCommentRepository) ModelToDomainModel(from *models.Arti @@ -165,6 +169,7 @@ func (repository *ArticleCommentRepository) ModelToDomainModel(from *models.Arti
165 CountUserLove: from.CountUserLove, 169 CountUserLove: from.CountUserLove,
166 CountAdminLove: from.CountAdminLove, 170 CountAdminLove: from.CountAdminLove,
167 Show: domain.CommentShow(from.Show), 171 Show: domain.CommentShow(from.Show),
  172 + AtWho: from.AtWho,
168 } 173 }
169 // err := copier.Copy(to, from) 174 // err := copier.Copy(to, from)
170 return to, nil 175 return to, nil
@@ -176,6 +181,7 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti @@ -176,6 +181,7 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti
176 CompanyId: from.CompanyId, 181 CompanyId: from.CompanyId,
177 CreatedAt: from.CreatedAt, 182 CreatedAt: from.CreatedAt,
178 UpdatedAt: from.UpdatedAt, 183 UpdatedAt: from.UpdatedAt,
  184 + IsDel: 0,
179 DeletedAt: from.DeletedAt, 185 DeletedAt: from.DeletedAt,
180 Version: from.Version, 186 Version: from.Version,
181 Pid: from.Pid, 187 Pid: from.Pid,
@@ -187,6 +193,7 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti @@ -187,6 +193,7 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti
187 FromUser: from.FromUser, 193 FromUser: from.FromUser,
188 ToUserId: from.ToUser.Id, 194 ToUserId: from.ToUser.Id,
189 ToUser: from.ToUser, 195 ToUser: from.ToUser,
  196 + AtWho: from.AtWho,
190 Content: from.Content, 197 Content: from.Content,
191 CountReply: from.CountReply, 198 CountReply: from.CountReply,
192 CountUserLove: from.CountUserLove, 199 CountUserLove: from.CountUserLove,