正在显示
3 个修改的文件
包含
30 行增加
和
1 行删除
@@ -149,11 +149,18 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | @@ -149,11 +149,18 @@ func (l *MiniCreateArticleCommentLogic) MiniCreateArticleComment(req *types.Mini | ||
149 | } | 149 | } |
150 | //保存数据 | 150 | //保存数据 |
151 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { | 151 | err = transaction.UseTrans(l.ctx, conn.DB(), func(ctx context.Context, c transaction.Conn) error { |
152 | - // 增加平评论计数 | 152 | + // 增加文章评论计数 |
153 | err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo) | 153 | err = l.svcCtx.ArticleRepository.IncreaseCountComment(ctx, c, 1, articleInfo) |
154 | if err != nil { | 154 | if err != nil { |
155 | return err | 155 | return err |
156 | } | 156 | } |
157 | + //增加评论回复计数 | ||
158 | + if pComment != nil { | ||
159 | + err = l.svcCtx.ArticleCommentRepository.IncreaseCountReply(l.ctx, c, 1, pComment) | ||
160 | + if err != nil { | ||
161 | + return err | ||
162 | + } | ||
163 | + } | ||
157 | //保存评论 | 164 | //保存评论 |
158 | _, err = l.svcCtx.ArticleCommentRepository.Insert(ctx, c, &newComment) | 165 | _, err = l.svcCtx.ArticleCommentRepository.Insert(ctx, c, &newComment) |
159 | if err != nil { | 166 | if err != nil { |
@@ -218,6 +218,27 @@ func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Co | @@ -218,6 +218,27 @@ func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Co | ||
218 | 218 | ||
219 | } | 219 | } |
220 | 220 | ||
221 | +// 点赞数量变动 | ||
222 | +func (repository *ArticleCommentRepository) IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, dm *domain.ArticleComment) error { | ||
223 | + var ( | ||
224 | + err error | ||
225 | + m *models.ArticleComment | ||
226 | + tx = conn.DB() | ||
227 | + ) | ||
228 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
229 | + return err | ||
230 | + } | ||
231 | + queryFunc := func() (interface{}, error) { | ||
232 | + tx = tx.Model(m).Update("count_reply", gorm.Expr("count_reply+?", incr)) | ||
233 | + return nil, tx.Error | ||
234 | + } | ||
235 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
236 | + return err | ||
237 | + } | ||
238 | + return nil | ||
239 | + | ||
240 | +} | ||
241 | + | ||
221 | func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository { | 242 | func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository { |
222 | return &ArticleCommentRepository{CachedRepository: cache} | 243 | return &ArticleCommentRepository{CachedRepository: cache} |
223 | } | 244 | } |
@@ -48,4 +48,5 @@ type ArticleCommentRepository interface { | @@ -48,4 +48,5 @@ type ArticleCommentRepository interface { | ||
48 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleComment, error) | 48 | FindOne(ctx context.Context, conn transaction.Conn, id int64) (*ArticleComment, error) |
49 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleComment, error) | 49 | Find(ctx context.Context, conn transaction.Conn, queryOptions map[string]interface{}) (int64, []*ArticleComment, error) |
50 | IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *ArticleComment) error //点赞数量变动 | 50 | IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *ArticleComment) error //点赞数量变动 |
51 | + IncreaseCountReply(ctx context.Context, conn transaction.Conn, incr int, dm *ArticleComment) error // 评论回复数量变动 | ||
51 | } | 52 | } |
-
请 注册 或 登录 后发表评论