package models import ( "time" "github.com/google/uuid" "gorm.io/gorm" ) // User représente un utilisateur dans le système // MIGRATION UUID: User.ID est maintenant un UUID pour cohérence Go↔Rust et alignment ORIGIN type User struct { ID uuid.UUID `gorm:"type:uuid;primary_key" json:"id" db:"id"` Username string `gorm:"not null;size:30" json:"username" db:"username"` Slug string `gorm:"size:255" json:"slug" db:"slug"` Email string `gorm:"not null;size:255" json:"email" db:"email"` PasswordHash string `gorm:"size:255" json:"-" db:"password_hash"` Password string `gorm:"-" json:"password,omitempty"` // Virtual field for input TokenVersion int `gorm:"default:0;not null" json:"token_version" db:"token_version"` FirstName string `gorm:"size:100" json:"first_name" db:"first_name"` LastName string `gorm:"size:100" json:"last_name" db:"last_name"` Avatar string `gorm:"type:text" json:"avatar" db:"avatar"` BannerURL string `gorm:"type:text" json:"banner_url" db:"banner_url"` Bio string `gorm:"type:text" json:"bio" db:"bio"` Location string `gorm:"size:100" json:"location" db:"location"` Birthdate *time.Time `json:"birthdate" db:"birthdate"` Gender string `gorm:"size:20" json:"gender" db:"gender"` UsernameChangedAt *time.Time `json:"username_changed_at" db:"username_changed_at"` Role string `gorm:"type:user_role;not null;default:'user'" json:"role" db:"role"` IsActive bool `gorm:"default:true" json:"is_active" db:"is_active"` IsVerified bool `gorm:"default:false" json:"is_verified" db:"is_verified"` IsBanned bool `gorm:"default:false;not null" json:"is_banned" db:"is_banned"` IsAdmin bool `gorm:"default:false" json:"is_admin" db:"is_admin"` IsPublic bool `gorm:"default:true" json:"is_public" db:"is_public"` LastLoginAt *time.Time `json:"last_login_at" db:"last_login_at"` LoginCount int `gorm:"default:0;not null" json:"login_count" db:"login_count"` PasswordChangedAt *time.Time `json:"password_changed_at,omitempty" db:"password_changed_at"` // F016: Password expiration tracking CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at" db:"created_at"` UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at" db:"updated_at"` DeletedAt gorm.DeletedAt `gorm:"index" json:"-"` SocialLinks string `gorm:"type:jsonb;default:'{}'" json:"social_links" db:"social_links"` // Relations Roles []Role `gorm:"many2many:user_roles;" json:"-"` TrackLikes []TrackLike `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE" json:"-"` } // BeforeCreate hook GORM pour générer UUID si non défini func (u *User) BeforeCreate(tx *gorm.DB) error { if u.ID == uuid.Nil { u.ID = uuid.New() } return nil } // TableName définit le nom de la table pour GORM func (User) TableName() string { return "users" } // SellableContent représente du contenu vendable // MIGRATION UUID: UserID migré vers UUID type SellableContent struct { ID uuid.UUID `json:"id" gorm:"type:uuid;primaryKey"` UserID uuid.UUID `gorm:"type:uuid;not null" json:"user_id" db:"user_id"` Title string `json:"title" db:"title"` Description string `json:"description" db:"description"` Price float64 `json:"price" db:"price"` IsActive bool `json:"is_active" db:"is_active"` CreatedAt time.Time `json:"created_at" db:"created_at"` UpdatedAt time.Time `json:"updated_at" db:"updated_at"` } // BeforeCreate hook GORM pour générer UUID si non défini func (m *SellableContent) BeforeCreate(tx *gorm.DB) error { if m.ID == uuid.Nil { m.ID = uuid.New() } return nil }