作者 tangxvhui

更新

... ... @@ -18,9 +18,6 @@ service Core {
@doc "小程序创建发布内容"
@handler MiniCreateArticle
post /article (MiniArticleCreateRequest) returns (MiniArticleCreateResponse)
@doc "小程序获取我发布的文章"
@handler MiniArticleSearchMe
post /article/search/me (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse)
@doc "小程序获取文章内容详情"
@handler MiniGetArticle
get /article/:id (MiniArticleGetRequest) returns (MiniArticleGetResponse)
... ... @@ -30,6 +27,10 @@ service Core {
@doc "小程序人员操作点赞文章/评论"
@handler MiniSetUserLike
post /article/user_like/set (MiniSetUserLikeRequset) returns (MiniSetUserLikeResponse)
@doc "小程序获取我发布的文章"
@handler MiniArticleSearchMe
post /article/search/me (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse)
}
// 坐标地点描述
... ...
... ... @@ -146,7 +146,12 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR
Latitude: req.Location.Latitude,
Descript: req.Location.Descript,
},
TargetUser: domain.ArticleTargetAll,
TargetUser: domain.ArticleTargetAll,
CountLove: 0,
CountComment: 0,
CountRead: 0,
Show: 0,
Tags: []int64{},
}
if len(whoRead) > 0 {
newArticle.TargetUser = domain.ArticleTargetLimit
... ...
... ... @@ -25,7 +25,7 @@ func NewMiniUserLikeArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext
}
}
// 获取点赞的人员列表
// 获取点赞文章的的人员列表
func (l *MiniUserLikeArticleLogic) MiniUserLikeArticle(req *types.MiniUserLikeArticleRequest) (resp *types.MiniUserLikeArticleResponse, err error) {
var conn = l.svcCtx.DefaultDBConn()
queryOption := domain.NewQueryOptions().
... ...
... ... @@ -45,6 +45,7 @@ func (m *Article) BeforeCreate(tx *gorm.DB) (err error) {
func (m *Article) BeforeUpdate(tx *gorm.DB) (err error) {
m.UpdatedAt = time.Now().Unix()
m.Version += 1
return
}
... ...
... ... @@ -45,6 +45,7 @@ func (m *ArticleComment) BeforeCreate(tx *gorm.DB) (err error) {
func (m *ArticleComment) BeforeUpdate(tx *gorm.DB) (err error) {
m.UpdatedAt = time.Now().Unix()
m.Version += 1
return
}
... ...
... ... @@ -194,9 +194,25 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti
return to, nil
}
// TODO 点赞数量变动
// 点赞数量变动
func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *domain.ArticleComment) error {
var (
err error
m *models.ArticleComment
tx = conn.DB()
)
if m, err = repository.DomainModelToModel(dm); err != nil {
return err
}
queryFunc := func() (interface{}, error) {
tx = tx.Model(m).Update("count_user_love", gorm.Expr("count_user_love+?", incr))
return nil, tx.Error
}
if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil {
return err
}
return nil
}
func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository {
... ...
... ... @@ -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
... ...