...
|
...
|
@@ -201,18 +201,55 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* |
|
|
// 点赞数量变动
|
|
|
func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error {
|
|
|
//
|
|
|
var (
|
|
|
err error
|
|
|
m *models.Article
|
|
|
tx = conn.DB()
|
|
|
)
|
|
|
m = &models.Article{Id: article.Id}
|
|
|
queryFunc := func() (interface{}, error) {
|
|
|
tx = tx.Model(m).Update("count_love", gorm.Expr("count_love+?", incr))
|
|
|
return nil, tx.Error
|
|
|
}
|
|
|
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// 浏览数量变动
|
|
|
func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error {
|
|
|
//
|
|
|
var (
|
|
|
err error
|
|
|
m *models.Article
|
|
|
tx = conn.DB()
|
|
|
)
|
|
|
m = &models.Article{Id: article.Id}
|
|
|
queryFunc := func() (interface{}, error) {
|
|
|
tx = tx.Model(m).Update("count_read", gorm.Expr("count_read+?", incr))
|
|
|
return nil, tx.Error
|
|
|
}
|
|
|
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
// 评论数量变动
|
|
|
func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error {
|
|
|
//
|
|
|
var (
|
|
|
err error
|
|
|
m *models.Article
|
|
|
tx = conn.DB()
|
|
|
)
|
|
|
m = &models.Article{Id: article.Id}
|
|
|
queryFunc := func() (interface{}, error) {
|
|
|
tx = tx.Model(m).Update("count_comment", gorm.Expr("count_comment+?", incr))
|
|
|
return nil, tx.Error
|
|
|
}
|
|
|
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
|
...
|
...
|
|