veza/veza-backend-api/internal/core/social/models.go

86 lines
3.1 KiB
Go

package social
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// PostType définit le type de post
type PostType string
const (
PostTypeStatus PostType = "status"
PostTypeShare PostType = "share"
PostTypeRelease PostType = "release"
PostTypeActivity PostType = "activity" // Pour les activités automatiques (ex: achat)
)
// Post représente une publication sociale d'un utilisateur
type Post struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
UserID uuid.UUID `gorm:"type:uuid;not null;index" json:"user_id"`
Content string `gorm:"type:text" json:"content"`
Type PostType `gorm:"default:'status'" json:"type"`
// Attachments (Optionnel)
TrackID *uuid.UUID `gorm:"type:uuid" json:"track_id,omitempty"`
PlaylistID *uuid.UUID `gorm:"type:uuid" json:"playlist_id,omitempty"`
// Metrics (Cached)
LikeCount int `gorm:"default:0" json:"like_count"`
CommentCount int `gorm:"default:0" json:"comment_count"`
CreatedAt time.Time `gorm:"autoCreateTime;index" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// Like représente une interaction "J'aime"
// Polymorphisme via TargetType + TargetID
type Like struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
UserID uuid.UUID `gorm:"type:uuid;not null;index" json:"user_id"`
TargetID uuid.UUID `gorm:"type:uuid;not null;index" json:"target_id"`
TargetType string `gorm:"not null" json:"target_type"` // "post", "track", "playlist"
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
}
// Comment représente un commentaire
type Comment struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey;default:gen_random_uuid()" json:"id"`
UserID uuid.UUID `gorm:"type:uuid;not null;index" json:"user_id"`
TargetID uuid.UUID `gorm:"type:uuid;not null;index" json:"target_id"`
TargetType string `gorm:"not null" json:"target_type"` // "post", "track", "playlist"
Content string `gorm:"type:text;not null" json:"content"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
// ActivityType définit le type d'activité
type ActivityType string
const (
ActivityPost ActivityType = "post"
ActivityLike ActivityType = "like"
ActivityComment ActivityType = "comment"
ActivityFollow ActivityType = "follow"
ActivityPurchase ActivityType = "purchase" // Nouveau
)
// FeedItem représente un élément agrégé pour le flux d'actualité
type FeedItem struct {
ID string `json:"id"`
Type ActivityType `json:"type"`
ActorID uuid.UUID `json:"actor_id"`
TargetID uuid.UUID `json:"target_id"`
TargetType string `json:"target_type"`
Content string `json:"content,omitempty"`
CreatedAt time.Time `json:"created_at"`
// Embedded objects
ActorName string `json:"actor_name,omitempty"`
ActorAvatar string `json:"actor_avatar,omitempty"`
}