2025-12-03 19:29:37 +00:00
|
|
|
package social
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2026-03-02 11:35:49 +00:00
|
|
|
"encoding/base64"
|
2025-12-03 19:29:37 +00:00
|
|
|
"fmt"
|
2026-03-02 11:35:49 +00:00
|
|
|
"strconv"
|
2026-02-21 04:26:52 +00:00
|
|
|
"strings"
|
2026-03-02 11:35:49 +00:00
|
|
|
"time"
|
2025-12-03 19:29:37 +00:00
|
|
|
|
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
"go.uber.org/zap"
|
|
|
|
|
"gorm.io/gorm"
|
2026-02-20 17:33:17 +00:00
|
|
|
|
2026-02-21 04:26:52 +00:00
|
|
|
"veza-backend-api/internal/models"
|
2026-02-20 17:33:17 +00:00
|
|
|
"veza-backend-api/internal/services"
|
2025-12-03 19:29:37 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// SocialService gère les interactions sociales
|
|
|
|
|
type SocialService interface {
|
|
|
|
|
CreatePost(ctx context.Context, userID uuid.UUID, content string, attachments map[string]uuid.UUID) (*Post, error)
|
2026-02-21 04:31:12 +00:00
|
|
|
GetGlobalFeed(ctx context.Context, limit, offset int, feedType string, userID *uuid.UUID) ([]FeedItem, error)
|
2026-03-02 11:35:49 +00:00
|
|
|
GetGlobalFeedWithCursor(ctx context.Context, limit int, cursor, feedType string, userID *uuid.UUID) ([]FeedItem, string, error) // v0.931: keyset cursor
|
2025-12-03 19:29:37 +00:00
|
|
|
GetUserFeed(ctx context.Context, userID uuid.UUID, limit, offset int) ([]FeedItem, error)
|
2025-12-06 16:21:59 +00:00
|
|
|
|
feat: Visual masterpiece - true light mode & premium UI
🎨 **True Light/Dark Mode**
- Implemented proper light mode with inverted color scheme
- Smooth theme transitions (0.3s ease)
- Light mode colors: white backgrounds, dark text, vibrant accents
- System theme detection with proper class application
🌈 **Enhanced Theme System**
- 4 color themes work in both light and dark modes
- Cyber (cyan/magenta), Ocean (blue/teal), Forest (green/lime), Sunset (orange/purple)
- Theme-specific glassmorphism effects
- Proper contrast in light mode
✨ **Premium Animations**
- Float, glow-pulse, slide-in, scale-in, rotate-in animations
- Smooth page transitions
- Hover effects with depth (lift, glow, scale)
- Micro-interactions on all interactive elements
🎯 **Visual Polish**
- Enhanced glassmorphism for light/dark modes
- Custom scrollbar with theme colors
- Beautiful text selection
- Focus indicators for accessibility
- Premium utility classes
🔧 **Technical Improvements**
- Updated UIStore to properly apply light/dark classes
- Added data-theme attribute for CSS targeting
- Smooth scroll behavior
- Optimized transitions
The app is now a visual masterpiece with perfect light/dark mode support!
2026-01-11 01:32:21 +00:00
|
|
|
GetPostsByUser(ctx context.Context, userID uuid.UUID, limit, offset int) ([]Post, error)
|
|
|
|
|
|
2025-12-03 19:29:37 +00:00
|
|
|
// Interactions
|
|
|
|
|
ToggleLike(ctx context.Context, userID uuid.UUID, targetID uuid.UUID, targetType string) (bool, error)
|
|
|
|
|
AddComment(ctx context.Context, userID uuid.UUID, targetID uuid.UUID, targetType string, content string) (*Comment, error)
|
2025-12-06 16:21:59 +00:00
|
|
|
|
2025-12-03 19:29:37 +00:00
|
|
|
// Internal
|
|
|
|
|
CreateActivityPost(ctx context.Context, userID uuid.UUID, content string, meta map[string]interface{}) error
|
2026-02-20 17:32:16 +00:00
|
|
|
|
|
|
|
|
// Trending (v0.203 Lot L)
|
|
|
|
|
GetTrendingHashtags(ctx context.Context, limit int) ([]TrendingTag, error)
|
2025-12-03 19:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Service implémente SocialService
|
|
|
|
|
type Service struct {
|
2026-02-20 17:33:17 +00:00
|
|
|
db *gorm.DB
|
|
|
|
|
logger *zap.Logger
|
|
|
|
|
cacheService *services.CacheService // optional, for trending cache
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetCacheService définit le service de cache (optionnel, pour trending)
|
|
|
|
|
func (s *Service) SetCacheService(cache *services.CacheService) {
|
|
|
|
|
s.cacheService = cache
|
2025-12-03 19:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewService crée une nouvelle instance du service social
|
|
|
|
|
func NewService(db *gorm.DB, logger *zap.Logger) *Service {
|
|
|
|
|
return &Service{
|
|
|
|
|
db: db,
|
|
|
|
|
logger: logger,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreatePost crée une nouvelle publication
|
|
|
|
|
func (s *Service) CreatePost(ctx context.Context, userID uuid.UUID, content string, attachments map[string]uuid.UUID) (*Post, error) {
|
|
|
|
|
post := &Post{
|
|
|
|
|
UserID: userID,
|
|
|
|
|
Content: content,
|
|
|
|
|
Type: PostTypeStatus,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Handle attachments
|
|
|
|
|
if trackID, ok := attachments["track_id"]; ok {
|
|
|
|
|
post.TrackID = &trackID
|
|
|
|
|
post.Type = PostTypeShare
|
|
|
|
|
}
|
|
|
|
|
if playlistID, ok := attachments["playlist_id"]; ok {
|
|
|
|
|
post.PlaylistID = &playlistID
|
|
|
|
|
post.Type = PostTypeShare
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if err := s.db.Create(post).Error; err != nil {
|
|
|
|
|
s.logger.Error("Failed to create post", zap.Error(err), zap.String("user_id", userID.String()))
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return post, nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 04:31:12 +00:00
|
|
|
// GetGlobalFeed récupère un flux d'activité global (S1.2, S1.6: enrichi, type filter)
|
|
|
|
|
func (s *Service) GetGlobalFeed(ctx context.Context, limit, offset int, feedType string, userID *uuid.UUID) ([]FeedItem, error) {
|
|
|
|
|
query := s.db.WithContext(ctx).Model(&Post{})
|
|
|
|
|
if feedType == "following" && userID != nil {
|
|
|
|
|
// Posts from users that current user follows
|
|
|
|
|
query = query.Joins("INNER JOIN follows ON follows.followed_id = posts.user_id AND follows.follower_id = ?", *userID)
|
2026-02-21 04:48:59 +00:00
|
|
|
} else if feedType == "groups" && userID != nil {
|
|
|
|
|
// S2.4: Posts from members of groups the current user belongs to
|
|
|
|
|
// Subquery: user_ids that share at least one group with current user
|
|
|
|
|
subQuery := s.db.WithContext(ctx).Model(&GroupMember{}).
|
|
|
|
|
Select("DISTINCT gm2.user_id").
|
|
|
|
|
Joins("INNER JOIN group_members gm2 ON group_members.group_id = gm2.group_id AND gm2.user_id != ?", *userID).
|
|
|
|
|
Where("group_members.user_id = ?", *userID)
|
|
|
|
|
query = query.Where("posts.user_id IN (?)", subQuery)
|
2026-02-21 04:31:12 +00:00
|
|
|
}
|
2025-12-03 19:29:37 +00:00
|
|
|
var posts []Post
|
2026-02-21 04:31:12 +00:00
|
|
|
if err := query.Order("posts.created_at desc").Limit(limit).Offset(offset).Find(&posts).Error; err != nil {
|
2025-12-03 19:29:37 +00:00
|
|
|
return nil, err
|
|
|
|
|
}
|
2026-03-02 11:35:49 +00:00
|
|
|
return s.enrichFeedFromPosts(ctx, posts)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GetGlobalFeedWithCursor uses keyset pagination on (created_at, id) for consistent performance (v0.931).
|
|
|
|
|
// Cursor format: base64(created_at_unix_nano|uuid). Returns feed items and next cursor.
|
|
|
|
|
func (s *Service) GetGlobalFeedWithCursor(ctx context.Context, limit int, cursor, feedType string, userID *uuid.UUID) ([]FeedItem, string, error) {
|
|
|
|
|
query := s.db.WithContext(ctx).Model(&Post{})
|
|
|
|
|
if feedType == "following" && userID != nil {
|
|
|
|
|
query = query.Joins("INNER JOIN follows ON follows.followed_id = posts.user_id AND follows.follower_id = ?", *userID)
|
|
|
|
|
} else if feedType == "groups" && userID != nil {
|
|
|
|
|
subQuery := s.db.WithContext(ctx).Model(&GroupMember{}).
|
|
|
|
|
Select("DISTINCT gm2.user_id").
|
|
|
|
|
Joins("INNER JOIN group_members gm2 ON group_members.group_id = gm2.group_id AND gm2.user_id != ?", *userID).
|
|
|
|
|
Where("group_members.user_id = ?", *userID)
|
|
|
|
|
query = query.Where("posts.user_id IN (?)", subQuery)
|
|
|
|
|
}
|
2025-12-03 19:29:37 +00:00
|
|
|
|
2026-03-02 11:35:49 +00:00
|
|
|
var cursorCreatedAt int64
|
|
|
|
|
var cursorID uuid.UUID
|
|
|
|
|
if cursor != "" {
|
|
|
|
|
decoded, err := base64.RawURLEncoding.DecodeString(cursor)
|
|
|
|
|
if err == nil {
|
|
|
|
|
parts := strings.SplitN(string(decoded), "|", 2)
|
|
|
|
|
if len(parts) == 2 {
|
|
|
|
|
if ts, err := strconv.ParseInt(parts[0], 10, 64); err == nil {
|
|
|
|
|
cursorCreatedAt = ts
|
|
|
|
|
}
|
|
|
|
|
if uid, err := uuid.Parse(parts[1]); err == nil {
|
|
|
|
|
cursorID = uid
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if cursor != "" && (cursorCreatedAt != 0 || cursorID != uuid.Nil) {
|
|
|
|
|
query = query.Where("(posts.created_at, posts.id) < (?, ?)", time.Unix(0, cursorCreatedAt), cursorID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if limit <= 0 {
|
|
|
|
|
limit = 20
|
|
|
|
|
}
|
|
|
|
|
if limit > 50 {
|
|
|
|
|
limit = 50
|
|
|
|
|
}
|
|
|
|
|
query = query.Order("posts.created_at desc, posts.id desc").Limit(limit + 1)
|
|
|
|
|
|
|
|
|
|
var posts []Post
|
|
|
|
|
if err := query.Find(&posts).Error; err != nil {
|
|
|
|
|
return nil, "", err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var nextCursor string
|
|
|
|
|
if len(posts) > limit {
|
|
|
|
|
last := posts[limit-1]
|
|
|
|
|
nextCursor = base64.RawURLEncoding.EncodeToString([]byte(
|
|
|
|
|
fmt.Sprintf("%d|%s", last.CreatedAt.UnixNano(), last.ID.String())))
|
|
|
|
|
posts = posts[:limit]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
feed, err := s.enrichFeedFromPosts(ctx, posts)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, "", err
|
|
|
|
|
}
|
|
|
|
|
return feed, nextCursor, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *Service) enrichFeedFromPosts(ctx context.Context, posts []Post) ([]FeedItem, error) {
|
2025-12-03 19:29:37 +00:00
|
|
|
var feed []FeedItem
|
2026-02-21 04:26:52 +00:00
|
|
|
actorIDs := make(map[uuid.UUID]bool)
|
|
|
|
|
var trackIDs []uuid.UUID
|
|
|
|
|
for _, p := range posts {
|
|
|
|
|
actorIDs[p.UserID] = true
|
|
|
|
|
if p.TrackID != nil {
|
|
|
|
|
trackIDs = append(trackIDs, *p.TrackID)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
actors := make(map[uuid.UUID]struct{ Name, Avatar string })
|
|
|
|
|
if len(actorIDs) > 0 {
|
|
|
|
|
ids := make([]uuid.UUID, 0, len(actorIDs))
|
|
|
|
|
for id := range actorIDs {
|
|
|
|
|
ids = append(ids, id)
|
|
|
|
|
}
|
|
|
|
|
var users []models.User
|
|
|
|
|
if err := s.db.WithContext(ctx).Where("id IN ?", ids).Find(&users).Error; err == nil {
|
|
|
|
|
for _, u := range users {
|
|
|
|
|
name := u.Username
|
|
|
|
|
if u.FirstName != "" || u.LastName != "" {
|
|
|
|
|
name = (u.FirstName + " " + u.LastName)
|
|
|
|
|
if name = strings.TrimSpace(name); name == "" {
|
|
|
|
|
name = u.Username
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
actors[u.ID] = struct{ Name, Avatar string }{Name: name, Avatar: u.Avatar}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tracks := make(map[uuid.UUID]*models.Track)
|
|
|
|
|
if len(trackIDs) > 0 {
|
|
|
|
|
var tr []models.Track
|
|
|
|
|
if err := s.db.WithContext(ctx).Where("id IN ?", trackIDs).Find(&tr).Error; err == nil {
|
|
|
|
|
for i := range tr {
|
|
|
|
|
tracks[tr[i].ID] = &tr[i]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 19:29:37 +00:00
|
|
|
for _, p := range posts {
|
|
|
|
|
targetType := "none"
|
|
|
|
|
targetID := uuid.Nil
|
2025-12-06 16:21:59 +00:00
|
|
|
|
2025-12-03 19:29:37 +00:00
|
|
|
if p.TrackID != nil {
|
|
|
|
|
targetType = "track"
|
|
|
|
|
targetID = *p.TrackID
|
|
|
|
|
} else if p.PlaylistID != nil {
|
|
|
|
|
targetType = "playlist"
|
|
|
|
|
targetID = *p.PlaylistID
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item := FeedItem{
|
|
|
|
|
ID: fmt.Sprintf("post:%s", p.ID.String()),
|
|
|
|
|
Type: ActivityPost,
|
|
|
|
|
ActorID: p.UserID,
|
|
|
|
|
TargetID: targetID,
|
|
|
|
|
TargetType: targetType,
|
|
|
|
|
Content: p.Content,
|
|
|
|
|
CreatedAt: p.CreatedAt,
|
|
|
|
|
}
|
2025-12-06 16:21:59 +00:00
|
|
|
|
2026-02-21 04:26:52 +00:00
|
|
|
if a, ok := actors[p.UserID]; ok {
|
|
|
|
|
item.ActorName = a.Name
|
|
|
|
|
item.ActorAvatar = a.Avatar
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if targetType == "track" {
|
|
|
|
|
if t, ok := tracks[targetID]; ok {
|
|
|
|
|
item.Track = &FeedItemTrack{
|
|
|
|
|
ID: t.ID.String(),
|
|
|
|
|
Title: t.Title,
|
|
|
|
|
Artist: t.Artist,
|
|
|
|
|
CoverURL: t.CoverArtPath,
|
|
|
|
|
Duration: formatDuration(t.Duration),
|
|
|
|
|
Genre: t.Genre,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 19:29:37 +00:00
|
|
|
if p.Type == PostTypeActivity {
|
2026-02-21 04:26:52 +00:00
|
|
|
item.Type = ActivityPurchase
|
2025-12-03 19:29:37 +00:00
|
|
|
}
|
2025-12-06 16:21:59 +00:00
|
|
|
|
2025-12-03 19:29:37 +00:00
|
|
|
feed = append(feed, item)
|
|
|
|
|
}
|
|
|
|
|
return feed, nil
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-21 04:26:52 +00:00
|
|
|
func formatDuration(seconds int) string {
|
|
|
|
|
m := seconds / 60
|
|
|
|
|
s := seconds % 60
|
|
|
|
|
return fmt.Sprintf("%d:%02d", m, s)
|
|
|
|
|
}
|
|
|
|
|
|
feat: Visual masterpiece - true light mode & premium UI
🎨 **True Light/Dark Mode**
- Implemented proper light mode with inverted color scheme
- Smooth theme transitions (0.3s ease)
- Light mode colors: white backgrounds, dark text, vibrant accents
- System theme detection with proper class application
🌈 **Enhanced Theme System**
- 4 color themes work in both light and dark modes
- Cyber (cyan/magenta), Ocean (blue/teal), Forest (green/lime), Sunset (orange/purple)
- Theme-specific glassmorphism effects
- Proper contrast in light mode
✨ **Premium Animations**
- Float, glow-pulse, slide-in, scale-in, rotate-in animations
- Smooth page transitions
- Hover effects with depth (lift, glow, scale)
- Micro-interactions on all interactive elements
🎯 **Visual Polish**
- Enhanced glassmorphism for light/dark modes
- Custom scrollbar with theme colors
- Beautiful text selection
- Focus indicators for accessibility
- Premium utility classes
🔧 **Technical Improvements**
- Updated UIStore to properly apply light/dark classes
- Added data-theme attribute for CSS targeting
- Smooth scroll behavior
- Optimized transitions
The app is now a visual masterpiece with perfect light/dark mode support!
2026-01-11 01:32:21 +00:00
|
|
|
// GetUserFeed récupère le flux d'un utilisateur (posts from people they follow + their own)
|
|
|
|
|
// NOTE: For now it just returns their own posts as FeedItems, keeping meaningful naming.
|
2025-12-03 19:29:37 +00:00
|
|
|
func (s *Service) GetUserFeed(ctx context.Context, userID uuid.UUID, limit, offset int) ([]FeedItem, error) {
|
|
|
|
|
var posts []Post
|
|
|
|
|
if err := s.db.Where("user_id = ?", userID).Order("created_at desc").Limit(limit).Offset(offset).Find(&posts).Error; err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var feed []FeedItem
|
|
|
|
|
for _, p := range posts {
|
|
|
|
|
item := FeedItem{
|
|
|
|
|
ID: fmt.Sprintf("post:%s", p.ID.String()),
|
|
|
|
|
Type: ActivityPost,
|
|
|
|
|
ActorID: p.UserID,
|
|
|
|
|
Content: p.Content,
|
|
|
|
|
CreatedAt: p.CreatedAt,
|
|
|
|
|
TargetType: "user_wall",
|
|
|
|
|
}
|
|
|
|
|
feed = append(feed, item)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return feed, nil
|
|
|
|
|
}
|
|
|
|
|
|
feat: Visual masterpiece - true light mode & premium UI
🎨 **True Light/Dark Mode**
- Implemented proper light mode with inverted color scheme
- Smooth theme transitions (0.3s ease)
- Light mode colors: white backgrounds, dark text, vibrant accents
- System theme detection with proper class application
🌈 **Enhanced Theme System**
- 4 color themes work in both light and dark modes
- Cyber (cyan/magenta), Ocean (blue/teal), Forest (green/lime), Sunset (orange/purple)
- Theme-specific glassmorphism effects
- Proper contrast in light mode
✨ **Premium Animations**
- Float, glow-pulse, slide-in, scale-in, rotate-in animations
- Smooth page transitions
- Hover effects with depth (lift, glow, scale)
- Micro-interactions on all interactive elements
🎯 **Visual Polish**
- Enhanced glassmorphism for light/dark modes
- Custom scrollbar with theme colors
- Beautiful text selection
- Focus indicators for accessibility
- Premium utility classes
🔧 **Technical Improvements**
- Updated UIStore to properly apply light/dark classes
- Added data-theme attribute for CSS targeting
- Smooth scroll behavior
- Optimized transitions
The app is now a visual masterpiece with perfect light/dark mode support!
2026-01-11 01:32:21 +00:00
|
|
|
// GetPostsByUser récupère les posts d'un utilisateur spécifique
|
|
|
|
|
func (s *Service) GetPostsByUser(ctx context.Context, userID uuid.UUID, limit, offset int) ([]Post, error) {
|
|
|
|
|
var posts []Post
|
|
|
|
|
if err := s.db.Where("user_id = ?", userID).Order("created_at desc").Limit(limit).Offset(offset).Find(&posts).Error; err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
}
|
|
|
|
|
return posts, nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-03 19:29:37 +00:00
|
|
|
// ToggleLike ajoute ou supprime un like
|
P0: stabilisation backend/chat/stream + nouvelle base migrations v1
Backend Go:
- Remplacement complet des anciennes migrations par la base V1 alignée sur ORIGIN.
- Durcissement global du parsing JSON (BindAndValidateJSON + RespondWithAppError).
- Sécurisation de config.go, CORS, statuts de santé et monitoring.
- Implémentation des transactions P0 (RBAC, duplication de playlists, social toggles).
- Ajout d’un job worker structuré (emails, analytics, thumbnails) + tests associés.
- Nouvelle doc backend : AUDIT_CONFIG, BACKEND_CONFIG, AUTH_PASSWORD_RESET, JOB_WORKER_*.
Chat server (Rust):
- Refonte du pipeline JWT + sécurité, audit et rate limiting avancé.
- Implémentation complète du cycle de message (read receipts, delivered, edit/delete, typing).
- Nettoyage des panics, gestion d’erreurs robuste, logs structurés.
- Migrations chat alignées sur le schéma UUID et nouvelles features.
Stream server (Rust):
- Refonte du moteur de streaming (encoding pipeline + HLS) et des modules core.
- Transactions P0 pour les jobs et segments, garanties d’atomicité.
- Documentation détaillée de la pipeline (AUDIT_STREAM_*, DESIGN_STREAM_PIPELINE, TRANSACTIONS_P0_IMPLEMENTATION).
Documentation & audits:
- TRIAGE.md et AUDIT_STABILITY.md à jour avec l’état réel des 3 services.
- Cartographie complète des migrations et des transactions (DB_MIGRATIONS_*, DB_TRANSACTION_PLAN, AUDIT_DB_TRANSACTIONS, TRANSACTION_TESTS_PHASE3).
- Scripts de reset et de cleanup pour la lab DB et la V1.
Ce commit fige l’ensemble du travail de stabilisation P0 (UUID, backend, chat et stream) avant les phases suivantes (Coherence Guardian, WS hardening, etc.).
2025-12-06 10:14:38 +00:00
|
|
|
// Transactionnelle : SELECT like + DELETE/CREATE + UPDATE compteur dans une seule transaction
|
2025-12-03 19:29:37 +00:00
|
|
|
func (s *Service) ToggleLike(ctx context.Context, userID uuid.UUID, targetID uuid.UUID, targetType string) (bool, error) {
|
P0: stabilisation backend/chat/stream + nouvelle base migrations v1
Backend Go:
- Remplacement complet des anciennes migrations par la base V1 alignée sur ORIGIN.
- Durcissement global du parsing JSON (BindAndValidateJSON + RespondWithAppError).
- Sécurisation de config.go, CORS, statuts de santé et monitoring.
- Implémentation des transactions P0 (RBAC, duplication de playlists, social toggles).
- Ajout d’un job worker structuré (emails, analytics, thumbnails) + tests associés.
- Nouvelle doc backend : AUDIT_CONFIG, BACKEND_CONFIG, AUTH_PASSWORD_RESET, JOB_WORKER_*.
Chat server (Rust):
- Refonte du pipeline JWT + sécurité, audit et rate limiting avancé.
- Implémentation complète du cycle de message (read receipts, delivered, edit/delete, typing).
- Nettoyage des panics, gestion d’erreurs robuste, logs structurés.
- Migrations chat alignées sur le schéma UUID et nouvelles features.
Stream server (Rust):
- Refonte du moteur de streaming (encoding pipeline + HLS) et des modules core.
- Transactions P0 pour les jobs et segments, garanties d’atomicité.
- Documentation détaillée de la pipeline (AUDIT_STREAM_*, DESIGN_STREAM_PIPELINE, TRANSACTIONS_P0_IMPLEMENTATION).
Documentation & audits:
- TRIAGE.md et AUDIT_STABILITY.md à jour avec l’état réel des 3 services.
- Cartographie complète des migrations et des transactions (DB_MIGRATIONS_*, DB_TRANSACTION_PLAN, AUDIT_DB_TRANSACTIONS, TRANSACTION_TESTS_PHASE3).
- Scripts de reset et de cleanup pour la lab DB et la V1.
Ce commit fige l’ensemble du travail de stabilisation P0 (UUID, backend, chat et stream) avant les phases suivantes (Coherence Guardian, WS hardening, etc.).
2025-12-06 10:14:38 +00:00
|
|
|
var liked bool
|
|
|
|
|
|
|
|
|
|
err := s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
|
|
|
|
// 1. VÉRIFICATION : Like existe déjà ? (SELECT dans la transaction)
|
|
|
|
|
var like Like
|
|
|
|
|
err := tx.Where("user_id = ? AND target_id = ? AND target_type = ?", userID, targetID, targetType).First(&like).Error
|
|
|
|
|
|
|
|
|
|
if err == nil {
|
|
|
|
|
// 2a. Mode UNLIKE : Like existe, on le supprime
|
|
|
|
|
if err := tx.Delete(&like).Error; err != nil {
|
|
|
|
|
return fmt.Errorf("ToggleLike: failed to delete like: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3a. Décrémenter le compteur si c'est un post (dans la transaction)
|
|
|
|
|
if targetType == "post" {
|
|
|
|
|
if err := tx.Model(&Post{}).Where("id = ?", targetID).Update("like_count", gorm.Expr("like_count - 1")).Error; err != nil {
|
|
|
|
|
return fmt.Errorf("ToggleLike: failed to decrement like_count: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
liked = false
|
|
|
|
|
return nil
|
|
|
|
|
} else if err == gorm.ErrRecordNotFound {
|
|
|
|
|
// 2b. Mode LIKE : Like n'existe pas, on le crée
|
2025-12-16 16:23:49 +00:00
|
|
|
// Vérifier d'abord que la ressource existe (pour les posts)
|
|
|
|
|
if targetType == "post" {
|
|
|
|
|
var post Post
|
|
|
|
|
if err := tx.Where("id = ?", targetID).First(&post).Error; err != nil {
|
|
|
|
|
if err == gorm.ErrRecordNotFound {
|
|
|
|
|
return fmt.Errorf("ToggleLike: post not found: %w", err)
|
|
|
|
|
}
|
|
|
|
|
return fmt.Errorf("ToggleLike: failed to check post existence: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
P0: stabilisation backend/chat/stream + nouvelle base migrations v1
Backend Go:
- Remplacement complet des anciennes migrations par la base V1 alignée sur ORIGIN.
- Durcissement global du parsing JSON (BindAndValidateJSON + RespondWithAppError).
- Sécurisation de config.go, CORS, statuts de santé et monitoring.
- Implémentation des transactions P0 (RBAC, duplication de playlists, social toggles).
- Ajout d’un job worker structuré (emails, analytics, thumbnails) + tests associés.
- Nouvelle doc backend : AUDIT_CONFIG, BACKEND_CONFIG, AUTH_PASSWORD_RESET, JOB_WORKER_*.
Chat server (Rust):
- Refonte du pipeline JWT + sécurité, audit et rate limiting avancé.
- Implémentation complète du cycle de message (read receipts, delivered, edit/delete, typing).
- Nettoyage des panics, gestion d’erreurs robuste, logs structurés.
- Migrations chat alignées sur le schéma UUID et nouvelles features.
Stream server (Rust):
- Refonte du moteur de streaming (encoding pipeline + HLS) et des modules core.
- Transactions P0 pour les jobs et segments, garanties d’atomicité.
- Documentation détaillée de la pipeline (AUDIT_STREAM_*, DESIGN_STREAM_PIPELINE, TRANSACTIONS_P0_IMPLEMENTATION).
Documentation & audits:
- TRIAGE.md et AUDIT_STABILITY.md à jour avec l’état réel des 3 services.
- Cartographie complète des migrations et des transactions (DB_MIGRATIONS_*, DB_TRANSACTION_PLAN, AUDIT_DB_TRANSACTIONS, TRANSACTION_TESTS_PHASE3).
- Scripts de reset et de cleanup pour la lab DB et la V1.
Ce commit fige l’ensemble du travail de stabilisation P0 (UUID, backend, chat et stream) avant les phases suivantes (Coherence Guardian, WS hardening, etc.).
2025-12-06 10:14:38 +00:00
|
|
|
like = Like{
|
|
|
|
|
UserID: userID,
|
|
|
|
|
TargetID: targetID,
|
|
|
|
|
TargetType: targetType,
|
|
|
|
|
}
|
|
|
|
|
if err := tx.Create(&like).Error; err != nil {
|
|
|
|
|
return fmt.Errorf("ToggleLike: failed to create like: %w", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3b. Incrémenter le compteur si c'est un post (dans la transaction)
|
|
|
|
|
if targetType == "post" {
|
|
|
|
|
if err := tx.Model(&Post{}).Where("id = ?", targetID).Update("like_count", gorm.Expr("like_count + 1")).Error; err != nil {
|
|
|
|
|
return fmt.Errorf("ToggleLike: failed to increment like_count: %w", err)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
liked = true
|
|
|
|
|
return nil
|
|
|
|
|
} else {
|
|
|
|
|
return fmt.Errorf("ToggleLike: failed to check like existence: %w", err)
|
2025-12-03 19:29:37 +00:00
|
|
|
}
|
P0: stabilisation backend/chat/stream + nouvelle base migrations v1
Backend Go:
- Remplacement complet des anciennes migrations par la base V1 alignée sur ORIGIN.
- Durcissement global du parsing JSON (BindAndValidateJSON + RespondWithAppError).
- Sécurisation de config.go, CORS, statuts de santé et monitoring.
- Implémentation des transactions P0 (RBAC, duplication de playlists, social toggles).
- Ajout d’un job worker structuré (emails, analytics, thumbnails) + tests associés.
- Nouvelle doc backend : AUDIT_CONFIG, BACKEND_CONFIG, AUTH_PASSWORD_RESET, JOB_WORKER_*.
Chat server (Rust):
- Refonte du pipeline JWT + sécurité, audit et rate limiting avancé.
- Implémentation complète du cycle de message (read receipts, delivered, edit/delete, typing).
- Nettoyage des panics, gestion d’erreurs robuste, logs structurés.
- Migrations chat alignées sur le schéma UUID et nouvelles features.
Stream server (Rust):
- Refonte du moteur de streaming (encoding pipeline + HLS) et des modules core.
- Transactions P0 pour les jobs et segments, garanties d’atomicité.
- Documentation détaillée de la pipeline (AUDIT_STREAM_*, DESIGN_STREAM_PIPELINE, TRANSACTIONS_P0_IMPLEMENTATION).
Documentation & audits:
- TRIAGE.md et AUDIT_STABILITY.md à jour avec l’état réel des 3 services.
- Cartographie complète des migrations et des transactions (DB_MIGRATIONS_*, DB_TRANSACTION_PLAN, AUDIT_DB_TRANSACTIONS, TRANSACTION_TESTS_PHASE3).
- Scripts de reset et de cleanup pour la lab DB et la V1.
Ce commit fige l’ensemble du travail de stabilisation P0 (UUID, backend, chat et stream) avant les phases suivantes (Coherence Guardian, WS hardening, etc.).
2025-12-06 10:14:38 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
|
return false, err // Rollback automatique si erreur
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return liked, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// AddComment ajoute un commentaire
|
|
|
|
|
// Transactionnelle : CREATE comment + UPDATE compteur dans une seule transaction
|
|
|
|
|
func (s *Service) AddComment(ctx context.Context, userID uuid.UUID, targetID uuid.UUID, targetType string, content string) (*Comment, error) {
|
|
|
|
|
var comment *Comment
|
|
|
|
|
|
|
|
|
|
err := s.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
|
|
|
|
// 1. VALIDATION : Post existe ? (SELECT dans la transaction si targetType == "post")
|
2025-12-03 19:29:37 +00:00
|
|
|
if targetType == "post" {
|
P0: stabilisation backend/chat/stream + nouvelle base migrations v1
Backend Go:
- Remplacement complet des anciennes migrations par la base V1 alignée sur ORIGIN.
- Durcissement global du parsing JSON (BindAndValidateJSON + RespondWithAppError).
- Sécurisation de config.go, CORS, statuts de santé et monitoring.
- Implémentation des transactions P0 (RBAC, duplication de playlists, social toggles).
- Ajout d’un job worker structuré (emails, analytics, thumbnails) + tests associés.
- Nouvelle doc backend : AUDIT_CONFIG, BACKEND_CONFIG, AUTH_PASSWORD_RESET, JOB_WORKER_*.
Chat server (Rust):
- Refonte du pipeline JWT + sécurité, audit et rate limiting avancé.
- Implémentation complète du cycle de message (read receipts, delivered, edit/delete, typing).
- Nettoyage des panics, gestion d’erreurs robuste, logs structurés.
- Migrations chat alignées sur le schéma UUID et nouvelles features.
Stream server (Rust):
- Refonte du moteur de streaming (encoding pipeline + HLS) et des modules core.
- Transactions P0 pour les jobs et segments, garanties d’atomicité.
- Documentation détaillée de la pipeline (AUDIT_STREAM_*, DESIGN_STREAM_PIPELINE, TRANSACTIONS_P0_IMPLEMENTATION).
Documentation & audits:
- TRIAGE.md et AUDIT_STABILITY.md à jour avec l’état réel des 3 services.
- Cartographie complète des migrations et des transactions (DB_MIGRATIONS_*, DB_TRANSACTION_PLAN, AUDIT_DB_TRANSACTIONS, TRANSACTION_TESTS_PHASE3).
- Scripts de reset et de cleanup pour la lab DB et la V1.
Ce commit fige l’ensemble du travail de stabilisation P0 (UUID, backend, chat et stream) avant les phases suivantes (Coherence Guardian, WS hardening, etc.).
2025-12-06 10:14:38 +00:00
|
|
|
var post Post
|
|
|
|
|
if err := tx.First(&post, "id = ?", targetID).Error; err != nil {
|
|
|
|
|
if err == gorm.ErrRecordNotFound {
|
|
|
|
|
return fmt.Errorf("post not found")
|
|
|
|
|
}
|
|
|
|
|
return fmt.Errorf("AddComment: failed to validate post: %w", err)
|
|
|
|
|
}
|
2025-12-03 19:29:37 +00:00
|
|
|
}
|
P0: stabilisation backend/chat/stream + nouvelle base migrations v1
Backend Go:
- Remplacement complet des anciennes migrations par la base V1 alignée sur ORIGIN.
- Durcissement global du parsing JSON (BindAndValidateJSON + RespondWithAppError).
- Sécurisation de config.go, CORS, statuts de santé et monitoring.
- Implémentation des transactions P0 (RBAC, duplication de playlists, social toggles).
- Ajout d’un job worker structuré (emails, analytics, thumbnails) + tests associés.
- Nouvelle doc backend : AUDIT_CONFIG, BACKEND_CONFIG, AUTH_PASSWORD_RESET, JOB_WORKER_*.
Chat server (Rust):
- Refonte du pipeline JWT + sécurité, audit et rate limiting avancé.
- Implémentation complète du cycle de message (read receipts, delivered, edit/delete, typing).
- Nettoyage des panics, gestion d’erreurs robuste, logs structurés.
- Migrations chat alignées sur le schéma UUID et nouvelles features.
Stream server (Rust):
- Refonte du moteur de streaming (encoding pipeline + HLS) et des modules core.
- Transactions P0 pour les jobs et segments, garanties d’atomicité.
- Documentation détaillée de la pipeline (AUDIT_STREAM_*, DESIGN_STREAM_PIPELINE, TRANSACTIONS_P0_IMPLEMENTATION).
Documentation & audits:
- TRIAGE.md et AUDIT_STABILITY.md à jour avec l’état réel des 3 services.
- Cartographie complète des migrations et des transactions (DB_MIGRATIONS_*, DB_TRANSACTION_PLAN, AUDIT_DB_TRANSACTIONS, TRANSACTION_TESTS_PHASE3).
- Scripts de reset et de cleanup pour la lab DB et la V1.
Ce commit fige l’ensemble du travail de stabilisation P0 (UUID, backend, chat et stream) avant les phases suivantes (Coherence Guardian, WS hardening, etc.).
2025-12-06 10:14:38 +00:00
|
|
|
|
|
|
|
|
// 2. CRÉATION : Commentaire (INSERT dans la transaction)
|
|
|
|
|
comment = &Comment{
|
2025-12-03 19:29:37 +00:00
|
|
|
UserID: userID,
|
|
|
|
|
TargetID: targetID,
|
|
|
|
|
TargetType: targetType,
|
P0: stabilisation backend/chat/stream + nouvelle base migrations v1
Backend Go:
- Remplacement complet des anciennes migrations par la base V1 alignée sur ORIGIN.
- Durcissement global du parsing JSON (BindAndValidateJSON + RespondWithAppError).
- Sécurisation de config.go, CORS, statuts de santé et monitoring.
- Implémentation des transactions P0 (RBAC, duplication de playlists, social toggles).
- Ajout d’un job worker structuré (emails, analytics, thumbnails) + tests associés.
- Nouvelle doc backend : AUDIT_CONFIG, BACKEND_CONFIG, AUTH_PASSWORD_RESET, JOB_WORKER_*.
Chat server (Rust):
- Refonte du pipeline JWT + sécurité, audit et rate limiting avancé.
- Implémentation complète du cycle de message (read receipts, delivered, edit/delete, typing).
- Nettoyage des panics, gestion d’erreurs robuste, logs structurés.
- Migrations chat alignées sur le schéma UUID et nouvelles features.
Stream server (Rust):
- Refonte du moteur de streaming (encoding pipeline + HLS) et des modules core.
- Transactions P0 pour les jobs et segments, garanties d’atomicité.
- Documentation détaillée de la pipeline (AUDIT_STREAM_*, DESIGN_STREAM_PIPELINE, TRANSACTIONS_P0_IMPLEMENTATION).
Documentation & audits:
- TRIAGE.md et AUDIT_STABILITY.md à jour avec l’état réel des 3 services.
- Cartographie complète des migrations et des transactions (DB_MIGRATIONS_*, DB_TRANSACTION_PLAN, AUDIT_DB_TRANSACTIONS, TRANSACTION_TESTS_PHASE3).
- Scripts de reset et de cleanup pour la lab DB et la V1.
Ce commit fige l’ensemble du travail de stabilisation P0 (UUID, backend, chat et stream) avant les phases suivantes (Coherence Guardian, WS hardening, etc.).
2025-12-06 10:14:38 +00:00
|
|
|
Content: content,
|
2025-12-03 19:29:37 +00:00
|
|
|
}
|
P0: stabilisation backend/chat/stream + nouvelle base migrations v1
Backend Go:
- Remplacement complet des anciennes migrations par la base V1 alignée sur ORIGIN.
- Durcissement global du parsing JSON (BindAndValidateJSON + RespondWithAppError).
- Sécurisation de config.go, CORS, statuts de santé et monitoring.
- Implémentation des transactions P0 (RBAC, duplication de playlists, social toggles).
- Ajout d’un job worker structuré (emails, analytics, thumbnails) + tests associés.
- Nouvelle doc backend : AUDIT_CONFIG, BACKEND_CONFIG, AUTH_PASSWORD_RESET, JOB_WORKER_*.
Chat server (Rust):
- Refonte du pipeline JWT + sécurité, audit et rate limiting avancé.
- Implémentation complète du cycle de message (read receipts, delivered, edit/delete, typing).
- Nettoyage des panics, gestion d’erreurs robuste, logs structurés.
- Migrations chat alignées sur le schéma UUID et nouvelles features.
Stream server (Rust):
- Refonte du moteur de streaming (encoding pipeline + HLS) et des modules core.
- Transactions P0 pour les jobs et segments, garanties d’atomicité.
- Documentation détaillée de la pipeline (AUDIT_STREAM_*, DESIGN_STREAM_PIPELINE, TRANSACTIONS_P0_IMPLEMENTATION).
Documentation & audits:
- TRIAGE.md et AUDIT_STABILITY.md à jour avec l’état réel des 3 services.
- Cartographie complète des migrations et des transactions (DB_MIGRATIONS_*, DB_TRANSACTION_PLAN, AUDIT_DB_TRANSACTIONS, TRANSACTION_TESTS_PHASE3).
- Scripts de reset et de cleanup pour la lab DB et la V1.
Ce commit fige l’ensemble du travail de stabilisation P0 (UUID, backend, chat et stream) avant les phases suivantes (Coherence Guardian, WS hardening, etc.).
2025-12-06 10:14:38 +00:00
|
|
|
if err := tx.Create(comment).Error; err != nil {
|
|
|
|
|
return fmt.Errorf("AddComment: failed to create comment: %w", err)
|
2025-12-03 19:29:37 +00:00
|
|
|
}
|
P0: stabilisation backend/chat/stream + nouvelle base migrations v1
Backend Go:
- Remplacement complet des anciennes migrations par la base V1 alignée sur ORIGIN.
- Durcissement global du parsing JSON (BindAndValidateJSON + RespondWithAppError).
- Sécurisation de config.go, CORS, statuts de santé et monitoring.
- Implémentation des transactions P0 (RBAC, duplication de playlists, social toggles).
- Ajout d’un job worker structuré (emails, analytics, thumbnails) + tests associés.
- Nouvelle doc backend : AUDIT_CONFIG, BACKEND_CONFIG, AUTH_PASSWORD_RESET, JOB_WORKER_*.
Chat server (Rust):
- Refonte du pipeline JWT + sécurité, audit et rate limiting avancé.
- Implémentation complète du cycle de message (read receipts, delivered, edit/delete, typing).
- Nettoyage des panics, gestion d’erreurs robuste, logs structurés.
- Migrations chat alignées sur le schéma UUID et nouvelles features.
Stream server (Rust):
- Refonte du moteur de streaming (encoding pipeline + HLS) et des modules core.
- Transactions P0 pour les jobs et segments, garanties d’atomicité.
- Documentation détaillée de la pipeline (AUDIT_STREAM_*, DESIGN_STREAM_PIPELINE, TRANSACTIONS_P0_IMPLEMENTATION).
Documentation & audits:
- TRIAGE.md et AUDIT_STABILITY.md à jour avec l’état réel des 3 services.
- Cartographie complète des migrations et des transactions (DB_MIGRATIONS_*, DB_TRANSACTION_PLAN, AUDIT_DB_TRANSACTIONS, TRANSACTION_TESTS_PHASE3).
- Scripts de reset et de cleanup pour la lab DB et la V1.
Ce commit fige l’ensemble du travail de stabilisation P0 (UUID, backend, chat et stream) avant les phases suivantes (Coherence Guardian, WS hardening, etc.).
2025-12-06 10:14:38 +00:00
|
|
|
|
|
|
|
|
// 3. MISE À JOUR : Compteur (UPDATE dans la transaction)
|
2025-12-03 19:29:37 +00:00
|
|
|
if targetType == "post" {
|
P0: stabilisation backend/chat/stream + nouvelle base migrations v1
Backend Go:
- Remplacement complet des anciennes migrations par la base V1 alignée sur ORIGIN.
- Durcissement global du parsing JSON (BindAndValidateJSON + RespondWithAppError).
- Sécurisation de config.go, CORS, statuts de santé et monitoring.
- Implémentation des transactions P0 (RBAC, duplication de playlists, social toggles).
- Ajout d’un job worker structuré (emails, analytics, thumbnails) + tests associés.
- Nouvelle doc backend : AUDIT_CONFIG, BACKEND_CONFIG, AUTH_PASSWORD_RESET, JOB_WORKER_*.
Chat server (Rust):
- Refonte du pipeline JWT + sécurité, audit et rate limiting avancé.
- Implémentation complète du cycle de message (read receipts, delivered, edit/delete, typing).
- Nettoyage des panics, gestion d’erreurs robuste, logs structurés.
- Migrations chat alignées sur le schéma UUID et nouvelles features.
Stream server (Rust):
- Refonte du moteur de streaming (encoding pipeline + HLS) et des modules core.
- Transactions P0 pour les jobs et segments, garanties d’atomicité.
- Documentation détaillée de la pipeline (AUDIT_STREAM_*, DESIGN_STREAM_PIPELINE, TRANSACTIONS_P0_IMPLEMENTATION).
Documentation & audits:
- TRIAGE.md et AUDIT_STABILITY.md à jour avec l’état réel des 3 services.
- Cartographie complète des migrations et des transactions (DB_MIGRATIONS_*, DB_TRANSACTION_PLAN, AUDIT_DB_TRANSACTIONS, TRANSACTION_TESTS_PHASE3).
- Scripts de reset et de cleanup pour la lab DB et la V1.
Ce commit fige l’ensemble du travail de stabilisation P0 (UUID, backend, chat et stream) avant les phases suivantes (Coherence Guardian, WS hardening, etc.).
2025-12-06 10:14:38 +00:00
|
|
|
if err := tx.Model(&Post{}).Where("id = ?", targetID).Update("comment_count", gorm.Expr("comment_count + 1")).Error; err != nil {
|
|
|
|
|
return fmt.Errorf("AddComment: failed to increment comment_count: %w", err)
|
|
|
|
|
}
|
2025-12-03 19:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
P0: stabilisation backend/chat/stream + nouvelle base migrations v1
Backend Go:
- Remplacement complet des anciennes migrations par la base V1 alignée sur ORIGIN.
- Durcissement global du parsing JSON (BindAndValidateJSON + RespondWithAppError).
- Sécurisation de config.go, CORS, statuts de santé et monitoring.
- Implémentation des transactions P0 (RBAC, duplication de playlists, social toggles).
- Ajout d’un job worker structuré (emails, analytics, thumbnails) + tests associés.
- Nouvelle doc backend : AUDIT_CONFIG, BACKEND_CONFIG, AUTH_PASSWORD_RESET, JOB_WORKER_*.
Chat server (Rust):
- Refonte du pipeline JWT + sécurité, audit et rate limiting avancé.
- Implémentation complète du cycle de message (read receipts, delivered, edit/delete, typing).
- Nettoyage des panics, gestion d’erreurs robuste, logs structurés.
- Migrations chat alignées sur le schéma UUID et nouvelles features.
Stream server (Rust):
- Refonte du moteur de streaming (encoding pipeline + HLS) et des modules core.
- Transactions P0 pour les jobs et segments, garanties d’atomicité.
- Documentation détaillée de la pipeline (AUDIT_STREAM_*, DESIGN_STREAM_PIPELINE, TRANSACTIONS_P0_IMPLEMENTATION).
Documentation & audits:
- TRIAGE.md et AUDIT_STABILITY.md à jour avec l’état réel des 3 services.
- Cartographie complète des migrations et des transactions (DB_MIGRATIONS_*, DB_TRANSACTION_PLAN, AUDIT_DB_TRANSACTIONS, TRANSACTION_TESTS_PHASE3).
- Scripts de reset et de cleanup pour la lab DB et la V1.
Ce commit fige l’ensemble du travail de stabilisation P0 (UUID, backend, chat et stream) avant les phases suivantes (Coherence Guardian, WS hardening, etc.).
2025-12-06 10:14:38 +00:00
|
|
|
// 4. RETOUR nil = commit automatique
|
|
|
|
|
return nil
|
|
|
|
|
})
|
2025-12-03 19:29:37 +00:00
|
|
|
|
P0: stabilisation backend/chat/stream + nouvelle base migrations v1
Backend Go:
- Remplacement complet des anciennes migrations par la base V1 alignée sur ORIGIN.
- Durcissement global du parsing JSON (BindAndValidateJSON + RespondWithAppError).
- Sécurisation de config.go, CORS, statuts de santé et monitoring.
- Implémentation des transactions P0 (RBAC, duplication de playlists, social toggles).
- Ajout d’un job worker structuré (emails, analytics, thumbnails) + tests associés.
- Nouvelle doc backend : AUDIT_CONFIG, BACKEND_CONFIG, AUTH_PASSWORD_RESET, JOB_WORKER_*.
Chat server (Rust):
- Refonte du pipeline JWT + sécurité, audit et rate limiting avancé.
- Implémentation complète du cycle de message (read receipts, delivered, edit/delete, typing).
- Nettoyage des panics, gestion d’erreurs robuste, logs structurés.
- Migrations chat alignées sur le schéma UUID et nouvelles features.
Stream server (Rust):
- Refonte du moteur de streaming (encoding pipeline + HLS) et des modules core.
- Transactions P0 pour les jobs et segments, garanties d’atomicité.
- Documentation détaillée de la pipeline (AUDIT_STREAM_*, DESIGN_STREAM_PIPELINE, TRANSACTIONS_P0_IMPLEMENTATION).
Documentation & audits:
- TRIAGE.md et AUDIT_STABILITY.md à jour avec l’état réel des 3 services.
- Cartographie complète des migrations et des transactions (DB_MIGRATIONS_*, DB_TRANSACTION_PLAN, AUDIT_DB_TRANSACTIONS, TRANSACTION_TESTS_PHASE3).
- Scripts de reset et de cleanup pour la lab DB et la V1.
Ce commit fige l’ensemble du travail de stabilisation P0 (UUID, backend, chat et stream) avant les phases suivantes (Coherence Guardian, WS hardening, etc.).
2025-12-06 10:14:38 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return nil, err // Rollback automatique si erreur
|
2025-12-03 19:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return comment, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CreateActivityPost crée un post automatique pour une activité (ex: Achat)
|
|
|
|
|
func (s *Service) CreateActivityPost(ctx context.Context, userID uuid.UUID, content string, meta map[string]interface{}) error {
|
|
|
|
|
post := &Post{
|
|
|
|
|
UserID: userID,
|
|
|
|
|
Content: content,
|
|
|
|
|
Type: PostTypeActivity,
|
|
|
|
|
}
|
2025-12-06 16:21:59 +00:00
|
|
|
|
2025-12-03 19:29:37 +00:00
|
|
|
if trackIDStr, ok := meta["track_id"].(string); ok {
|
|
|
|
|
if trackID, err := uuid.Parse(trackIDStr); err == nil {
|
|
|
|
|
post.TrackID = &trackID
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return s.db.Create(post).Error
|
|
|
|
|
}
|