26 lines
780 B
Go
26 lines
780 B
Go
|
|
package models
|
||
|
|
|
||
|
|
import (
|
||
|
|
"time"
|
||
|
|
|
||
|
|
"github.com/google/uuid"
|
||
|
|
"gorm.io/gorm"
|
||
|
|
)
|
||
|
|
|
||
|
|
type MessageReaction struct {
|
||
|
|
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
|
||
|
|
UserID uuid.UUID `gorm:"type:uuid;not null;uniqueIndex:uq_message_reactions_user_message_emoji" json:"user_id"`
|
||
|
|
MessageID uuid.UUID `gorm:"type:uuid;not null;uniqueIndex:uq_message_reactions_user_message_emoji" json:"message_id"`
|
||
|
|
Emoji string `gorm:"size:50;not null;uniqueIndex:uq_message_reactions_user_message_emoji" json:"emoji"`
|
||
|
|
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
|
||
|
|
}
|
||
|
|
|
||
|
|
func (mr *MessageReaction) BeforeCreate(tx *gorm.DB) error {
|
||
|
|
if mr.ID == uuid.Nil {
|
||
|
|
mr.ID = uuid.New()
|
||
|
|
}
|
||
|
|
return nil
|
||
|
|
}
|
||
|
|
|
||
|
|
func (MessageReaction) TableName() string { return "message_reactions" }
|