Refactor handlers and OpenAPI documentation for improved readability and consistency
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 6m49s
test / unit (pull_request) Successful in 16m24s
test / integration (pull_request) Failing after 17m7s

- Reorganized imports in health, notifications, social, thoughts, and users handlers for clarity.
- Updated function signatures in handlers to improve readability by aligning parameters.
- Enhanced JSON response formatting in notifications and thoughts handlers.
- Improved error handling in user-related functions.
- Refactored OpenAPI documentation to maintain consistent formatting and structure.
- Cleaned up unnecessary code and comments across various files.
- Ensured consistent use of `Arc` for shared state in AppState and WorkerHandlers.
This commit is contained in:
2026-05-14 16:28:57 +02:00
parent 004bfb427b
commit 10c4a66de5
47 changed files with 2406 additions and 723 deletions

View File

@@ -1,5 +1,5 @@
use chrono::{DateTime, Utc};
use crate::value_objects::{ApiKeyId, UserId};
use chrono::{DateTime, Utc};
#[derive(Debug, Clone)]
pub struct ApiKey {

View File

@@ -1,4 +1,4 @@
use crate::models::{user::User, thought::Thought};
use crate::models::{thought::Thought, user::User};
use crate::value_objects::UserId;
#[derive(Debug, Clone)]
@@ -25,10 +25,17 @@ pub struct FeedEntry {
}
#[derive(Debug, Clone)]
pub struct PageParams { pub page: u64, pub per_page: u64 }
pub struct PageParams {
pub page: u64,
pub per_page: u64,
}
impl PageParams {
pub fn offset(&self) -> i64 { ((self.page.saturating_sub(1)) * self.per_page) as i64 }
pub fn limit(&self) -> i64 { self.per_page as i64 }
pub fn offset(&self) -> i64 {
((self.page.saturating_sub(1)) * self.per_page) as i64
}
pub fn limit(&self) -> i64 {
self.per_page as i64
}
}
#[derive(Debug, Clone)]

View File

@@ -1,14 +1,32 @@
use crate::value_objects::{NotificationId, ThoughtId, UserId};
use chrono::{DateTime, Utc};
use crate::value_objects::{NotificationId, UserId, ThoughtId};
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum NotificationType { Like, Boost, Follow, Mention, Reply }
pub enum NotificationType {
Like,
Boost,
Follow,
Mention,
Reply,
}
impl NotificationType {
pub fn from_str(s: &str) -> Self {
match s { "like" => Self::Like, "boost" => Self::Boost, "follow" => Self::Follow, "mention" => Self::Mention, _ => Self::Reply }
match s {
"like" => Self::Like,
"boost" => Self::Boost,
"follow" => Self::Follow,
"mention" => Self::Mention,
_ => Self::Reply,
}
}
pub fn as_str(&self) -> &str {
match self { Self::Like => "like", Self::Boost => "boost", Self::Follow => "follow", Self::Mention => "mention", Self::Reply => "reply" }
match self {
Self::Like => "like",
Self::Boost => "boost",
Self::Follow => "follow",
Self::Mention => "mention",
Self::Reply => "reply",
}
}
}

View File

@@ -1,5 +1,5 @@
use crate::value_objects::{BoostId, LikeId, ThoughtId, UserId};
use chrono::{DateTime, Utc};
use crate::value_objects::{UserId, ThoughtId, LikeId, BoostId};
#[derive(Debug, Clone)]
pub struct Like {
@@ -20,13 +20,25 @@ pub struct Boost {
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FollowState { Pending, Accepted, Rejected }
pub enum FollowState {
Pending,
Accepted,
Rejected,
}
impl FollowState {
pub fn from_str(s: &str) -> Self {
match s { "pending" => Self::Pending, "rejected" => Self::Rejected, _ => Self::Accepted }
match s {
"pending" => Self::Pending,
"rejected" => Self::Rejected,
_ => Self::Accepted,
}
}
pub fn as_str(&self) -> &str {
match self { Self::Pending => "pending", Self::Accepted => "accepted", Self::Rejected => "rejected" }
match self {
Self::Pending => "pending",
Self::Accepted => "accepted",
Self::Rejected => "rejected",
}
}
}

View File

@@ -1,2 +1,5 @@
#[derive(Debug, Clone)]
pub struct Tag { pub id: i32, pub name: String }
pub struct Tag {
pub id: i32,
pub name: String,
}

View File

@@ -1,16 +1,29 @@
use crate::value_objects::{Content, ThoughtId, UserId};
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,
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 }
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" }
match self {
Self::Public => "public",
Self::Followers => "followers",
Self::Unlisted => "unlisted",
Self::Direct => "direct",
}
}
}
@@ -32,14 +45,27 @@ pub struct Thought {
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,
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,
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,
}
}
}

View File

@@ -1,4 +1,8 @@
use crate::value_objects::UserId;
#[derive(Debug, Clone)]
pub struct TopFriend { pub user_id: UserId, pub friend_id: UserId, pub position: i16 }
pub struct TopFriend {
pub user_id: UserId,
pub friend_id: UserId,
pub position: i16,
}

View File

@@ -1,5 +1,5 @@
use crate::value_objects::{Email, PasswordHash, UserId, Username};
use chrono::{DateTime, Utc};
use crate::value_objects::{UserId, Username, Email, PasswordHash};
#[derive(Debug, Clone)]
pub struct User {
@@ -22,14 +22,30 @@ pub struct User {
}
impl User {
pub fn new_local(id: UserId, username: Username, email: Email, password_hash: PasswordHash) -> Self {
pub fn new_local(
id: UserId,
username: Username,
email: Email,
password_hash: PasswordHash,
) -> Self {
let now = Utc::now();
Self {
id, username, email, password_hash,
display_name: None, bio: None, avatar_url: None, header_url: None,
custom_css: None, local: true, ap_id: None, inbox_url: None,
public_key: None, private_key: None,
created_at: now, updated_at: now,
id,
username,
email,
password_hash,
display_name: None,
bio: None,
avatar_url: None,
header_url: None,
custom_css: None,
local: true,
ap_id: None,
inbox_url: None,
public_key: None,
private_key: None,
created_at: now,
updated_at: now,
}
}
}