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 std::sync::Arc;
use sqlx::PgPool;
use std::sync::Arc;
use activitypub::ThoughtsObjectHandler;
use activitypub_base::ActivityPubService;
@@ -11,7 +11,7 @@ use crate::handlers::{FederationHandler, NotificationHandler};
pub struct WorkerHandlers {
pub notification: NotificationHandler,
pub federation: FederationHandler,
pub federation: FederationHandler,
}
pub async fn build(
@@ -27,15 +27,20 @@ pub async fn build(
.expect("DB connect failed");
// Repos
let thoughts = Arc::new(postgres::thought::PgThoughtRepository::new(pool.clone()));
let users = Arc::new(postgres::user::PgUserRepository::new(pool.clone()));
let notifications = Arc::new(postgres::notification::PgNotificationRepository::new(pool.clone()));
let thoughts = Arc::new(postgres::thought::PgThoughtRepository::new(pool.clone()));
let users = Arc::new(postgres::user::PgUserRepository::new(pool.clone()));
let notifications = Arc::new(postgres::notification::PgNotificationRepository::new(
pool.clone(),
));
// ActivityPub service (for federation fan-out)
let ap_service: Arc<dyn domain::ports::OutboundFederationPort> = Arc::new(
ActivityPubService::new(
Arc::new(PostgresFederationRepository::new(pool.clone())),
Arc::new(PostgresApUserRepository::new(pool.clone(), base_url.to_string())),
Arc::new(PostgresApUserRepository::new(
pool.clone(),
base_url.to_string(),
)),
Arc::new(ThoughtsObjectHandler::new(
Arc::new(PgActivityPubRepository::new(pool.clone())),
base_url,
@@ -64,17 +69,20 @@ pub async fn build(
// Thin handlers
let handlers = WorkerHandlers {
notification: NotificationHandler { service: notification_svc },
federation: FederationHandler { service: federation_svc },
notification: NotificationHandler {
service: notification_svc,
},
federation: FederationHandler {
service: federation_svc,
},
};
// NATS consumer
let nats_client = async_nats::connect(nats_url)
.await
.expect("NATS connect failed");
let consumer = event_transport::EventConsumerAdapter::new(
nats::NatsMessageSource::new(nats_client),
);
let consumer =
event_transport::EventConsumerAdapter::new(nats::NatsMessageSource::new(nats_client));
(consumer, handlers)
}