- Backend: callbacks on_publish/on_publish_done, UpdateStreamURL, GetByStreamKey - Nginx-RTMP: config infra, docker-compose service (profil live) - Frontend: stream_url dans LiveStream, HLS.js dans LiveViewPlayer, état Stream terminé - Chat: rate limit send_live_message 1 msg/3s pour rooms live_streams - Env: RTMP_CALLBACK_SECRET, STREAM_HLS_BASE_URL, NGINX_RTMP_HOST - Roadmap v0.10.6 marquée DONE
78 lines
2.5 KiB
Go
78 lines
2.5 KiB
Go
package repositories
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
|
|
"veza-backend-api/internal/models"
|
|
)
|
|
|
|
// LiveStreamRepository defines the interface for live stream operations
|
|
type LiveStreamRepository interface {
|
|
Create(ctx context.Context, s *models.LiveStream) error
|
|
GetByID(ctx context.Context, id uuid.UUID) (*models.LiveStream, error)
|
|
GetByStreamKey(ctx context.Context, streamKey string) (*models.LiveStream, error)
|
|
List(ctx context.Context, isLive *bool) ([]*models.LiveStream, error)
|
|
ListByUserID(ctx context.Context, userID uuid.UUID) ([]*models.LiveStream, error)
|
|
Update(ctx context.Context, s *models.LiveStream) error
|
|
Delete(ctx context.Context, id uuid.UUID) error
|
|
}
|
|
|
|
type liveStreamRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewLiveStreamRepository creates a new LiveStreamRepository
|
|
func NewLiveStreamRepository(db *gorm.DB) LiveStreamRepository {
|
|
return &liveStreamRepository{db: db}
|
|
}
|
|
|
|
func (r *liveStreamRepository) Create(ctx context.Context, s *models.LiveStream) error {
|
|
return r.db.WithContext(ctx).Create(s).Error
|
|
}
|
|
|
|
func (r *liveStreamRepository) GetByID(ctx context.Context, id uuid.UUID) (*models.LiveStream, error) {
|
|
var s models.LiveStream
|
|
if err := r.db.WithContext(ctx).First(&s, "id = ?", id).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return &s, nil
|
|
}
|
|
|
|
func (r *liveStreamRepository) GetByStreamKey(ctx context.Context, streamKey string) (*models.LiveStream, error) {
|
|
var s models.LiveStream
|
|
if err := r.db.WithContext(ctx).First(&s, "stream_key = ?", streamKey).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return &s, nil
|
|
}
|
|
|
|
func (r *liveStreamRepository) List(ctx context.Context, isLive *bool) ([]*models.LiveStream, error) {
|
|
var items []*models.LiveStream
|
|
query := r.db.WithContext(ctx)
|
|
if isLive != nil {
|
|
query = query.Where("is_live = ?", *isLive)
|
|
}
|
|
if err := query.Order("created_at DESC").Find(&items).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
func (r *liveStreamRepository) ListByUserID(ctx context.Context, userID uuid.UUID) ([]*models.LiveStream, error) {
|
|
var items []*models.LiveStream
|
|
if err := r.db.WithContext(ctx).Where("user_id = ?", userID).Order("created_at DESC").Find(&items).Error; err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
func (r *liveStreamRepository) Update(ctx context.Context, s *models.LiveStream) error {
|
|
return r.db.WithContext(ctx).Save(s).Error
|
|
}
|
|
|
|
func (r *liveStreamRepository) Delete(ctx context.Context, id uuid.UUID) error {
|
|
return r.db.WithContext(ctx).Delete(&models.LiveStream{}, "id = ?", id).Error
|
|
}
|