正在显示
1 个修改的文件
包含
39 行增加
和
2 行删除
@@ -201,18 +201,55 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* | @@ -201,18 +201,55 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* | ||
201 | // 点赞数量变动 | 201 | // 点赞数量变动 |
202 | func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error { | 202 | func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error { |
203 | // | 203 | // |
204 | + var ( | ||
205 | + err error | ||
206 | + m *models.Article | ||
207 | + tx = conn.DB() | ||
208 | + ) | ||
209 | + m = &models.Article{Id: article.Id} | ||
210 | + queryFunc := func() (interface{}, error) { | ||
211 | + tx = tx.Model(m).Update("count_love", gorm.Expr("count_love+?", incr)) | ||
212 | + return nil, tx.Error | ||
213 | + } | ||
214 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
215 | + return err | ||
216 | + } | ||
204 | return nil | 217 | return nil |
205 | } | 218 | } |
206 | 219 | ||
207 | // 浏览数量变动 | 220 | // 浏览数量变动 |
208 | func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error { | 221 | func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error { |
209 | - // | 222 | + var ( |
223 | + err error | ||
224 | + m *models.Article | ||
225 | + tx = conn.DB() | ||
226 | + ) | ||
227 | + m = &models.Article{Id: article.Id} | ||
228 | + queryFunc := func() (interface{}, error) { | ||
229 | + tx = tx.Model(m).Update("count_read", gorm.Expr("count_read+?", incr)) | ||
230 | + return nil, tx.Error | ||
231 | + } | ||
232 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
233 | + return err | ||
234 | + } | ||
210 | return nil | 235 | return nil |
211 | } | 236 | } |
212 | 237 | ||
213 | // 评论数量变动 | 238 | // 评论数量变动 |
214 | func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error { | 239 | func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error { |
215 | - // | 240 | + var ( |
241 | + err error | ||
242 | + m *models.Article | ||
243 | + tx = conn.DB() | ||
244 | + ) | ||
245 | + m = &models.Article{Id: article.Id} | ||
246 | + queryFunc := func() (interface{}, error) { | ||
247 | + tx = tx.Model(m).Update("count_comment", gorm.Expr("count_comment+?", incr)) | ||
248 | + return nil, tx.Error | ||
249 | + } | ||
250 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
251 | + return err | ||
252 | + } | ||
216 | return nil | 253 | return nil |
217 | } | 254 | } |
218 | 255 |
-
请 注册 或 登录 后发表评论