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

@@ -6,12 +6,21 @@ use domain::{
};
pub async fn get_user(users: &dyn UserRepository, user_id: &UserId) -> Result<User, DomainError> {
users.find_by_id(user_id).await?.ok_or(DomainError::NotFound)
users
.find_by_id(user_id)
.await?
.ok_or(DomainError::NotFound)
}
pub async fn get_user_by_username(users: &dyn UserRepository, username: &str) -> Result<User, DomainError> {
pub async fn get_user_by_username(
users: &dyn UserRepository,
username: &str,
) -> Result<User, DomainError> {
let username = Username::new(username).map_err(|_| DomainError::NotFound)?;
users.find_by_username(&username).await?.ok_or(DomainError::NotFound)
users
.find_by_username(&username)
.await?
.ok_or(DomainError::NotFound)
}
pub async fn update_profile(
@@ -23,16 +32,38 @@ pub async fn update_profile(
header_url: Option<String>,
custom_css: Option<String>,
) -> Result<(), DomainError> {
users.update_profile(user_id, display_name, bio, avatar_url, header_url, custom_css).await
users
.update_profile(
user_id,
display_name,
bio,
avatar_url,
header_url,
custom_css,
)
.await
}
pub async fn get_top_friends(top_friends: &dyn TopFriendRepository, user_id: &UserId) -> Result<Vec<(TopFriend, User)>, DomainError> {
pub async fn get_top_friends(
top_friends: &dyn TopFriendRepository,
user_id: &UserId,
) -> Result<Vec<(TopFriend, User)>, DomainError> {
top_friends.list_for_user(user_id).await
}
pub async fn set_top_friends(top_friends: &dyn TopFriendRepository, user_id: &UserId, friend_ids: Vec<UserId>) -> Result<(), DomainError> {
if friend_ids.len() > 8 { return Err(DomainError::InvalidInput("top friends: max 8".into())); }
let friends: Vec<(UserId, i16)> = friend_ids.into_iter().enumerate().map(|(i, id)| (id, (i + 1) as i16)).collect();
pub async fn set_top_friends(
top_friends: &dyn TopFriendRepository,
user_id: &UserId,
friend_ids: Vec<UserId>,
) -> Result<(), DomainError> {
if friend_ids.len() > 8 {
return Err(DomainError::InvalidInput("top friends: max 8".into()));
}
let friends: Vec<(UserId, i16)> = friend_ids
.into_iter()
.enumerate()
.map(|(i, id)| (id, (i + 1) as i16))
.collect();
top_friends.set_top_friends(user_id, friends).await
}
@@ -71,11 +102,21 @@ mod tests {
let f1 = UserId::new();
let f2 = UserId::new();
let f3 = UserId::new();
set_top_friends(&store, &uid, vec![f1.clone(), f2.clone(), f3.clone()]).await.unwrap();
set_top_friends(&store, &uid, vec![f1.clone(), f2.clone(), f3.clone()])
.await
.unwrap();
let tf = store.top_friends.lock().unwrap();
assert_eq!(tf.len(), 3);
let pos_f1 = tf.iter().find(|t| t.friend_id == f1).map(|t| t.position).unwrap();
let pos_f2 = tf.iter().find(|t| t.friend_id == f2).map(|t| t.position).unwrap();
let pos_f1 = tf
.iter()
.find(|t| t.friend_id == f1)
.map(|t| t.position)
.unwrap();
let pos_f2 = tf
.iter()
.find(|t| t.friend_id == f2)
.map(|t| t.position)
.unwrap();
assert!(pos_f1 < pos_f2, "f1 should come before f2");
}