Set up project files and add .gitignore to exclude local build/runtime artifacts. Made-with: Cursor
29 lines
714 B
Go
29 lines
714 B
Go
package model
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/google/uuid"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// PostLike 帖子点赞
|
|
type PostLike struct {
|
|
ID string `json:"id" gorm:"type:varchar(36);primaryKey"`
|
|
PostID string `json:"post_id" gorm:"type:varchar(36);not null;index;uniqueIndex:idx_post_like_user,priority:1"`
|
|
UserID string `json:"user_id" gorm:"type:varchar(36);not null;index;uniqueIndex:idx_post_like_user,priority:2"`
|
|
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
|
}
|
|
|
|
// BeforeCreate 创建前生成UUID
|
|
func (pl *PostLike) BeforeCreate(tx *gorm.DB) error {
|
|
if pl.ID == "" {
|
|
pl.ID = uuid.New().String()
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (PostLike) TableName() string {
|
|
return "post_likes"
|
|
}
|