feat(feed): add ListLatest

This commit is contained in:
Leon
2025-12-07 22:46:45 +08:00
parent 3b80a7c5da
commit d29a3a5232
4 changed files with 123 additions and 0 deletions

30
internal/feed/repo.go Normal file
View File

@@ -0,0 +1,30 @@
package feed
import (
"context"
"feedsystem_video_go/internal/video" // 引入视频实体
"time"
"gorm.io/gorm"
)
type FeedRepository struct {
db *gorm.DB
}
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
query := repo.db.WithContext(ctx).Model(&video.Video{}).
Order("create_time DESC")
if !latestBefore.IsZero() {
query = query.Where("create_time < ?", latestBefore)
}
if err := query.Limit(limit).Find(&videos).Error; err != nil {
return nil, err
}
return videos, nil
}