This commit is contained in:
2025-11-02 01:25:30 +01:00
commit ed18be9fbd
17 changed files with 598 additions and 0 deletions

19
models/attachment.go Normal file
View File

@@ -0,0 +1,19 @@
package models
import (
"time"
"github.com/google/uuid"
)
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"`
}

18
models/category.go Normal file
View File

@@ -0,0 +1,18 @@
package models
import (
"time"
"github.com/google/uuid"
)
type Category struct {
ID uuid.UUID `gorm:"primaryKey" json:"id"`
ServerID uuid.UUID `gorm:"index;not null" json:"server_id"`
Name string `gorm:"not null" json:"name"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
// Relation optionnelle vers le serveur
Server *Server `gorm:"foreignKey:ServerID" json:"server,omitempty"`
}

50
models/channel.go Normal file
View File

@@ -0,0 +1,50 @@
package models
import (
"time"
"github.com/google/uuid"
)
// #[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)]
// pub struct Channel {
// pub id: Uuid,
// #[sqlx(default)]
// pub server_id: Option<Uuid>, // Option = nullable
// #[sqlx(default)]
// pub category_id: Option<Uuid>, // Option = nullable
// #[sqlx(default)]
// pub position: i32,
// #[sqlx(rename = "type")]
// pub channel_type: ChannelType,
// pub name: Option<String>, // Option = nullable
// pub created_at: DateTime<Utc>,
// pub updated_at: DateTime<Utc>,
// }
type ChannelType string
const (
ChannelTypeText ChannelType = "text"
ChannelTypeVoice ChannelType = "voice"
ChannelTypeDM ChannelType = "dm"
// Ajoutez vos autres types ici
)
type Channel struct {
ID uuid.UUID `gorm:"primaryKey" json:"id"`
ServerID *uuid.UUID `gorm:"index;constraint:OnDelete:CASCADE;" json:"server_id,omitempty"` // Pointeur = nullable
CategoryID *uuid.UUID `gorm:"index;constraint:OnDelete:SET NULL;" json:"category_id,omitempty"` // Pointeur = nullable
Position int32 `gorm:"default:0" json:"position"`
Type ChannelType `gorm:"not null;column:type" json:"type"`
Name *string `gorm:"" json:"name,omitempty"` // Pointeur = nullable
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
Users []*User `gorm:"many2many:channel_users" json:"users,omitempty"` // accès direct aux users
UserLinks []ChannelUser `gorm:"foreignKey:ChannelID" json:"user_links,omitempty"` // accès aux lignes de jointure/métadonnées
// Relations (optionnelles)
Server *Server `gorm:"foreignKey:ServerID" json:"server,omitempty"`
Category *Category `gorm:"foreignKey:CategoryID" json:"category,omitempty"`
}

19
models/channel_user.go Normal file
View File

@@ -0,0 +1,19 @@
package models
import (
"time"
"github.com/google/uuid"
)
type ChannelUser struct {
ChannelID uuid.UUID `gorm:"primaryKey" json:"channel_id"`
UserID uuid.UUID `gorm:"primaryKey" json:"user_id"`
Role string `gorm:"default:'member'" json:"role"`
JoinedAt time.Time `gorm:"autoCreateTime" json:"joined_at"`
// Relations pour navigation (optionnelles)
Channel *Channel `gorm:"foreignKey:ChannelID" json:"channel,omitempty"`
User *User `gorm:"foreignKey:UserID" json:"user,omitempty"`
}

28
models/message.go Normal file
View File

@@ -0,0 +1,28 @@
package models
import (
"time"
"github.com/google/uuid"
)
// #[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"`
}

14
models/server.go Normal file
View File

@@ -0,0 +1,14 @@
package models
import (
"time"
"github.com/google/uuid"
)
type Server struct {
ID uuid.UUID `gorm:"primaryKey" json:"id"`
Password string `gorm:"not null" json:"-"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
}

20
models/server_user.go Normal file
View File

@@ -0,0 +1,20 @@
package models
import (
"time"
"github.com/google/uuid"
)
type ServerUser struct {
ID uuid.UUID `gorm:"primaryKey" json:"id"`
ServerID uuid.UUID `gorm:"index;not null" json:"server_id"`
UserID uuid.UUID `gorm:"index;not null" json:"user_id"`
Username *string `json:"username,omitempty"` // Option<String> = pointeur nullable
JoinedAt time.Time `gorm:"autoCreateTime" json:"joined_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
// Relations pour navigation (optionnelles)
Server *Server `gorm:"foreignKey:ServerID" json:"server,omitempty"`
User *User `gorm:"foreignKey:UserID" json:"user,omitempty"`
}

18
models/user.go Normal file
View File

@@ -0,0 +1,18 @@
package models
import (
"time"
"github.com/google/uuid"
)
type User struct {
ID uuid.UUID `gorm:"primaryKey" json:"id"`
Username string `gorm:"not null" json:"username"`
PubKey string `gorm:"type:text;uniqueIndex;not null" json:"pub_key"`
CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at"`
UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at"`
Channels []*Channel `gorm:"many2many:channel_users" json:"channels,omitempty"`
ChannelLinks []ChannelUser `gorm:"foreignKey:UserID" json:"channel_links,omitempty"`
}