45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
package model
|
||
|
||
import (
|
||
"time"
|
||
|
||
"spark-server/internal/module/favorite/entity"
|
||
)
|
||
|
||
// Favorite maps table favorites.
|
||
type Favorite struct {
|
||
ID int64 `gorm:"column:id;primaryKey;comment:Snowflake 收藏 id"`
|
||
UserID int64 `gorm:"column:user_id;comment:收藏者 user_id"`
|
||
MsgID int64 `gorm:"column:msg_id;comment:原消息 Snowflake id,仅作来源;撤回不影响收藏"`
|
||
ConversationID int64 `gorm:"column:conversation_id;comment:原会话 id,仅作来源"`
|
||
MessageType int16 `gorm:"column:message_type;comment:消息类型,与 messages.message_type 一致"`
|
||
Content []byte `gorm:"column:content;type:blob;comment:收藏快照(JSON 字节);媒体 key 已复制到 perm/fav/"`
|
||
CreatedAt time.Time `gorm:"column:created_at;comment:收藏时间"`
|
||
}
|
||
|
||
func (Favorite) TableName() string { return "t_favorites" }
|
||
|
||
func (r *Favorite) Entity() *entity.Favorite {
|
||
if r == nil {
|
||
return nil
|
||
}
|
||
return &entity.Favorite{
|
||
ID: r.ID, UserID: r.UserID, MsgID: r.MsgID, ConversationID: r.ConversationID,
|
||
MessageType: r.MessageType, Content: r.Content, CreatedAtMS: r.CreatedAt.UnixMilli(),
|
||
}
|
||
}
|
||
|
||
func fromEntity(f *entity.Favorite) *Favorite {
|
||
if f == nil {
|
||
return nil
|
||
}
|
||
row := &Favorite{
|
||
ID: f.ID, UserID: f.UserID, MsgID: f.MsgID, ConversationID: f.ConversationID,
|
||
MessageType: f.MessageType, Content: f.Content,
|
||
}
|
||
if f.CreatedAtMS > 0 {
|
||
row.CreatedAt = time.UnixMilli(f.CreatedAtMS)
|
||
}
|
||
return row
|
||
}
|