veza/veza-backend-api/internal/services/live_stream_service.go
senke 04c25aa24f Phase 2 stabilisation: code mort, Modal→Dialog, feature flags, tests, router split, Rust legacy
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/)
2026-02-14 17:23:32 +01:00

75 lines
2.1 KiB
Go

package services
import (
"context"
"errors"
"github.com/google/uuid"
"veza-backend-api/internal/models"
"veza-backend-api/internal/repositories"
)
// LiveStreamService handles live stream business logic
type LiveStreamService struct {
repo repositories.LiveStreamRepository
}
// NewLiveStreamService creates a new LiveStreamService
func NewLiveStreamService(repo repositories.LiveStreamRepository) *LiveStreamService {
return &LiveStreamService{repo: repo}
}
// List returns all live streams, optionally filtered by is_live
func (s *LiveStreamService) List(ctx context.Context, isLive *bool) ([]*models.LiveStream, error) {
return s.repo.List(ctx, isLive)
}
// Get returns a single live stream by ID
func (s *LiveStreamService) Get(ctx context.Context, id uuid.UUID) (*models.LiveStream, error) {
return s.repo.GetByID(ctx, id)
}
// Create creates a new live stream for a user
func (s *LiveStreamService) Create(ctx context.Context, userID uuid.UUID, stream *models.LiveStream) (*models.LiveStream, error) {
if stream.Title == "" {
return nil, errors.New("title is required")
}
stream.UserID = userID
if stream.StreamerName == "" {
stream.StreamerName = "Streamer"
}
if err := s.repo.Create(ctx, stream); err != nil {
return nil, err
}
return stream, nil
}
// Update updates an existing live stream (with ownership check)
func (s *LiveStreamService) Update(ctx context.Context, id, userID uuid.UUID, stream *models.LiveStream) (*models.LiveStream, error) {
existing, err := s.repo.GetByID(ctx, id)
if err != nil {
return nil, err
}
if existing.UserID != userID {
return nil, errors.New("live stream not found")
}
stream.ID = id
stream.UserID = userID
if err := s.repo.Update(ctx, stream); err != nil {
return nil, err
}
return stream, nil
}
// Delete deletes a live stream (with ownership check)
func (s *LiveStreamService) Delete(ctx context.Context, id, userID uuid.UUID) error {
existing, err := s.repo.GetByID(ctx, id)
if err != nil {
return err
}
if existing.UserID != userID {
return errors.New("live stream not found")
}
return s.repo.Delete(ctx, id)
}