veza/veza-backend-api/internal/handlers/live_stream_handler.go
senke ae586f6134 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

97 lines
2.8 KiB
Go

package handlers
import (
"net/http"
"strconv"
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"go.uber.org/zap"
apperrors "veza-backend-api/internal/errors"
"veza-backend-api/internal/models"
"veza-backend-api/internal/services"
)
// LiveStreamHandler handles live stream HTTP requests
type LiveStreamHandler struct {
service *services.LiveStreamService
logger *zap.Logger
}
// NewLiveStreamHandler creates a new LiveStreamHandler
func NewLiveStreamHandler(service *services.LiveStreamService, logger *zap.Logger) *LiveStreamHandler {
return &LiveStreamHandler{service: service, logger: logger}
}
// CreateLiveStreamRequest represents the request body for creating a live stream
type CreateLiveStreamRequest struct {
Title string `json:"title" binding:"required"`
Description string `json:"description"`
Category string `json:"category"`
ThumbnailURL string `json:"thumbnailUrl"`
StreamerName string `json:"streamer"`
Tags []string `json:"tags"`
}
// ListLiveStreams returns all live streams (public - optionally filter by is_live)
func (h *LiveStreamHandler) ListLiveStreams(c *gin.Context) {
var isLive *bool
if q := c.Query("is_live"); q != "" {
b, err := strconv.ParseBool(q)
if err == nil {
isLive = &b
}
}
streams, err := h.service.List(c.Request.Context(), isLive)
if err != nil {
RespondWithAppError(c, apperrors.Wrap(apperrors.ErrCodeInternal, "Failed to list streams", err))
return
}
RespondSuccess(c, http.StatusOK, gin.H{"streams": streams})
}
// GetLiveStream returns a single live stream by ID
func (h *LiveStreamHandler) GetLiveStream(c *gin.Context) {
id, err := uuid.Parse(c.Param("id"))
if err != nil {
RespondWithAppError(c, apperrors.NewValidationError("invalid stream ID"))
return
}
stream, err := h.service.Get(c.Request.Context(), id)
if err != nil {
RespondWithAppError(c, apperrors.NewNotFoundError("stream not found"))
return
}
RespondSuccess(c, http.StatusOK, gin.H{"stream": stream})
}
// CreateLiveStream creates a new live stream (requires auth)
func (h *LiveStreamHandler) CreateLiveStream(c *gin.Context) {
userID, ok := GetUserIDUUID(c)
if !ok {
return
}
var req CreateLiveStreamRequest
if appErr := NewCommonHandler(h.logger).BindAndValidateJSON(c, &req); appErr != nil {
RespondWithAppError(c, appErr)
return
}
stream := &models.LiveStream{
Title: req.Title,
Description: req.Description,
Category: req.Category,
ThumbnailURL: req.ThumbnailURL,
StreamerName: req.StreamerName,
Tags: req.Tags,
}
if stream.StreamerName == "" {
stream.StreamerName = "Streamer"
}
created, err := h.service.Create(c.Request.Context(), userID, stream)
if err != nil {
RespondWithAppError(c, apperrors.Wrap(apperrors.ErrCodeInternal, "Failed to create stream", err))
return
}
RespondSuccess(c, http.StatusCreated, gin.H{"stream": created})
}