feat: 添加了根据关注的feed流

This commit is contained in:
Leon
2025-12-19 19:20:52 +08:00
parent d2f40acf4d
commit 8ee2025951
5 changed files with 96 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ package feed
import (
"context"
"feedsystem_video_go/internal/social"
"feedsystem_video_go/internal/video"
"time"
@@ -41,3 +42,20 @@ func (repo *FeedRepository) ListLikesCount(ctx context.Context, limit int, likes
}
return videos, nil
}
func (repo *FeedRepository) ListByFollowing(ctx context.Context, limit int, viewerAccountID uint) ([]video.Video, error) {
var videos []video.Video
query := repo.db.WithContext(ctx).Model(&video.Video{}).
Order("create_time DESC")
if viewerAccountID > 0 {
followingSubQuery := repo.db.WithContext(ctx).
Model(&social.Social{}).
Select("vlogger_id").
Where("follower_id = ?", viewerAccountID)
query = query.Where("author_id IN (?)", followingSubQuery)
}
if err := query.Limit(limit).Find(&videos).Error; err != nil {
return nil, err
}
return videos, nil
}