正在显示
9 个修改的文件
包含
202 行增加
和
5 行删除
| @@ -24,6 +24,10 @@ service Core { | @@ -24,6 +24,10 @@ service Core { | ||
| 24 | @handler MiniListArticleComment | 24 | @handler MiniListArticleComment |
| 25 | post /article_comment/list (MiniListArticleCommentRequest) returns (MiniListArticleCommentResponse) | 25 | post /article_comment/list (MiniListArticleCommentRequest) returns (MiniListArticleCommentResponse) |
| 26 | 26 | ||
| 27 | + @doc "小程序展示评论对应的一级回复列表" | ||
| 28 | + @handler MiniListReplyArticleComment | ||
| 29 | + post /article_comment/list_reply (MiniListReplyArticleCommentRequest) returns (MiniListReplyArticleCommentResponse) | ||
| 30 | + | ||
| 27 | @doc "小程序展示文章的评论列表TOP5" | 31 | @doc "小程序展示文章的评论列表TOP5" |
| 28 | @handler MiniTop5ArticleComment | 32 | @handler MiniTop5ArticleComment |
| 29 | post /article_comment/top5 (MiniTop5ArticleCommentRequest) returns (MiniTop5ArticleCommentResponse) | 33 | post /article_comment/top5 (MiniTop5ArticleCommentRequest) returns (MiniTop5ArticleCommentResponse) |
| @@ -159,7 +163,7 @@ type ( | @@ -159,7 +163,7 @@ type ( | ||
| 159 | AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人 | 163 | AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人 |
| 160 | MatchUrl map[string]string `json:"matchUrl"` // 评论内容中的url文本 | 164 | MatchUrl map[string]string `json:"matchUrl"` // 评论内容中的url文本 |
| 161 | CreatedAt int64 `json:"createdAt"` // | 165 | CreatedAt int64 `json:"createdAt"` // |
| 162 | - MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞) | 166 | + MeLoveFlag int `json:"meLoveFlag"` // 当前人员对评论的点赞标识 (0 没有点赞 1有点赞) |
| 163 | Content string `json:"content"` // 评论的内容 | 167 | Content string `json:"content"` // 评论的内容 |
| 164 | } | 168 | } |
| 165 | ) | 169 | ) |
| @@ -214,6 +218,22 @@ type ( | @@ -214,6 +218,22 @@ type ( | ||
| 214 | } | 218 | } |
| 215 | ) | 219 | ) |
| 216 | 220 | ||
| 221 | +// 获取评论的回复,只返回一级 | ||
| 222 | +type ( | ||
| 223 | + MiniListReplyArticleCommentRequest { | ||
| 224 | + CommentId int64 `json:"commentId"` | ||
| 225 | + UserId int64 `json:",optional"` | ||
| 226 | + CompanyId int64 `json:",optional"` | ||
| 227 | + Page int `json:"page"` | ||
| 228 | + Size int `json:"size"` | ||
| 229 | + } | ||
| 230 | + | ||
| 231 | + MiniListReplyArticleCommentResponse { | ||
| 232 | + Total int64 `json:"total"` | ||
| 233 | + List []ArticleCommentItem `json:"list"` | ||
| 234 | + } | ||
| 235 | +) | ||
| 236 | + | ||
| 217 | type ( | 237 | type ( |
| 218 | SystemArticleCommentSearchMeRequest { | 238 | SystemArticleCommentSearchMeRequest { |
| 219 | Page int `json:"page"` | 239 | Page int `json:"page"` |
| 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 MiniListReplyArticleCommentHandler(svcCtx *svc.ServiceContext) http.HandlerFunc { | ||
| 15 | + return func(w http.ResponseWriter, r *http.Request) { | ||
| 16 | + var req types.MiniListReplyArticleCommentRequest | ||
| 17 | + if err := httpx.Parse(r, &req); err != nil { | ||
| 18 | + result.HttpResult(r, w, nil, err) | ||
| 19 | + return | ||
| 20 | + } | ||
| 21 | + | ||
| 22 | + l := comment.NewMiniListReplyArticleCommentLogic(r.Context(), svcCtx) | ||
| 23 | + token := contextdata.GetUserTokenFromCtx(r.Context()) | ||
| 24 | + req.CompanyId = token.CompanyId | ||
| 25 | + req.UserId = token.UserId | ||
| 26 | + resp, err := l.MiniListReplyArticleComment(&req) | ||
| 27 | + result.HttpResult(r, w, resp, err) | ||
| 28 | + } | ||
| 29 | +} |
| @@ -70,6 +70,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | @@ -70,6 +70,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) { | ||
| 70 | }, | 70 | }, |
| 71 | { | 71 | { |
| 72 | Method: http.MethodPost, | 72 | Method: http.MethodPost, |
| 73 | + Path: "/article_comment/list_reply", | ||
| 74 | + Handler: comment.MiniListReplyArticleCommentHandler(serverCtx), | ||
| 75 | + }, | ||
| 76 | + { | ||
| 77 | + Method: http.MethodPost, | ||
| 73 | Path: "/article_comment/top5", | 78 | Path: "/article_comment/top5", |
| 74 | Handler: comment.MiniTop5ArticleCommentHandler(serverCtx), | 79 | Handler: comment.MiniTop5ArticleCommentHandler(serverCtx), |
| 75 | }, | 80 | }, |
| @@ -161,6 +161,7 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR | @@ -161,6 +161,7 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR | ||
| 161 | Show: domain.ArticleShowEnable, | 161 | Show: domain.ArticleShowEnable, |
| 162 | Tags: []int64{}, | 162 | Tags: []int64{}, |
| 163 | MatchUrl: map[string]string{}, | 163 | MatchUrl: map[string]string{}, |
| 164 | + Videos: []domain.Video{}, | ||
| 164 | } | 165 | } |
| 165 | if len(whoRead) > 0 { | 166 | if len(whoRead) > 0 { |
| 166 | newArticle.TargetUser = domain.ArticleTargetLimit | 167 | newArticle.TargetUser = domain.ArticleTargetLimit |
| @@ -29,8 +29,8 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont | @@ -29,8 +29,8 @@ func NewMiniListArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceCont | ||
| 29 | func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) { | 29 | func (l *MiniListArticleCommentLogic) MiniListArticleComment(req *types.MiniListArticleCommentRequest) (resp *types.MiniListArticleCommentResponse, err error) { |
| 30 | // 先获取最顶层的评论 | 30 | // 先获取最顶层的评论 |
| 31 | var conn = l.svcCtx.DefaultDBConn() | 31 | var conn = l.svcCtx.DefaultDBConn() |
| 32 | - if req.Page > 40 { | ||
| 33 | - req.Page = 40 | 32 | + if req.Size > 40 { |
| 33 | + req.Size = 40 | ||
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | queryOption := domain.NewQueryOptions(). | 36 | queryOption := domain.NewQueryOptions(). |
| 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 MiniListReplyArticleCommentLogic struct { | ||
| 15 | + logx.Logger | ||
| 16 | + ctx context.Context | ||
| 17 | + svcCtx *svc.ServiceContext | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +func NewMiniListReplyArticleCommentLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MiniListReplyArticleCommentLogic { | ||
| 21 | + return &MiniListReplyArticleCommentLogic{ | ||
| 22 | + Logger: logx.WithContext(ctx), | ||
| 23 | + ctx: ctx, | ||
| 24 | + svcCtx: svcCtx, | ||
| 25 | + } | ||
| 26 | +} | ||
| 27 | + | ||
| 28 | +// 获取评论对应的回复,只获取一级评论 | ||
| 29 | +func (l *MiniListReplyArticleCommentLogic) MiniListReplyArticleComment(req *types.MiniListReplyArticleCommentRequest) (resp *types.MiniListReplyArticleCommentResponse, err error) { | ||
| 30 | + // 先获取最顶层的评论 | ||
| 31 | + var conn = l.svcCtx.DefaultDBConn() | ||
| 32 | + if req.CommentId == 0 { | ||
| 33 | + return | ||
| 34 | + } | ||
| 35 | + queryOption := domain.NewQueryOptions(). | ||
| 36 | + WithOffsetLimit(req.Page, req.Size). | ||
| 37 | + MustWithKV("show", int(domain.CommentShowEnable)). | ||
| 38 | + MustWithKV("companyId", req.CompanyId). | ||
| 39 | + MustWithKV("pid", req.CommentId) | ||
| 40 | + | ||
| 41 | + cnt, commentList, err := l.svcCtx.ArticleCommentRepository.Find(l.ctx, conn, queryOption) | ||
| 42 | + if err != nil { | ||
| 43 | + return nil, xerr.NewErrMsgErr("获取评论信息失败", err) | ||
| 44 | + } | ||
| 45 | + if cnt == 0 || len(commentList) == 0 { | ||
| 46 | + resp = &types.MiniListReplyArticleCommentResponse{ | ||
| 47 | + Total: cnt, | ||
| 48 | + List: make([]types.ArticleCommentItem, 0), | ||
| 49 | + } | ||
| 50 | + return | ||
| 51 | + } | ||
| 52 | + commentIds := []int64{} | ||
| 53 | + for _, val := range commentList { | ||
| 54 | + commentIds = append(commentIds, val.Id) | ||
| 55 | + } | ||
| 56 | + queryOption = domain.NewQueryOptions().WithFindOnly(). | ||
| 57 | + MustWithKV("commentIdList", commentIds). | ||
| 58 | + MustWithKV("userId", req.UserId) | ||
| 59 | + // 获取我点赞的评论 | ||
| 60 | + _, userFlagList, err := l.svcCtx.UserLoveFlagRepository.Find(l.ctx, conn, queryOption) | ||
| 61 | + if err != nil { | ||
| 62 | + return nil, xerr.NewErrMsgErr("获取评论信息失败", err) | ||
| 63 | + } | ||
| 64 | + // 我点赞的 | ||
| 65 | + flagMap := map[int64]struct{}{} | ||
| 66 | + for _, val := range userFlagList { | ||
| 67 | + flagMap[val.CommentId] = struct{}{} | ||
| 68 | + } | ||
| 69 | + resp = &types.MiniListReplyArticleCommentResponse{ | ||
| 70 | + Total: cnt, | ||
| 71 | + List: make([]types.ArticleCommentItem, len(commentList)), | ||
| 72 | + } | ||
| 73 | + // 获取回复的评论 | ||
| 74 | + for i, val := range commentList { | ||
| 75 | + item := types.ArticleCommentItem{ | ||
| 76 | + | ||
| 77 | + Id: val.Id, | ||
| 78 | + Pid: val.Pid, | ||
| 79 | + TopId: val.TopId, | ||
| 80 | + ArtitcleId: val.ArticleId, | ||
| 81 | + SectionId: val.SectionId, | ||
| 82 | + FromUserId: val.FromUserId, | ||
| 83 | + FromUser: types.CommentAuthor{ | ||
| 84 | + Id: val.FromUser.Id, | ||
| 85 | + Name: val.FromUser.Name, | ||
| 86 | + Avatar: val.FromUser.Avatar, | ||
| 87 | + Position: val.FromUser.Position, | ||
| 88 | + Company: val.FromUser.Company, | ||
| 89 | + }, | ||
| 90 | + ToUserId: val.ToUserId, | ||
| 91 | + ToUser: types.CommentAuthor{ | ||
| 92 | + Id: val.ToUser.Id, | ||
| 93 | + Name: val.ToUser.Name, | ||
| 94 | + Avatar: val.ToUser.Avatar, | ||
| 95 | + Position: val.ToUser.Position, | ||
| 96 | + Company: val.ToUser.Company, | ||
| 97 | + }, | ||
| 98 | + SectionContent: val.SectionContent, | ||
| 99 | + CountReply: val.CountReply, | ||
| 100 | + CountUserLove: val.CountUserLove, | ||
| 101 | + CountAdminLove: val.CountAdminLove, | ||
| 102 | + AtWho: []types.CommentAtWho{}, | ||
| 103 | + MatchUrl: map[string]string{}, | ||
| 104 | + CreatedAt: val.CreatedAt, | ||
| 105 | + MeLoveFlag: 0, | ||
| 106 | + Content: val.Content, | ||
| 107 | + } | ||
| 108 | + | ||
| 109 | + if _, ok := flagMap[val.Id]; ok { | ||
| 110 | + item.MeLoveFlag = 1 | ||
| 111 | + } | ||
| 112 | + for key2, val2 := range val.MatchUrl { | ||
| 113 | + item.MatchUrl[key2] = val2 | ||
| 114 | + } | ||
| 115 | + for _, val2 := range val.AtWho { | ||
| 116 | + item.AtWho = append(item.AtWho, types.CommentAtWho{ | ||
| 117 | + Id: val2.Id, | ||
| 118 | + Name: val2.Name, | ||
| 119 | + }) | ||
| 120 | + } | ||
| 121 | + resp.List[i] = item | ||
| 122 | + } | ||
| 123 | + return resp, nil | ||
| 124 | +} |
| @@ -94,7 +94,7 @@ type ArticleCommentItem struct { | @@ -94,7 +94,7 @@ type ArticleCommentItem struct { | ||
| 94 | AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人 | 94 | AtWho []CommentAtWho `json:"atWho"` // 填写评论时@的人 |
| 95 | MatchUrl map[string]string `json:"matchUrl"` // 评论内容中的url文本 | 95 | MatchUrl map[string]string `json:"matchUrl"` // 评论内容中的url文本 |
| 96 | CreatedAt int64 `json:"createdAt"` // | 96 | CreatedAt int64 `json:"createdAt"` // |
| 97 | - MeLoveFlag int `json:"meLoveFlag"` //当前人员对评论的点赞标识 (0 没有点赞 1有点赞) | 97 | + MeLoveFlag int `json:"meLoveFlag"` // 当前人员对评论的点赞标识 (0 没有点赞 1有点赞) |
| 98 | Content string `json:"content"` // 评论的内容 | 98 | Content string `json:"content"` // 评论的内容 |
| 99 | } | 99 | } |
| 100 | 100 | ||
| @@ -138,6 +138,19 @@ type MiniArticleCommentAtWhoResponse struct { | @@ -138,6 +138,19 @@ type MiniArticleCommentAtWhoResponse struct { | ||
| 138 | List []CommentAtWho `json:"list"` | 138 | List []CommentAtWho `json:"list"` |
| 139 | } | 139 | } |
| 140 | 140 | ||
| 141 | +type MiniListReplyArticleCommentRequest struct { | ||
| 142 | + CommentId int64 `json:"commentId"` | ||
| 143 | + UserId int64 `json:",optional"` | ||
| 144 | + CompanyId int64 `json:",optional"` | ||
| 145 | + Page int `json:"page"` | ||
| 146 | + Size int `json:"size"` | ||
| 147 | +} | ||
| 148 | + | ||
| 149 | +type MiniListReplyArticleCommentResponse struct { | ||
| 150 | + Total int64 `json:"total"` | ||
| 151 | + List []ArticleCommentItem `json:"list"` | ||
| 152 | +} | ||
| 153 | + | ||
| 141 | type SystemArticleCommentSearchMeRequest struct { | 154 | type SystemArticleCommentSearchMeRequest struct { |
| 142 | Page int `json:"page"` | 155 | Page int `json:"page"` |
| 143 | Size int `json:"size"` | 156 | Size int `json:"size"` |
| @@ -155,7 +155,9 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans | @@ -155,7 +155,9 @@ func (repository *ArticleCommentRepository) Find(ctx context.Context, conn trans | ||
| 155 | if v, ok := queryOptions["fromUserName"]; ok && v.(string) != "" { | 155 | if v, ok := queryOptions["fromUserName"]; ok && v.(string) != "" { |
| 156 | tx = tx.Where(`from_user #>> '{"name"}' like ?`, "%"+v.(string)+"%") | 156 | tx = tx.Where(`from_user #>> '{"name"}' like ?`, "%"+v.(string)+"%") |
| 157 | } | 157 | } |
| 158 | - | 158 | + if v, ok := queryOptions["pid"]; ok { |
| 159 | + tx = tx.Where("pid=?", v) | ||
| 160 | + } | ||
| 159 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | 161 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { |
| 160 | return dms, tx.Error | 162 | return dms, tx.Error |
| 161 | } | 163 | } |
| @@ -135,6 +135,9 @@ func (repository *UserLoveFlagRepository) Find(ctx context.Context, conn transac | @@ -135,6 +135,9 @@ func (repository *UserLoveFlagRepository) Find(ctx context.Context, conn transac | ||
| 135 | if v, ok := queryOptions["toUserId"]; ok { | 135 | if v, ok := queryOptions["toUserId"]; ok { |
| 136 | tx = tx.Where("to_user_id=?", v) | 136 | tx = tx.Where("to_user_id=?", v) |
| 137 | } | 137 | } |
| 138 | + if v, ok := queryOptions["commentIdList"]; ok { | ||
| 139 | + tx = tx.Where("comment_id in (?)", v) | ||
| 140 | + } | ||
| 138 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { | 141 | if total, tx = transaction.PaginationAndCount(ctx, tx, queryOptions, &ms); tx.Error != nil { |
| 139 | return dms, tx.Error | 142 | return dms, tx.Error |
| 140 | } | 143 | } |
-
请 注册 或 登录 后发表评论