feat(post): implement share recording functionality
All checks were successful
Build Backend / build (push) Successful in 13m16s
Build Backend / build-docker (push) Successful in 1m4s

- Added RecordShare method in PostHandler to handle sharing posts and increment share count.
- Introduced IncrementShares method in PostRepository to update shares_count for published posts.
- Updated PostService to include RecordShare, ensuring cache invalidation for post details and lists.
- Integrated new share route in the router for handling share requests.
This commit is contained in:
lafay
2026-03-24 05:21:36 +08:00
parent 176cd20847
commit 15f0f1605e
4 changed files with 79 additions and 0 deletions

View File

@@ -64,6 +64,8 @@ type PostService interface {
// 其他
IncrementViews(ctx context.Context, postID, userID string) error
// RecordShare 记录分享(仅已发布帖子计数 +1返回最新 shares_count
RecordShare(ctx context.Context, postID, userID string) (sharesCount int, err error)
// 日志服务设置
SetLogService(logService *LogService)
@@ -492,6 +494,19 @@ func (s *postServiceImpl) IncrementViews(ctx context.Context, postID, userID str
return nil
}
// RecordShare 记录分享:仅已发布帖子增加 shares_count并失效帖子详情与列表缓存
func (s *postServiceImpl) RecordShare(ctx context.Context, postID, userID string) (int, error) {
n, err := s.postRepo.IncrementShares(postID)
if err != nil {
return 0, err
}
if s.cache != nil {
cache.InvalidatePostDetail(s.cache, postID)
cache.InvalidatePostList(s.cache)
}
return n, nil
}
// GetFavorites 获取收藏列表
func (s *postServiceImpl) GetFavorites(ctx context.Context, userID string, page, pageSize int) ([]*model.Post, int64, error) {
return s.postRepo.GetFavorites(userID, page, pageSize)