正在显示
4 个修改的文件
包含
45 行增加
和
5 行删除
@@ -152,11 +152,23 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | @@ -152,11 +152,23 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | ||
152 | } | 152 | } |
153 | //保存数据 | 153 | //保存数据 |
154 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { | 154 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { |
155 | + //保存评论 | ||
156 | + _, err = l.svcCtx.ArticleCommentRepository.Insert(ctx, c, &newComment) | ||
157 | + if err != nil { | ||
158 | + return err | ||
159 | + } | ||
155 | // 增加文章评论计数 | 160 | // 增加文章评论计数 |
156 | err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo.Id) | 161 | err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo.Id) |
157 | if err != nil { | 162 | if err != nil { |
158 | return err | 163 | return err |
159 | } | 164 | } |
165 | + //增加段落评论计数 | ||
166 | + if newComment.SectionId > 0 { | ||
167 | + err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, 1, newComment.SectionId) | ||
168 | + if err != nil { | ||
169 | + return err | ||
170 | + } | ||
171 | + } | ||
160 | //增加评论回复计数 | 172 | //增加评论回复计数 |
161 | if pComment != nil { | 173 | if pComment != nil { |
162 | err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, pComment.Id) | 174 | err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, pComment.Id) |
@@ -171,11 +183,6 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | @@ -171,11 +183,6 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | ||
171 | return err | 183 | return err |
172 | } | 184 | } |
173 | } | 185 | } |
174 | - //保存评论 | ||
175 | - _, err = l.svcCtx.ArticleCommentRepository.Insert(ctx, c, &newComment) | ||
176 | - if err != nil { | ||
177 | - return err | ||
178 | - } | ||
179 | return nil | 186 | return nil |
180 | }, true) | 187 | }, true) |
181 | 188 |
@@ -60,6 +60,18 @@ func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.Mini | @@ -60,6 +60,18 @@ func (l *MiniDeleteArticleCommentLogic) MiniDeleteArticleComment(req *types.Mini | ||
60 | return err | 60 | return err |
61 | } | 61 | } |
62 | } | 62 | } |
63 | + //减少加段落评论计数 | ||
64 | + if commetInfo.SectionId > 0 { | ||
65 | + err = l.svcCtx.ArticleSectionRepository.IncreaseCountComment(ctx, c, -1, commetInfo.SectionId) | ||
66 | + if err != nil { | ||
67 | + return err | ||
68 | + } | ||
69 | + } | ||
70 | + // 减少文章的评论数 | ||
71 | + err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, -1, commetInfo.ArticleId) | ||
72 | + if err != nil { | ||
73 | + return err | ||
74 | + } | ||
63 | return nil | 75 | return nil |
64 | }, true) | 76 | }, true) |
65 | 77 |
@@ -178,6 +178,26 @@ func (repository *ArticleSectionRepository) DomainModelToModel(from *domain.Arti | @@ -178,6 +178,26 @@ func (repository *ArticleSectionRepository) DomainModelToModel(from *domain.Arti | ||
178 | return to, nil | 178 | return to, nil |
179 | } | 179 | } |
180 | 180 | ||
181 | +// 评论数量变动 | ||
182 | +func (repository *ArticleSectionRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, sectionId int64) error { | ||
183 | + var ( | ||
184 | + err error | ||
185 | + m *models.ArticleSection | ||
186 | + tx = conn.DB() | ||
187 | + ) | ||
188 | + m = &models.ArticleSection{Id: sectionId} | ||
189 | + queryFunc := func() (interface{}, error) { | ||
190 | + tx = tx.Model(m).Updates(map[string]interface{}{ | ||
191 | + "total_comment": gorm.Expr("total_comment+?", incr), | ||
192 | + }) | ||
193 | + return nil, tx.Error | ||
194 | + } | ||
195 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
196 | + return err | ||
197 | + } | ||
198 | + return nil | ||
199 | +} | ||
200 | + | ||
181 | func NewArticleSectionRepository(cache *cache.CachedRepository) domain.ArticleSectionRepository { | 201 | func NewArticleSectionRepository(cache *cache.CachedRepository) domain.ArticleSectionRepository { |
182 | return &ArticleSectionRepository{CachedRepository: cache} | 202 | return &ArticleSectionRepository{CachedRepository: cache} |
183 | } | 203 | } |
@@ -27,6 +27,7 @@ type ArticleSectionRepository interface { | @@ -27,6 +27,7 @@ type ArticleSectionRepository interface { | ||
27 | Delete(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error) | 27 | Delete(ctx context.Context, conn transaction.Conn, dm *ArticleSection) (*ArticleSection, error) |
28 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleSection, error) | 28 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleSection, error) |
29 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleSection, error) | 29 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleSection, error) |
30 | + IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, sectionId int64) error //评论数量变动 | ||
30 | } | 31 | } |
31 | 32 | ||
32 | // 排序文章分段列表 | 33 | // 排序文章分段列表 |
-
请 注册 或 登录 后发表评论