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,17 +1,25 @@
use uuid::Uuid;
use crate::errors::DomainError;
use uuid::Uuid;
macro_rules! uuid_id {
($name:ident) => {
#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct $name(Uuid);
impl $name {
pub fn new() -> Self { Self(Uuid::new_v4()) }
pub fn from_uuid(u: Uuid) -> Self { Self(u) }
pub fn as_uuid(&self) -> Uuid { self.0 }
pub fn new() -> Self {
Self(Uuid::new_v4())
}
pub fn from_uuid(u: Uuid) -> Self {
Self(u)
}
pub fn as_uuid(&self) -> Uuid {
self.0
}
}
impl Default for $name {
fn default() -> Self { Self::new() }
fn default() -> Self {
Self::new()
}
}
impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
@@ -37,15 +45,23 @@ impl Username {
return Err(DomainError::InvalidInput("username: 1-32 chars".into()));
}
if !s.chars().all(|c| c.is_alphanumeric() || c == '_') {
return Err(DomainError::InvalidInput("username: alphanumeric or underscore only".into()));
return Err(DomainError::InvalidInput(
"username: alphanumeric or underscore only".into(),
));
}
Ok(Self(s))
}
pub fn from_trusted(s: String) -> Self { Self(s) }
pub fn as_str(&self) -> &str { &self.0 }
pub fn from_trusted(s: String) -> Self {
Self(s)
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for Username {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0) }
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
@@ -58,8 +74,12 @@ impl Email {
}
Ok(Self(s))
}
pub fn from_trusted(s: String) -> Self { Self(s) }
pub fn as_str(&self) -> &str { &self.0 }
pub fn from_trusted(s: String) -> Self {
Self(s)
}
pub fn as_str(&self) -> &str {
&self.0
}
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
@@ -75,11 +95,17 @@ impl Content {
}
Ok(Self(s))
}
pub fn new_remote(s: impl Into<String>) -> Self { Self(s.into()) }
pub fn as_str(&self) -> &str { &self.0 }
pub fn new_remote(s: impl Into<String>) -> Self {
Self(s.into())
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl std::fmt::Display for Content {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.0) }
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[cfg(test)]