refactor: 优化islLked的获取方式并将部分相同代码提取为一个函数

This commit is contained in:
Leon
2025-12-23 18:45:39 +08:00
parent 23b4babc23
commit f884167db8
3 changed files with 56 additions and 67 deletions

View File

@@ -17,8 +17,8 @@ func NewFeedRepository(db *gorm.DB) *FeedRepository {
return &FeedRepository{db: db}
}
func (repo *FeedRepository) ListLatest(ctx context.Context, limit int, latestBefore time.Time) ([]video.Video, error) {
var videos []video.Video
func (repo *FeedRepository) ListLatest(ctx context.Context, limit int, latestBefore time.Time) ([]*video.Video, error) {
var videos []*video.Video
query := repo.db.WithContext(ctx).Model(&video.Video{}).
Order("create_time DESC")
if !latestBefore.IsZero() {
@@ -30,8 +30,8 @@ func (repo *FeedRepository) ListLatest(ctx context.Context, limit int, latestBef
return videos, nil
}
func (repo *FeedRepository) ListLikesCountWithCursor(ctx context.Context, limit int, cursor *LikesCountCursor) ([]video.Video, error) {
var videos []video.Video
func (repo *FeedRepository) ListLikesCountWithCursor(ctx context.Context, limit int, cursor *LikesCountCursor) ([]*video.Video, error) {
var videos []*video.Video
query := repo.db.WithContext(ctx).Model(&video.Video{}).
Order("likes_count DESC, id DESC")
@@ -49,8 +49,8 @@ func (repo *FeedRepository) ListLikesCountWithCursor(ctx context.Context, limit
return videos, nil
}
func (repo *FeedRepository) ListByFollowing(ctx context.Context, limit int, viewerAccountID uint) ([]video.Video, error) {
var videos []video.Video
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 {