feat(domain): models
This commit is contained in:
45
crates/domain/src/models/thought.rs
Normal file
45
crates/domain/src/models/thought.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use chrono::{DateTime, Utc};
|
||||
use crate::value_objects::{ThoughtId, UserId, Content};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||
pub enum Visibility {
|
||||
Public, Followers, Unlisted, Direct,
|
||||
}
|
||||
impl Visibility {
|
||||
pub fn from_str(s: &str) -> Self {
|
||||
match s { "followers" => Self::Followers, "unlisted" => Self::Unlisted, "direct" => Self::Direct, _ => Self::Public }
|
||||
}
|
||||
pub fn as_str(&self) -> &str {
|
||||
match self { Self::Public => "public", Self::Followers => "followers", Self::Unlisted => "unlisted", Self::Direct => "direct" }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Thought {
|
||||
pub id: ThoughtId,
|
||||
pub user_id: UserId,
|
||||
pub content: Content,
|
||||
pub in_reply_to_id: Option<ThoughtId>,
|
||||
pub in_reply_to_url: Option<String>,
|
||||
pub ap_id: Option<String>,
|
||||
pub visibility: Visibility,
|
||||
pub content_warning: Option<String>,
|
||||
pub sensitive: bool,
|
||||
pub local: bool,
|
||||
pub created_at: DateTime<Utc>,
|
||||
pub updated_at: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
impl Thought {
|
||||
pub fn new_local(
|
||||
id: ThoughtId, user_id: UserId, content: Content,
|
||||
in_reply_to_id: Option<ThoughtId>, visibility: Visibility,
|
||||
content_warning: Option<String>, sensitive: bool,
|
||||
) -> Self {
|
||||
Self {
|
||||
id, user_id, content, in_reply_to_id, in_reply_to_url: None, ap_id: None,
|
||||
visibility, content_warning, sensitive, local: true,
|
||||
created_at: Utc::now(), updated_at: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user