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,19 +6,36 @@ use domain::{
value_objects::{ApiKeyId, UserId},
};
pub async fn list_api_keys(keys: &dyn ApiKeyRepository, user_id: &UserId) -> Result<Vec<ApiKey>, DomainError> {
pub async fn list_api_keys(
keys: &dyn ApiKeyRepository,
user_id: &UserId,
) -> Result<Vec<ApiKey>, DomainError> {
keys.list_for_user(user_id).await
}
pub async fn create_api_key(keys: &dyn ApiKeyRepository, user_id: &UserId, name: String) -> Result<(ApiKey, String), DomainError> {
pub async fn create_api_key(
keys: &dyn ApiKeyRepository,
user_id: &UserId,
name: String,
) -> Result<(ApiKey, String), DomainError> {
let raw_key = uuid::Uuid::new_v4().to_string().replace('-', "");
let key_hash = sha256_hex(&raw_key);
let key = ApiKey { id: ApiKeyId::new(), user_id: user_id.clone(), key_hash, name, created_at: Utc::now() };
let key = ApiKey {
id: ApiKeyId::new(),
user_id: user_id.clone(),
key_hash,
name,
created_at: Utc::now(),
};
keys.save(&key).await?;
Ok((key, raw_key))
}
pub async fn delete_api_key(keys: &dyn ApiKeyRepository, user_id: &UserId, key_id: &ApiKeyId) -> Result<(), DomainError> {
pub async fn delete_api_key(
keys: &dyn ApiKeyRepository,
user_id: &UserId,
key_id: &ApiKeyId,
) -> Result<(), DomainError> {
keys.delete(key_id, user_id).await
}
@@ -37,7 +54,9 @@ mod tests {
async fn create_key_saves_hashed_not_raw() {
let store = TestStore::default();
let uid = UserId::new();
let (key, raw) = create_api_key(&store, &uid, "my-key".to_string()).await.unwrap();
let (key, raw) = create_api_key(&store, &uid, "my-key".to_string())
.await
.unwrap();
assert_ne!(key.key_hash, raw, "stored hash must differ from raw key");
assert!(!key.key_hash.is_empty());
assert_eq!(key.name, "my-key");
@@ -50,7 +69,9 @@ mod tests {
use sha2::{Digest, Sha256};
let store = TestStore::default();
let uid = UserId::new();
let (key, raw) = create_api_key(&store, &uid, "test".to_string()).await.unwrap();
let (key, raw) = create_api_key(&store, &uid, "test".to_string())
.await
.unwrap();
let expected_hash = hex::encode(Sha256::digest(raw.as_bytes()));
assert_eq!(key.key_hash, expected_hash);
}
@@ -69,7 +90,9 @@ mod tests {
let store = TestStore::default();
let alice = UserId::new();
let bob = UserId::new();
create_api_key(&store, &alice, "a".to_string()).await.unwrap();
create_api_key(&store, &alice, "a".to_string())
.await
.unwrap();
create_api_key(&store, &bob, "b".to_string()).await.unwrap();
let alice_keys = list_api_keys(&store, &alice).await.unwrap();
assert_eq!(alice_keys.len(), 1);