Files
go_oxspeak_server/models/message.go
2025-11-17 01:06:03 +01:00

37 lines
935 B
Go

package models
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// #[derive(Debug, Clone, FromRow, Serialize, Deserialize)]
//pub struct Message {
// pub id: Uuid,
// pub channel_id: Uuid,
// pub user_id: Uuid,
// pub content: String,
// pub created_at: DateTime<Utc>,
// pub edited_at: DateTime<Utc>,
// pub reply_to_id: Option<Uuid>,
//}
type Message struct {
ID uuid.UUID `gorm:"primaryKey" json:"id"`
ChannelID uuid.UUID `gorm:"index" json:"channel_id"`
UserID uuid.UUID `gorm:"index" json:"user_id"`
Content string `gorm:"not null" json:"content"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
EditedAt *time.Time `gorm:"default:null" json:"edited_at,omitempty"`
ReplyToID *uuid.UUID `gorm:"index" json:"reply_to_id,omitempty"`
}
func (s *Message) BeforeCreate(tx *gorm.DB) (err error) {
if s.ID == uuid.Nil {
s.ID = uuid.New()
}
return nil
}