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
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:
@@ -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)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use std::sync::Arc;
|
||||
use application::services::{FederationEventService, NotificationEventService};
|
||||
use domain::{errors::DomainError, events::DomainEvent};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct NotificationHandler {
|
||||
pub service: Arc<NotificationEventService>,
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
mod factory;
|
||||
mod handlers;
|
||||
|
||||
use futures::StreamExt;
|
||||
use domain::ports::EventConsumer;
|
||||
use futures::StreamExt;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() {
|
||||
@@ -12,8 +12,8 @@ async fn main() {
|
||||
.init();
|
||||
|
||||
let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL required");
|
||||
let nats_url = std::env::var("NATS_URL").unwrap_or_else(|_| "nats://localhost:4222".into());
|
||||
let base_url = std::env::var("BASE_URL").expect("BASE_URL required");
|
||||
let nats_url = std::env::var("NATS_URL").unwrap_or_else(|_| "nats://localhost:4222".into());
|
||||
let base_url = std::env::var("BASE_URL").expect("BASE_URL required");
|
||||
|
||||
tracing::info!("Building worker...");
|
||||
let (consumer, handlers) = factory::build(&database_url, &base_url, &nats_url).await;
|
||||
@@ -32,8 +32,12 @@ async fn main() {
|
||||
if n.is_ok() && f.is_ok() {
|
||||
(envelope.ack)();
|
||||
} else {
|
||||
if let Err(e) = n { tracing::error!("notification handler: {e}"); }
|
||||
if let Err(e) = f { tracing::error!("federation handler: {e}"); }
|
||||
if let Err(e) = n {
|
||||
tracing::error!("notification handler: {e}");
|
||||
}
|
||||
if let Err(e) = f {
|
||||
tracing::error!("federation handler: {e}");
|
||||
}
|
||||
(envelope.nack)();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user