Bloc A - Code mort: - Suppression Studio (components, views, features) - Suppression gamification + services mock (projectService, storageService, gamificationService) - Mise à jour Sidebar, Navbar, locales Bloc B - Frontend: - Suppression modal.tsx deprecated, Modal.stories (doublon Dialog) - Feature flags: PLAYLIST_SEARCH, PLAYLIST_RECOMMENDATIONS, ROLE_MANAGEMENT = true - Suppression 19 tests orphelins, retrait exclusions vitest.config Bloc C - Backend: - Extraction routes_auth.go depuis router.go Bloc D - Rust: - Suppression security_legacy.rs (code mort, patterns déjà dans security/)
69 lines
2.1 KiB
Go
69 lines
2.1 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)
|
|
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) 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
|
|
}
|