init
This commit is contained in:
32
src/store/models/channel.rs
Normal file
32
src/store/models/channel.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
// use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
// use uuid::Uuid;
|
||||
use sqlx::types::{Uuid, chrono::{{ DateTime, Utc}}};
|
||||
|
||||
#[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)]
|
||||
pub struct Channel {
|
||||
pub id: Uuid,
|
||||
pub sub_server_id: Uuid,
|
||||
pub channel_type: ChannelType,
|
||||
pub name: String,
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, sqlx::Type, Serialize, Deserialize)]
|
||||
#[repr(i32)]
|
||||
pub enum ChannelType {
|
||||
Text = 0,
|
||||
Voice = 1,
|
||||
}
|
||||
|
||||
impl Channel {
|
||||
pub fn new(sub_server_id: Uuid, channel_type: ChannelType, name: String) -> Self {
|
||||
Self {
|
||||
id: Uuid::new_v4(),
|
||||
sub_server_id,
|
||||
channel_type,
|
||||
name,
|
||||
created_at: Utc::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
32
src/store/models/link_sub_server_user.rs
Normal file
32
src/store/models/link_sub_server_user.rs
Normal file
@@ -0,0 +1,32 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)]
|
||||
pub struct LinkSubServerUser {
|
||||
pub id: Option<u64>,
|
||||
pub sub_server_id: Uuid,
|
||||
pub user_id: Uuid,
|
||||
pub display_username: String,
|
||||
pub joined_at: DateTime<Utc>,
|
||||
pub last_seen_at: Option<DateTime<Utc>>,
|
||||
pub is_admin: bool,
|
||||
}
|
||||
|
||||
impl LinkSubServerUser {
|
||||
pub fn new(
|
||||
sub_server_id: Uuid,
|
||||
user_id: Uuid,
|
||||
display_username: String
|
||||
) -> Self {
|
||||
Self {
|
||||
id: None,
|
||||
sub_server_id,
|
||||
user_id,
|
||||
display_username,
|
||||
joined_at: Utc::now(),
|
||||
last_seen_at: None,
|
||||
is_admin: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
24
src/store/models/message.rs
Normal file
24
src/store/models/message.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, sqlx::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>,
|
||||
}
|
||||
|
||||
impl Message {
|
||||
pub fn new(channel_id: Uuid, user_id: Uuid, content: String) -> Self {
|
||||
Self {
|
||||
id: Uuid::new_v4(),
|
||||
channel_id,
|
||||
user_id,
|
||||
content,
|
||||
created_at: Utc::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
11
src/store/models/mod.rs
Normal file
11
src/store/models/mod.rs
Normal file
@@ -0,0 +1,11 @@
|
||||
pub mod sub_server;
|
||||
pub mod channel;
|
||||
pub mod user;
|
||||
pub mod message;
|
||||
pub mod link_sub_server_user;
|
||||
|
||||
pub use sub_server::*;
|
||||
pub use channel::*;
|
||||
pub use user::*;
|
||||
pub use message::*;
|
||||
pub use link_sub_server_user::*;
|
||||
24
src/store/models/sub_server.rs
Normal file
24
src/store/models/sub_server.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
// L'application peut avoir plusieurs sous servers
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)]
|
||||
pub struct SubServer {
|
||||
pub id: Uuid,
|
||||
pub name: String,
|
||||
pub password: String, // voir si on le hash, mais sera certainement pas nécessaire.
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
impl SubServer {
|
||||
pub fn new(name: String, password: String) -> Self {
|
||||
Self {
|
||||
id: Uuid::new_v4(),
|
||||
name,
|
||||
password,
|
||||
created_at: Utc::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
13
src/store/models/user.rs
Normal file
13
src/store/models/user.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, sqlx::FromRow, Serialize, Deserialize)]
|
||||
pub struct User {
|
||||
pub id: Uuid,
|
||||
pub username: String,
|
||||
pub pub_key: String, // l'identification se fera par clé public/privé, comme teamspeak
|
||||
pub created_at: DateTime<Utc>,
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user