//! Wiring function that instantiates all PostgreSQL repositories and returns them //! as trait-object Arcs. use std::sync::Arc; use sqlx::PgPool; use domain::ports::{ activity::{ActivityLogCommand, ActivityLogQuery}, channel::{ChannelCommand, ChannelQuery}, library::{LibraryCommand, LibraryQuery}, provider_config::{ProviderConfigCommand, ProviderConfigQuery}, schedule::{ScheduleCommand, ScheduleQuery}, settings::AppSettingsRepository, transcode::TranscodeSettingsRepository, user::{UserCommand, UserQuery}, }; use crate::{ activity::PgActivityLog, channel::PgChannelRepository, library::PgLibraryRepository, provider_config::PgProviderConfig, schedule::PgScheduleRepository, settings::PgAppSettings, transcode::PgTranscodeSettings, user::PgUserRepository, }; /// All PostgreSQL adapter outputs, ready to be injected into the application layer. pub struct PostgresWireOutput { pub user_command: Arc, pub user_query: Arc, pub channel_command: Arc, pub channel_query: Arc, pub schedule_command: Arc, pub schedule_query: Arc, pub library_command: Arc, pub library_query: Arc, pub activity_command: Arc, pub activity_query: Arc, pub settings: Arc, pub provider_config_command: Arc, pub provider_config_query: Arc, pub transcode_settings: Arc, } /// Create all PostgreSQL repository implementations from a single pool. /// /// Each struct wraps a clone of the same pool. Repositories that implement /// both Command and Query traits share a single `Arc` via `.clone()`. pub fn wire(pool: PgPool) -> PostgresWireOutput { let user = Arc::new(PgUserRepository::new(pool.clone())); let channel = Arc::new(PgChannelRepository::new(pool.clone())); let schedule = Arc::new(PgScheduleRepository::new(pool.clone())); let library = Arc::new(PgLibraryRepository::new(pool.clone())); let activity = Arc::new(PgActivityLog::new(pool.clone())); let settings = Arc::new(PgAppSettings::new(pool.clone())); let provider_config = Arc::new(PgProviderConfig::new(pool.clone())); let transcode_settings = Arc::new(PgTranscodeSettings::new(pool)); PostgresWireOutput { user_command: user.clone(), user_query: user, channel_command: channel.clone(), channel_query: channel, schedule_command: schedule.clone(), schedule_query: schedule, library_command: library.clone(), library_query: library, activity_command: activity.clone(), activity_query: activity, settings, provider_config_command: provider_config.clone(), provider_config_query: provider_config, transcode_settings, } }