35 lines
961 B
Go
35 lines
961 B
Go
package model
|
|
|
|
import (
|
|
"gorm.io/gorm"
|
|
"hepa-calc-admin-api/global"
|
|
"time"
|
|
)
|
|
|
|
// UserCollection 用户收藏表
|
|
type UserCollection struct {
|
|
CollectionId int64 `gorm:"column:collection_id;type:bigint(19);primary_key;comment:主键id" json:"collection_id"`
|
|
UserId int64 `gorm:"column:user_id;type:bigint(19);comment:用户id" json:"user_id"`
|
|
QuestionId int64 `gorm:"column:question_id;type:bigint(19);comment:问题id" json:"question_id"`
|
|
Model
|
|
Question *Question `gorm:"foreignKey:QuestionId;references:question_id" json:"question"`
|
|
}
|
|
|
|
func (m *UserCollection) TableName() string {
|
|
return "user_collection"
|
|
}
|
|
|
|
func (m *UserCollection) BeforeCreate(tx *gorm.DB) error {
|
|
if m.CollectionId == 0 {
|
|
m.CollectionId = global.Snowflake.Generate().Int64()
|
|
}
|
|
|
|
m.CreatedAt = LocalTime(time.Now())
|
|
tx.Statement.SetColumn("CreatedAt", m.CreatedAt)
|
|
|
|
m.UpdatedAt = LocalTime(time.Now())
|
|
tx.Statement.SetColumn("UpdatedAt", m.UpdatedAt)
|
|
|
|
return nil
|
|
}
|