This commit is contained in:
2025-10-05 21:47:49 +02:00
parent 04c2750f0b
commit a6626571fa
29 changed files with 681 additions and 677 deletions

56
src/db/models/channel.rs Normal file
View File

@@ -0,0 +1,56 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)]
pub struct Channel {
pub id: Uuid, // Blob(16) sqlite
#[sqlx(default)]
pub server_id: Option<Uuid>,
#[sqlx(default)]
pub category_id: Option<Uuid>,
#[sqlx(default)]
pub position: i32,
#[sqlx(rename = "type")]
pub channel_type: ChannelType,
pub name: Option<String>, // Not necessary for DMs
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::Type)]
#[sqlx(type_name = "text")]
#[serde(rename_all = "snake_case")]
pub enum ChannelType {
Text,
Voice,
Dm
}
impl Channel {
pub fn new_server_channel(server_id: Uuid, name: String, channel_type: ChannelType) -> Self {
Self {
id: Uuid::now_v7(),
server_id: Some(server_id),
category_id: None,
position: 0,
channel_type,
name: Some(name),
created_at: Utc::now(),
updated_at: Utc::now()
}
}
pub fn new_dm_channel() -> Self {
Self {
id: Uuid::now_v7(),
server_id: None,
category_id: None,
channel_type: ChannelType::Dm,
name: None,
position: 0,
created_at: Utc::now(),
updated_at: Utc::now(),
}
}
}