56 lines
1.4 KiB
Rust
56 lines
1.4 KiB
Rust
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(),
|
|
}
|
|
}
|
|
} |