2026-03-09 21:28:58 +08:00
|
|
|
package model
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"gorm.io/gorm"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// Favorite 收藏
|
|
|
|
|
type Favorite struct {
|
|
|
|
|
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
|
|
|
|
|
PostID string `json:"post_id" gorm:"type:varchar(36);not null;index;uniqueIndex:idx_favorite_post_user,priority:1"`
|
|
|
|
|
UserID string `json:"user_id" gorm:"type:varchar(36);not null;index;uniqueIndex:idx_favorite_post_user,priority:2"`
|
|
|
|
|
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// BeforeCreate 创建前生成UUID
|
|
|
|
|
func (f *Favorite) BeforeCreate(tx *gorm.DB) error {
|
2026-05-04 13:07:03 +08:00
|
|
|
SetUUIDIfEmpty(&f.ID)
|
2026-03-09 21:28:58 +08:00
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (Favorite) TableName() string {
|
|
|
|
|
return "favorites"
|
|
|
|
|
}
|