正在显示
7 个修改的文件
包含
47 行增加
和
13 行删除
| @@ -18,9 +18,6 @@ service Core { | @@ -18,9 +18,6 @@ service Core { | ||
| 18 | @doc "小程序创建发布内容" | 18 | @doc "小程序创建发布内容" |
| 19 | @handler MiniCreateArticle | 19 | @handler MiniCreateArticle |
| 20 | post /article (MiniArticleCreateRequest) returns (MiniArticleCreateResponse) | 20 | post /article (MiniArticleCreateRequest) returns (MiniArticleCreateResponse) |
| 21 | - @doc "小程序获取我发布的文章" | ||
| 22 | - @handler MiniArticleSearchMe | ||
| 23 | - post /article/search/me (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse) | ||
| 24 | @doc "小程序获取文章内容详情" | 21 | @doc "小程序获取文章内容详情" |
| 25 | @handler MiniGetArticle | 22 | @handler MiniGetArticle |
| 26 | get /article/:id (MiniArticleGetRequest) returns (MiniArticleGetResponse) | 23 | get /article/:id (MiniArticleGetRequest) returns (MiniArticleGetResponse) |
| @@ -30,6 +27,10 @@ service Core { | @@ -30,6 +27,10 @@ service Core { | ||
| 30 | @doc "小程序人员操作点赞文章/评论" | 27 | @doc "小程序人员操作点赞文章/评论" |
| 31 | @handler MiniSetUserLike | 28 | @handler MiniSetUserLike |
| 32 | post /article/user_like/set (MiniSetUserLikeRequset) returns (MiniSetUserLikeResponse) | 29 | post /article/user_like/set (MiniSetUserLikeRequset) returns (MiniSetUserLikeResponse) |
| 30 | + | ||
| 31 | + @doc "小程序获取我发布的文章" | ||
| 32 | + @handler MiniArticleSearchMe | ||
| 33 | + post /article/search/me (MiniArticleSearchMeRequest) returns (MiniArticleSearchMeResponse) | ||
| 33 | } | 34 | } |
| 34 | 35 | ||
| 35 | // 坐标地点描述 | 36 | // 坐标地点描述 |
| @@ -146,7 +146,12 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR | @@ -146,7 +146,12 @@ func (l *MiniCreateArticleLogic) MiniCreateArticle(req *types.MiniArticleCreateR | ||
| 146 | Latitude: req.Location.Latitude, | 146 | Latitude: req.Location.Latitude, |
| 147 | Descript: req.Location.Descript, | 147 | Descript: req.Location.Descript, |
| 148 | }, | 148 | }, |
| 149 | - TargetUser: domain.ArticleTargetAll, | 149 | + TargetUser: domain.ArticleTargetAll, |
| 150 | + CountLove: 0, | ||
| 151 | + CountComment: 0, | ||
| 152 | + CountRead: 0, | ||
| 153 | + Show: 0, | ||
| 154 | + Tags: []int64{}, | ||
| 150 | } | 155 | } |
| 151 | if len(whoRead) > 0 { | 156 | if len(whoRead) > 0 { |
| 152 | newArticle.TargetUser = domain.ArticleTargetLimit | 157 | newArticle.TargetUser = domain.ArticleTargetLimit |
| @@ -25,7 +25,7 @@ func NewMiniUserLikeArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext | @@ -25,7 +25,7 @@ func NewMiniUserLikeArticleLogic(ctx context.Context, svcCtx *svc.ServiceContext | ||
| 25 | } | 25 | } |
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | -// 获取点赞的人员列表 | 28 | +// 获取点赞文章的的人员列表 |
| 29 | func (l *MiniUserLikeArticleLogic) MiniUserLikeArticle(req *types.MiniUserLikeArticleRequest) (resp *types.MiniUserLikeArticleResponse, err error) { | 29 | func (l *MiniUserLikeArticleLogic) MiniUserLikeArticle(req *types.MiniUserLikeArticleRequest) (resp *types.MiniUserLikeArticleResponse, err error) { |
| 30 | var conn = l.svcCtx.DefaultDBConn() | 30 | var conn = l.svcCtx.DefaultDBConn() |
| 31 | queryOption := domain.NewQueryOptions(). | 31 | queryOption := domain.NewQueryOptions(). |
| @@ -45,6 +45,7 @@ func (m *Article) BeforeCreate(tx *gorm.DB) (err error) { | @@ -45,6 +45,7 @@ func (m *Article) BeforeCreate(tx *gorm.DB) (err error) { | ||
| 45 | 45 | ||
| 46 | func (m *Article) BeforeUpdate(tx *gorm.DB) (err error) { | 46 | func (m *Article) BeforeUpdate(tx *gorm.DB) (err error) { |
| 47 | m.UpdatedAt = time.Now().Unix() | 47 | m.UpdatedAt = time.Now().Unix() |
| 48 | + m.Version += 1 | ||
| 48 | return | 49 | return |
| 49 | } | 50 | } |
| 50 | 51 |
| @@ -45,6 +45,7 @@ func (m *ArticleComment) BeforeCreate(tx *gorm.DB) (err error) { | @@ -45,6 +45,7 @@ func (m *ArticleComment) BeforeCreate(tx *gorm.DB) (err error) { | ||
| 45 | 45 | ||
| 46 | func (m *ArticleComment) BeforeUpdate(tx *gorm.DB) (err error) { | 46 | func (m *ArticleComment) BeforeUpdate(tx *gorm.DB) (err error) { |
| 47 | m.UpdatedAt = time.Now().Unix() | 47 | m.UpdatedAt = time.Now().Unix() |
| 48 | + m.Version += 1 | ||
| 48 | return | 49 | return |
| 49 | } | 50 | } |
| 50 | 51 |
| @@ -194,9 +194,25 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti | @@ -194,9 +194,25 @@ func (repository *ArticleCommentRepository) DomainModelToModel(from *domain.Arti | ||
| 194 | return to, nil | 194 | return to, nil |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | -// TODO 点赞数量变动 | 197 | +// 点赞数量变动 |
| 198 | func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *domain.ArticleComment) error { | 198 | func (repository *ArticleCommentRepository) IncreaseCountUserLove(ctx context.Context, conn transaction.Conn, incr int, dm *domain.ArticleComment) error { |
| 199 | + var ( | ||
| 200 | + err error | ||
| 201 | + m *models.ArticleComment | ||
| 202 | + tx = conn.DB() | ||
| 203 | + ) | ||
| 204 | + if m, err = repository.DomainModelToModel(dm); err != nil { | ||
| 205 | + return err | ||
| 206 | + } | ||
| 207 | + queryFunc := func() (interface{}, error) { | ||
| 208 | + tx = tx.Model(m).Update("count_user_love", gorm.Expr("count_user_love+?", incr)) | ||
| 209 | + return nil, tx.Error | ||
| 210 | + } | ||
| 211 | + if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | ||
| 212 | + return err | ||
| 213 | + } | ||
| 199 | return nil | 214 | return nil |
| 215 | + | ||
| 200 | } | 216 | } |
| 201 | 217 | ||
| 202 | func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository { | 218 | func NewArticleCommentRepository(cache *cache.CachedRepository) domain.ArticleCommentRepository { |
| @@ -168,6 +168,7 @@ func (repository *ArticleRepository) ModelToDomainModel(from *models.Article) (* | @@ -168,6 +168,7 @@ func (repository *ArticleRepository) ModelToDomainModel(from *models.Article) (* | ||
| 168 | CountComment: from.CountComment, | 168 | CountComment: from.CountComment, |
| 169 | CountRead: from.CountRead, | 169 | CountRead: from.CountRead, |
| 170 | Show: domain.ArticleShow(from.Show), | 170 | Show: domain.ArticleShow(from.Show), |
| 171 | + Tags: from.Tags, | ||
| 171 | } | 172 | } |
| 172 | return to, nil | 173 | return to, nil |
| 173 | } | 174 | } |
| @@ -193,22 +194,27 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* | @@ -193,22 +194,27 @@ func (repository *ArticleRepository) DomainModelToModel(from *domain.Article) (* | ||
| 193 | CountRead: from.CountRead, | 194 | CountRead: from.CountRead, |
| 194 | CountComment: from.CountComment, | 195 | CountComment: from.CountComment, |
| 195 | Show: int(from.Show), | 196 | Show: int(from.Show), |
| 197 | + Tags: from.Tags, | ||
| 196 | } | 198 | } |
| 197 | // err := copier.Copy(to, from) | 199 | // err := copier.Copy(to, from) |
| 198 | return to, nil | 200 | return to, nil |
| 199 | } | 201 | } |
| 200 | 202 | ||
| 201 | // 点赞数量变动 | 203 | // 点赞数量变动 |
| 202 | -func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error { | 204 | +func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error { |
| 203 | // | 205 | // |
| 204 | var ( | 206 | var ( |
| 205 | err error | 207 | err error |
| 206 | m *models.Article | 208 | m *models.Article |
| 207 | tx = conn.DB() | 209 | tx = conn.DB() |
| 208 | ) | 210 | ) |
| 209 | - m = &models.Article{Id: article.Id} | 211 | + if m, err = repository.DomainModelToModel(dm); err != nil { |
| 212 | + return err | ||
| 213 | + } | ||
| 210 | queryFunc := func() (interface{}, error) { | 214 | queryFunc := func() (interface{}, error) { |
| 211 | - tx = tx.Model(m).Update("count_love", gorm.Expr("count_love+?", incr)) | 215 | + tx = tx.Model(m).Updates(map[string]interface{}{ |
| 216 | + "count_love": gorm.Expr("count_love+?", incr), | ||
| 217 | + }) | ||
| 212 | return nil, tx.Error | 218 | return nil, tx.Error |
| 213 | } | 219 | } |
| 214 | if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { | 220 | if _, err = repository.Query(queryFunc, m.CacheKeyFunc()); err != nil { |
| @@ -218,13 +224,15 @@ func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn | @@ -218,13 +224,15 @@ func (repository *ArticleRepository) IncreaseCountLove(ctx context.Context, conn | ||
| 218 | } | 224 | } |
| 219 | 225 | ||
| 220 | // 浏览数量变动 | 226 | // 浏览数量变动 |
| 221 | -func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error { | 227 | +func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error { |
| 222 | var ( | 228 | var ( |
| 223 | err error | 229 | err error |
| 224 | m *models.Article | 230 | m *models.Article |
| 225 | tx = conn.DB() | 231 | tx = conn.DB() |
| 226 | ) | 232 | ) |
| 227 | - m = &models.Article{Id: article.Id} | 233 | + if m, err = repository.DomainModelToModel(dm); err != nil { |
| 234 | + return err | ||
| 235 | + } | ||
| 228 | queryFunc := func() (interface{}, error) { | 236 | queryFunc := func() (interface{}, error) { |
| 229 | tx = tx.Model(m).Update("count_read", gorm.Expr("count_read+?", incr)) | 237 | tx = tx.Model(m).Update("count_read", gorm.Expr("count_read+?", incr)) |
| 230 | return nil, tx.Error | 238 | return nil, tx.Error |
| @@ -236,13 +244,15 @@ func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn | @@ -236,13 +244,15 @@ func (repository *ArticleRepository) IncreaseCountRead(ctx context.Context, conn | ||
| 236 | } | 244 | } |
| 237 | 245 | ||
| 238 | // 评论数量变动 | 246 | // 评论数量变动 |
| 239 | -func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, article *domain.Article) error { | 247 | +func (repository *ArticleRepository) IncreaseCountComment(ctx context.Context, conn transaction.Conn, incr int, dm *domain.Article) error { |
| 240 | var ( | 248 | var ( |
| 241 | err error | 249 | err error |
| 242 | m *models.Article | 250 | m *models.Article |
| 243 | tx = conn.DB() | 251 | tx = conn.DB() |
| 244 | ) | 252 | ) |
| 245 | - m = &models.Article{Id: article.Id} | 253 | + if m, err = repository.DomainModelToModel(dm); err != nil { |
| 254 | + return err | ||
| 255 | + } | ||
| 246 | queryFunc := func() (interface{}, error) { | 256 | queryFunc := func() (interface{}, error) { |
| 247 | tx = tx.Model(m).Update("count_comment", gorm.Expr("count_comment+?", incr)) | 257 | tx = tx.Model(m).Update("count_comment", gorm.Expr("count_comment+?", incr)) |
| 248 | return nil, tx.Error | 258 | return nil, tx.Error |
-
请 注册 或 登录 后发表评论