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

28 lines
687 B
Go

package models
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
type Attachment struct {
ID uuid.UUID `gorm:"primaryKey" json:"id"`
MessageID uuid.UUID `gorm:"index;not null" json:"message_id"`
Filename string `gorm:"not null" json:"filename"`
FileSize int64 `gorm:"not null" json:"file_size"`
MimeType string `gorm:"not null" json:"mime_type"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
// Relation optionnelle vers le message
Message *Message `gorm:"foreignKey:MessageID" json:"message,omitempty"`
}
func (s *Attachment) BeforeCreate(tx *gorm.DB) (err error) {
if s.ID == uuid.Nil {
s.ID = uuid.New()
}
return nil
}