作者 tangxvhui

调试接口

@@ -258,7 +258,7 @@ type ( @@ -258,7 +258,7 @@ type (
258 Page int `json:"page"` 258 Page int `json:"page"`
259 Size int `json:"size"` 259 Size int `json:"size"`
260 CompanyId int64 `json:",optional"` // 260 CompanyId int64 `json:",optional"` //
261 - TopId int64 `json:"topId"` // 文章顶层ID 261 + TopId int64 `json:"topId"` // 评论的顶层ID
262 FromUser string `json:"fromUser,optional"` // 用户 262 FromUser string `json:"fromUser,optional"` // 用户
263 Show int `json:"show,optional"` // 显示状态 263 Show int `json:"show,optional"` // 显示状态
264 BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间 264 BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间
@@ -272,6 +272,9 @@ type ( @@ -272,6 +272,9 @@ type (
272 } 272 }
273 SystemCommentItem { 273 SystemCommentItem {
274 Id int64 `json:"id"` //评论id 274 Id int64 `json:"id"` //评论id
  275 + Pid int64 `json:"pid"` //
  276 + TopId int64 `json:"topId"` //
  277 + ArticleId int64 `json:"articleId"` //对应的文章id
275 ArticleTitle string `json:"articleTitle"` //文章标题 278 ArticleTitle string `json:"articleTitle"` //文章标题
276 FromUserId int64 `json:"fromUserId"` //填写评论的人 279 FromUserId int64 `json:"fromUserId"` //填写评论的人
277 FromUser CommentAuthor `json:"fromUser"` //填写评论的人 280 FromUser CommentAuthor `json:"fromUser"` //填写评论的人
@@ -293,6 +296,9 @@ type ( @@ -293,6 +296,9 @@ type (
293 296
294 SystemGetCommentResponse { 297 SystemGetCommentResponse {
295 Id int64 `json:"id"` //评论id 298 Id int64 `json:"id"` //评论id
  299 + Pid int64 `json:"pid"` //
  300 + TopId int64 `json:"topId"` //
  301 + ArticleId int64 `json:"articleId"` //对应的文章id
296 ArticleTitle string `json:"articleTitle"` //文章标题 302 ArticleTitle string `json:"articleTitle"` //文章标题
297 FromUserId int64 `json:"fromUserId"` //填写评论的人 303 FromUserId int64 `json:"fromUserId"` //填写评论的人
298 FromUser CommentAuthor `json:"fromUser"` //填写评论的人 304 FromUser CommentAuthor `json:"fromUser"` //填写评论的人
@@ -16,7 +16,7 @@ func MiniSearchArticlePageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { @@ -16,7 +16,7 @@ func MiniSearchArticlePageHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
16 return func(w http.ResponseWriter, r *http.Request) { 16 return func(w http.ResponseWriter, r *http.Request) {
17 var req types.MiniSearchArticleRequest 17 var req types.MiniSearchArticleRequest
18 if err := httpx.Parse(r, &req); err != nil { 18 if err := httpx.Parse(r, &req); err != nil {
19 - httpx.ErrorCtx(r.Context(), w, err) 19 + result.HttpResult(r, w, nil, err)
20 return 20 return
21 } 21 }
22 22
1 package comment 1 package comment
2 2
3 import ( 3 import (
4 - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"  
5 "net/http" 4 "net/http"
6 5
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
  7 +
7 "github.com/zeromicro/go-zero/rest/httpx" 8 "github.com/zeromicro/go-zero/rest/httpx"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment"
9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
@@ -14,7 +15,7 @@ func SystemArticleCommentSearchHandler(svcCtx *svc.ServiceContext) http.HandlerF @@ -14,7 +15,7 @@ func SystemArticleCommentSearchHandler(svcCtx *svc.ServiceContext) http.HandlerF
14 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
15 var req types.SystemArticleCommentSearchRequest 16 var req types.SystemArticleCommentSearchRequest
16 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
17 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
18 return 19 return
19 } 20 }
20 21
1 package comment 1 package comment
2 2
3 import ( 3 import (
4 - "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"  
5 "net/http" 4 "net/http"
6 5
  6 + "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/pkg/result"
  7 +
7 "github.com/zeromicro/go-zero/rest/httpx" 8 "github.com/zeromicro/go-zero/rest/httpx"
8 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment" 9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/logic/comment"
9 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc" 10 "gitlab.fjmaimaimai.com/allied-creation/sumifcc-discuss/cmd/discuss/api/internal/svc"
@@ -14,7 +15,7 @@ func SystemArticleCommentSearchMeHandler(svcCtx *svc.ServiceContext) http.Handle @@ -14,7 +15,7 @@ func SystemArticleCommentSearchMeHandler(svcCtx *svc.ServiceContext) http.Handle
14 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
15 var req types.SystemArticleCommentSearchMeRequest 16 var req types.SystemArticleCommentSearchMeRequest
16 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
17 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
18 return 19 return
19 } 20 }
20 21
@@ -15,7 +15,7 @@ func SystemEditAticleCommentShowHandler(svcCtx *svc.ServiceContext) http.Handler @@ -15,7 +15,7 @@ func SystemEditAticleCommentShowHandler(svcCtx *svc.ServiceContext) http.Handler
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.SystemEditCommentShowRequest 16 var req types.SystemEditCommentShowRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func SystemGetAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc @@ -15,7 +15,7 @@ func SystemGetAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.SystemGetCommentRequest 16 var req types.SystemGetCommentRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -15,7 +15,7 @@ func SystemListAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc @@ -15,7 +15,7 @@ func SystemListAticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc
15 return func(w http.ResponseWriter, r *http.Request) { 15 return func(w http.ResponseWriter, r *http.Request) {
16 var req types.SystemListCommentRequest 16 var req types.SystemListCommentRequest
17 if err := httpx.Parse(r, &req); err != nil { 17 if err := httpx.Parse(r, &req); err != nil {
18 - httpx.ErrorCtx(r.Context(), w, err) 18 + result.HttpResult(r, w, nil, err)
19 return 19 return
20 } 20 }
21 21
@@ -35,8 +35,12 @@ func (l *SystemGetAticleCommentLogic) SystemGetAticleComment(req *types.SystemGe @@ -35,8 +35,12 @@ func (l *SystemGetAticleCommentLogic) SystemGetAticleComment(req *types.SystemGe
35 return nil, xerr.NewErrMsg("没有查看权限") 35 return nil, xerr.NewErrMsg("没有查看权限")
36 } 36 }
37 resp = &types.SystemGetCommentResponse{ 37 resp = &types.SystemGetCommentResponse{
38 - Id: commentInfo.Id,  
39 - FromUserId: commentInfo.FromUserId, 38 + Id: commentInfo.Id,
  39 + Pid: commentInfo.Pid,
  40 + TopId: commentInfo.TopId,
  41 + ArticleId: commentInfo.ArticleId,
  42 + ArticleTitle: "",
  43 + FromUserId: commentInfo.FromUserId,
40 FromUser: types.CommentAuthor{ 44 FromUser: types.CommentAuthor{
41 Id: commentInfo.FromUserId, 45 Id: commentInfo.FromUserId,
42 Name: commentInfo.FromUser.Name, 46 Name: commentInfo.FromUser.Name,
@@ -29,10 +29,10 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System @@ -29,10 +29,10 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System
29 var conn = l.svcCtx.DefaultDBConn() 29 var conn = l.svcCtx.DefaultDBConn()
30 30
31 cnt, commentList, err := l.svcCtx.ArticleCommentRepository.CustomSearchBy(l.ctx, conn, req.CompanyId, req.Page, req.Size, 31 cnt, commentList, err := l.svcCtx.ArticleCommentRepository.CustomSearchBy(l.ctx, conn, req.CompanyId, req.Page, req.Size,
32 - req.ArticleTitle, req.Content, req.FromUser, req.Show, 32 + req.TopId, req.ArticleTitle, req.Content, req.FromUser, req.Show,
33 ) 33 )
34 if err != nil { 34 if err != nil {
35 - return nil, xerr.NewErrMsgErr("获取评论详情失败", err) 35 + return nil, xerr.NewErrMsgErr("获取评论列表失败", err)
36 } 36 }
37 37
38 resp = &types.SystemListCommentResponse{ 38 resp = &types.SystemListCommentResponse{
@@ -43,6 +43,8 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System @@ -43,6 +43,8 @@ func (l *SystemListAticleCommentLogic) SystemListAticleComment(req *types.System
43 for i, val := range commentList { 43 for i, val := range commentList {
44 resp.List[i] = types.SystemCommentItem{ 44 resp.List[i] = types.SystemCommentItem{
45 Id: val.Id, 45 Id: val.Id,
  46 + Pid: val.Pid,
  47 + TopId: val.TopId,
46 ArticleTitle: val.ArticleTitle, 48 ArticleTitle: val.ArticleTitle,
47 FromUserId: val.FromUserId, 49 FromUserId: val.FromUserId,
48 FromUser: types.CommentAuthor{ 50 FromUser: types.CommentAuthor{
@@ -172,7 +172,7 @@ type SystemListCommentRequest struct { @@ -172,7 +172,7 @@ type SystemListCommentRequest struct {
172 Page int `json:"page"` 172 Page int `json:"page"`
173 Size int `json:"size"` 173 Size int `json:"size"`
174 CompanyId int64 `json:",optional"` // 174 CompanyId int64 `json:",optional"` //
175 - TopId int64 `json:"topId"` // 文章顶层ID 175 + TopId int64 `json:"topId"` // 评论的顶层ID
176 FromUser string `json:"fromUser,optional"` // 用户 176 FromUser string `json:"fromUser,optional"` // 用户
177 Show int `json:"show,optional"` // 显示状态 177 Show int `json:"show,optional"` // 显示状态
178 BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间 178 BeginTime int64 `json:"beginTime,optional"` // 填写评论的开始时间
@@ -188,6 +188,9 @@ type SystemListCommentResponse struct { @@ -188,6 +188,9 @@ type SystemListCommentResponse struct {
188 188
189 type SystemCommentItem struct { 189 type SystemCommentItem struct {
190 Id int64 `json:"id"` //评论id 190 Id int64 `json:"id"` //评论id
  191 + Pid int64 `json:"pid"` //
  192 + TopId int64 `json:"topId"` //
  193 + ArticleId int64 `json:"articleId"` //对应的文章id
191 ArticleTitle string `json:"articleTitle"` //文章标题 194 ArticleTitle string `json:"articleTitle"` //文章标题
192 FromUserId int64 `json:"fromUserId"` //填写评论的人 195 FromUserId int64 `json:"fromUserId"` //填写评论的人
193 FromUser CommentAuthor `json:"fromUser"` //填写评论的人 196 FromUser CommentAuthor `json:"fromUser"` //填写评论的人
@@ -206,6 +209,9 @@ type SystemGetCommentRequest struct { @@ -206,6 +209,9 @@ type SystemGetCommentRequest struct {
206 209
207 type SystemGetCommentResponse struct { 210 type SystemGetCommentResponse struct {
208 Id int64 `json:"id"` //评论id 211 Id int64 `json:"id"` //评论id
  212 + Pid int64 `json:"pid"` //
  213 + TopId int64 `json:"topId"` //
  214 + ArticleId int64 `json:"articleId"` //对应的文章id
209 ArticleTitle string `json:"articleTitle"` //文章标题 215 ArticleTitle string `json:"articleTitle"` //文章标题
210 FromUserId int64 `json:"fromUserId"` //填写评论的人 216 FromUserId int64 `json:"fromUserId"` //填写评论的人
211 FromUser CommentAuthor `json:"fromUser"` //填写评论的人 217 FromUser CommentAuthor `json:"fromUser"` //填写评论的人
@@ -72,8 +72,10 @@ func (m *ArticleComment) CachePrimaryKeyFunc() string { @@ -72,8 +72,10 @@ func (m *ArticleComment) CachePrimaryKeyFunc() string {
72 } 72 }
73 73
74 type ArticleCommentShow struct { 74 type ArticleCommentShow struct {
  75 + Id int64 //评论id
  76 + Pid int64
  77 + TopId int64
75 ArticleTitle string //文章标题 78 ArticleTitle string //文章标题
76 - Id int64 //评论id  
77 FromUserId int64 // 评论填写人的id 79 FromUserId int64 // 评论填写人的id
78 FromUser domain.UserSimple `gorm:"type:jsonb;serializer:json"` 80 FromUser domain.UserSimple `gorm:"type:jsonb;serializer:json"`
79 Content string // 评论内容 81 Content string // 评论内容
@@ -327,21 +327,8 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con @@ -327,21 +327,8 @@ func (repository *ArticleCommentRepository) Top5Comment(ctx context.Context, con
327 } 327 }
328 328
329 func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int, 329 func (repository *ArticleCommentRepository) CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int,
330 - articleTitle string, contentLike string, fromUserName string, show int) (int, []*domain.ArticleCommentShow, error) {  
331 - sqlStr := `select  
332 -article.title as article_title ,  
333 -article_comment.id ,  
334 -article_comment.from_user_id ,  
335 -article_comment.from_user,  
336 -article_comment."content" ,  
337 -article_comment.created_at ,  
338 -article_comment.count_reply ,  
339 -article_comment.count_user_love ,  
340 -article_comment.count_admin_love ,  
341 -article_comment."show"  
342 -from article_comment  
343 -join article on article.id = article_comment.article_id  
344 -where 1=1 ` 330 + topId int64, articleTitle string, contentLike string, fromUserName string, show int) (int, []*domain.ArticleCommentShow, error) {
  331 +
345 if size <= 0 { 332 if size <= 0 {
346 size = 20 333 size = 20
347 } 334 }
@@ -349,8 +336,8 @@ where 1=1 ` @@ -349,8 +336,8 @@ where 1=1 `
349 page = 1 336 page = 1
350 } 337 }
351 338
352 - where := ""  
353 - condition := []interface{}{} 339 + where := " and article_comment.company_id=? "
  340 + condition := []interface{}{companyId}
354 341
355 if len(articleTitle) > 0 { 342 if len(articleTitle) > 0 {
356 where += ` and article.title like ? ` 343 where += ` and article.title like ? `
@@ -370,7 +357,15 @@ where 1=1 ` @@ -370,7 +357,15 @@ where 1=1 `
370 condition = append(condition, show) 357 condition = append(condition, show)
371 } 358 }
372 359
373 - countSql := sqlStr + where 360 + if topId >= 0 {
  361 + where += ` and article_comment."top_id"= ? `
  362 + condition = append(condition, topId)
  363 + }
  364 + countSql := `select
  365 + count(*)
  366 + from article_comment
  367 + join article on article.id = article_comment.article_id
  368 + where 1=1 ` + where
374 369
375 var cnt int 370 var cnt int
376 db := conn.DB() 371 db := conn.DB()
@@ -379,7 +374,23 @@ where 1=1 ` @@ -379,7 +374,23 @@ where 1=1 `
379 return 0, nil, result.Error 374 return 0, nil, result.Error
380 } 375 }
381 376
382 - dataSql := sqlStr + where + ` order by article_comment.id desc limit ? offset ? ` 377 + dataSql := `select
  378 + article.title as article_title ,
  379 + article_comment.id ,
  380 + article_comment.pid,
  381 + article_comment.top_id,
  382 + article_comment.from_user_id ,
  383 + article_comment.from_user,
  384 + article_comment."content" ,
  385 + article_comment.created_at ,
  386 + article_comment.count_reply ,
  387 + article_comment.count_user_love ,
  388 + article_comment.count_admin_love ,
  389 + article_comment."show"
  390 + from article_comment
  391 + join article on article.id = article_comment.article_id
  392 + where 1=1` + where + ` order by article_comment.id desc limit ? offset ? `
  393 +
383 condition = append(condition, size, (page-1)*size) 394 condition = append(condition, size, (page-1)*size)
384 395
385 ms := []models.ArticleCommentShow{} 396 ms := []models.ArticleCommentShow{}
@@ -387,7 +398,6 @@ where 1=1 ` @@ -387,7 +398,6 @@ where 1=1 `
387 if result.Error != nil { 398 if result.Error != nil {
388 return 0, nil, result.Error 399 return 0, nil, result.Error
389 } 400 }
390 -  
391 d := []*domain.ArticleCommentShow{} 401 d := []*domain.ArticleCommentShow{}
392 for _, val := range ms { 402 for _, val := range ms {
393 d = append(d, &domain.ArticleCommentShow{ 403 d = append(d, &domain.ArticleCommentShow{
@@ -51,8 +51,10 @@ func (show CommentShow) Named() string { @@ -51,8 +51,10 @@ func (show CommentShow) Named() string {
51 } 51 }
52 52
53 type ArticleCommentShow struct { 53 type ArticleCommentShow struct {
  54 + Id int64 // 评论id
  55 + Pid int64
  56 + TopId int64
54 ArticleTitle string // 文章标题 57 ArticleTitle string // 文章标题
55 - Id int64 // 评论id  
56 FromUserId int64 // 评论填写人的id 58 FromUserId int64 // 评论填写人的id
57 FromUser UserSimple // 评论填写人 59 FromUser UserSimple // 评论填写人
58 Content string // 评论内容 60 Content string // 评论内容
@@ -75,5 +77,5 @@ type ArticleCommentRepository interface { @@ -75,5 +77,5 @@ type ArticleCommentRepository interface {
75 Top5Comment(ctx context.Context, conn transaction.Conn, companyId int64, articleId int64) ([]*ArticleComment, error) 77 Top5Comment(ctx context.Context, conn transaction.Conn, companyId int64, articleId int64) ([]*ArticleComment, error)
76 // 特定的查询 78 // 特定的查询
77 CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int, 79 CustomSearchBy(ctx context.Context, conn transaction.Conn, companyId int64, page int, size int,
78 - articleTitle string, contentLike string, fromUserName string, show int) (int, []*ArticleCommentShow, error) 80 + topId int64, articleTitle string, contentLike string, fromUserName string, show int) (int, []*ArticleCommentShow, error)
79 } 81 }