...
|
...
|
@@ -168,6 +168,7 @@ func (repository *ArticleRepository) ModelToDomainModel(from *models.Article) (* |
|
|
CountComment: from.CountComment,
|
|
|
CountRead: from.CountRead,
|
|
|
Show: domain.ArticleShow(from.Show),
|
|
|
Tags: from.Tags,
|
|
|
}
|
|
|
return to, nil
|
|
|
}
|
...
|
...
|
@@ -193,22 +194,27 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* |
|
|
CountRead: from.CountRead,
|
|
|
CountComment: from.CountComment,
|
|
|
Show: int(from.Show),
|
|
|
Tags: from.Tags,
|
|
|
}
|
|
|
// err := copier.Copy(to, from)
|
|
|
return to, nil
|
|
|
}
|
|
|
|
|
|
// 点赞数量变动
|
|
|
func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error {
|
|
|
func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error {
|
|
|
//
|
|
|
var (
|
|
|
err error
|
|
|
m *models.Article
|
|
|
tx = conn.DB()
|
|
|
)
|
|
|
m = &models.Article{Id: article.Id}
|
|
|
if m, err = repository.DomainModelToModel(dm); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
queryFunc := func() (interface{}, error) {
|
|
|
tx = tx.Model(m).Update("count_love", gorm.Expr("count_love+?", incr))
|
|
|
tx = tx.Model(m).Updates(map[string]interface{}{
|
|
|
"count_love": gorm.Expr("count_love+?", incr),
|
|
|
})
|
|
|
return nil, tx.Error
|
|
|
}
|
|
|
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
|
...
|
...
|
@@ -218,13 +224,15 @@ func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn |
|
|
}
|
|
|
|
|
|
// 浏览数量变动
|
|
|
func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error {
|
|
|
func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error {
|
|
|
var (
|
|
|
err error
|
|
|
m *models.Article
|
|
|
tx = conn.DB()
|
|
|
)
|
|
|
m = &models.Article{Id: article.Id}
|
|
|
if m, err = repository.DomainModelToModel(dm); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
queryFunc := func() (interface{}, error) {
|
|
|
tx = tx.Model(m).Update("count_read", gorm.Expr("count_read+?", incr))
|
|
|
return nil, tx.Error
|
...
|
...
|
@@ -236,13 +244,15 @@ func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn |
|
|
}
|
|
|
|
|
|
// 评论数量变动
|
|
|
func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error {
|
|
|
func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error {
|
|
|
var (
|
|
|
err error
|
|
|
m *models.Article
|
|
|
tx = conn.DB()
|
|
|
)
|
|
|
m = &models.Article{Id: article.Id}
|
|
|
if m, err = repository.DomainModelToModel(dm); err != nil {
|
|
|
return err
|
|
|
}
|
|
|
queryFunc := func() (interface{}, error) {
|
|
|
tx = tx.Model(m).Update("count_comment", gorm.Expr("count_comment+?", incr))
|
|
|
return nil, tx.Error
|
...
|
...
|
|