This commit is contained in:
2025-11-17 01:06:03 +01:00
parent bf78faba28
commit 4e76ee468b
16 changed files with 617 additions and 42 deletions

View File

@@ -4,6 +4,7 @@ import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
type Attachment struct {
@@ -17,3 +18,10 @@ type Attachment struct {
// 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
}

View File

@@ -4,6 +4,7 @@ import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
type Category struct {
@@ -14,5 +15,12 @@ type Category struct {
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
// Relation optionnelle vers le serveur
Server *Server `gorm:"foreignKey:ServerID" json:"server,omitempty"`
Server *Server `gorm:"foreignKey:ServerID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE;" json:"server,omitempty"`
}
func (s *Category) BeforeCreate(tx *gorm.DB) (err error) {
if s.ID == uuid.Nil {
s.ID = uuid.New()
}
return nil
}

View File

@@ -4,6 +4,7 @@ import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// #[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)]
@@ -48,3 +49,10 @@ type Channel struct {
Server *Server `gorm:"foreignKey:ServerID" json:"server,omitempty"`
Category *Category `gorm:"foreignKey:CategoryID" json:"category,omitempty"`
}
func (s *Channel) BeforeCreate(tx *gorm.DB) (err error) {
if s.ID == uuid.Nil {
s.ID = uuid.New()
}
return nil
}

View File

@@ -7,8 +7,9 @@ import (
)
type ChannelUser struct {
ChannelID uuid.UUID `gorm:"primaryKey" json:"channel_id"`
UserID uuid.UUID `gorm:"primaryKey" json:"user_id"`
ID uuid.UUID `gorm:"primaryKey" json:"id"`
ChannelID uuid.UUID `gorm:"index;not null" json:"channel_id"`
UserID uuid.UUID `gorm:"index;not null" json:"user_id"`
Role string `gorm:"default:'member'" json:"role"`
JoinedAt time.Time `gorm:"autoCreateTime" json:"joined_at"`

View File

@@ -4,6 +4,7 @@ import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// #[derive(Debug, Clone, FromRow, Serialize, Deserialize)]
@@ -26,3 +27,10 @@ type Message struct {
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
}

View File

@@ -4,6 +4,7 @@ import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
type Server struct {
@@ -13,3 +14,10 @@ type Server struct {
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
}
func (s *Server) BeforeCreate(tx *gorm.DB) (err error) {
if s.ID == uuid.Nil {
s.ID = uuid.New()
}
return nil
}