veza/veza-backend-api/internal/models/.backup-pre-uuid-migration/message.go
2025-12-03 20:29:37 +01:00

33 lines
1.2 KiB
Go

package models
import (
"time"
"gorm.io/gorm"
)
// Message représente un message dans une room de chat
type Message struct {
ID int64 `gorm:"primaryKey;autoIncrement" json:"id"`
RoomID int64 `gorm:"not null" json:"room_id"`
UserID int64 `gorm:"not null" json:"user_id"`
Content string `gorm:"not null;type:text" json:"content"`
Type string `gorm:"not null;default:'text'" json:"type"`
ParentID *int64 `json:"parent_id,omitempty"`
IsEdited bool `gorm:"default:false" json:"is_edited"`
IsDeleted bool `gorm:"default:false" json:"is_deleted"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"" json:"-"`
// Relations
Room Room `gorm:"foreignKey:RoomID;constraint:OnDelete:CASCADE" json:"-"`
User User `gorm:"foreignKey:UserID;constraint:OnDelete:CASCADE" json:"-"`
Parent *Message `gorm:"foreignKey:ParentID;constraint:OnDelete:SET NULL" json:"-"`
}
// TableName définit le nom de la table pour GORM
func (Message) TableName() string {
return "messages"
}