refactor(presentation): pure HTTP library — remove concrete adapter deps and binary

This commit is contained in:
2026-05-14 12:07:18 +02:00
parent 0c7a6fe9be
commit c072ee95cd
5 changed files with 1 additions and 127 deletions

View File

@@ -1,87 +1,6 @@
pub mod errors;
pub mod openapi;
pub mod extractors;
pub mod handlers;
pub mod openapi;
pub mod routes;
pub mod state;
use std::sync::Arc;
use async_trait::async_trait;
use sqlx::PgPool;
use domain::{errors::DomainError, events::DomainEvent, ports::EventPublisher};
use postgres_search::PgSearchRepository;
use activitypub_base::{ApFederationConfig, FederationData};
use activitypub::ThoughtsObjectHandler;
use postgres::activitypub::PgActivityPubRepository;
use postgres_federation::{PostgresApUserRepository, PostgresFederationRepository};
use state::AppState;
struct NoOpEventPublisher;
#[async_trait]
impl EventPublisher for NoOpEventPublisher {
async fn publish(&self, _e: &DomainEvent) -> Result<(), DomainError> { Ok(()) }
}
pub async fn build_state(pool: PgPool, jwt_secret: String) -> AppState {
let event_publisher: Arc<dyn EventPublisher> = match std::env::var("NATS_URL") {
Ok(url) => match async_nats::connect(&url).await {
Ok(client) => {
tracing::info!("Connected to NATS at {url}");
Arc::new(nats::NatsEventPublisher::new(client))
}
Err(e) => {
tracing::warn!("Failed to connect to NATS at {url}: {e} — using no-op publisher");
Arc::new(NoOpEventPublisher)
}
},
Err(_) => {
tracing::info!("NATS_URL not set — using no-op event publisher");
Arc::new(NoOpEventPublisher)
}
};
let base_url = std::env::var("BASE_URL")
.unwrap_or_else(|_| "http://localhost:3000".into());
let allow_registration = std::env::var("ALLOW_REGISTRATION")
.map(|v| v == "true")
.unwrap_or(true);
let fed_debug = std::env::var("RUST_ENV")
.map(|v| v != "production")
.unwrap_or(true);
let fed_data = FederationData::new(
Arc::new(PostgresFederationRepository::new(pool.clone())),
Arc::new(PostgresApUserRepository::new(pool.clone(), base_url.clone())),
Arc::new(ThoughtsObjectHandler::new(
std::sync::Arc::new(PgActivityPubRepository::new(pool.clone())),
&base_url,
)),
base_url,
allow_registration,
"thoughts".to_string(),
None,
);
let fed_config = ApFederationConfig::new(fed_data, fed_debug).await
.expect("federation config failed");
AppState {
users: Arc::new(postgres::user::PgUserRepository::new(pool.clone())),
thoughts: Arc::new(postgres::thought::PgThoughtRepository::new(pool.clone())),
likes: Arc::new(postgres::like::PgLikeRepository::new(pool.clone())),
boosts: Arc::new(postgres::boost::PgBoostRepository::new(pool.clone())),
follows: Arc::new(postgres::follow::PgFollowRepository::new(pool.clone())),
blocks: Arc::new(postgres::block::PgBlockRepository::new(pool.clone())),
tags: Arc::new(postgres::tag::PgTagRepository::new(pool.clone())),
api_keys: Arc::new(postgres::api_key::PgApiKeyRepository::new(pool.clone())),
top_friends: Arc::new(postgres::top_friend::PgTopFriendRepository::new(pool.clone())),
notifications: Arc::new(postgres::notification::PgNotificationRepository::new(pool.clone())),
remote_actors: Arc::new(postgres::remote_actor::PgRemoteActorRepository::new(pool.clone())),
feed: Arc::new(postgres::feed::PgFeedRepository::new(pool.clone())),
search: Arc::new(PgSearchRepository::new(pool.clone())),
auth: Arc::new(auth::JwtAuthService::new(jwt_secret, 86400 * 30)),
hasher: Arc::new(auth::Argon2PasswordHasher),
events: event_publisher,
fed_config,
}
}