Files
backend/internal/model/follow.go

29 lines
733 B
Go
Raw Normal View History

package model
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// Follow 关注关系
type Follow struct {
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
FollowerID string `json:"follower_id" gorm:"type:varchar(36);index;not null;uniqueIndex:idx_follower_following"` // 关注者
FollowingID string `json:"following_id" gorm:"type:varchar(36);index;not null;uniqueIndex:idx_follower_following"` // 被关注者
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
}
// BeforeCreate 创建前生成UUID
func (f *Follow) BeforeCreate(tx *gorm.DB) error {
if f.ID == "" {
f.ID = uuid.New().String()
}
return nil
}
func (Follow) TableName() string {
return "follows"
}