Some checks failed
lint / lint (push) Has been cancelled
test / unit (push) Has been cancelled
test / integration (push) Has been cancelled
lint / lint (pull_request) Failing after 9m30s
test / unit (pull_request) Successful in 16m10s
test / integration (pull_request) Failing after 16m44s
- Updated PgNotificationRepository to utilize IntoDbResult for error handling in various methods. - Refactored PgRemoteActorRepository to replace manual error mapping with IntoDbResult. - Modified PgRemoteActorConnectionRepository to implement IntoDbResult for error handling. - Adjusted PgTagRepository to use IntoDbResult for consistent error management. - Introduced test_helpers module for seeding users and thoughts in tests. - Enhanced PgThoughtRepository to leverage IntoDbResult for error handling. - Updated PgTopFriendRepository to utilize IntoDbResult for error management. - Refactored PgUserRepository to implement IntoDbResult for error handling. - Added constants for pagination defaults in requests. - Introduced MAX_TOP_FRIENDS constant for top friends validation. - Refactored JWT expiration time to use a constant. - Improved rate limiter configuration with constants for better readability. - Added utility methods for FollowState and Visibility enums for string conversions. - Introduced maximum length constants for Username, Email, and Content value objects. - Cleaned up test modules by removing redundant code and utilizing a shared testing state.
74 lines
1.8 KiB
Rust
74 lines
1.8 KiB
Rust
use crate::value_objects::{Content, ThoughtId, UserId};
|
|
use chrono::{DateTime, Utc};
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
|
pub enum Visibility {
|
|
Public,
|
|
Followers,
|
|
Unlisted,
|
|
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 Visibility {
|
|
pub fn as_str(&self) -> &'static str {
|
|
match self {
|
|
Visibility::Public => "public",
|
|
Visibility::Followers => "followers",
|
|
Visibility::Unlisted => "unlisted",
|
|
Visibility::Direct => "direct",
|
|
}
|
|
}
|
|
|
|
pub fn from_db_str(s: &str) -> Self {
|
|
match s {
|
|
"followers" => Self::Followers,
|
|
"unlisted" => Self::Unlisted,
|
|
"direct" => Self::Direct,
|
|
_ => Self::Public,
|
|
}
|
|
}
|
|
}
|
|
|
|
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,
|
|
}
|
|
}
|
|
}
|