79 lines
3.0 KiB
Rust
79 lines
3.0 KiB
Rust
//! 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<dyn UserCommand>,
|
|
pub user_query: Arc<dyn UserQuery>,
|
|
pub channel_command: Arc<dyn ChannelCommand>,
|
|
pub channel_query: Arc<dyn ChannelQuery>,
|
|
pub schedule_command: Arc<dyn ScheduleCommand>,
|
|
pub schedule_query: Arc<dyn ScheduleQuery>,
|
|
pub library_command: Arc<dyn LibraryCommand>,
|
|
pub library_query: Arc<dyn LibraryQuery>,
|
|
pub activity_command: Arc<dyn ActivityLogCommand>,
|
|
pub activity_query: Arc<dyn ActivityLogQuery>,
|
|
pub settings: Arc<dyn AppSettingsRepository>,
|
|
pub provider_config_command: Arc<dyn ProviderConfigCommand>,
|
|
pub provider_config_query: Arc<dyn ProviderConfigQuery>,
|
|
pub transcode_settings: Arc<dyn TranscodeSettingsRepository>,
|
|
}
|
|
|
|
/// 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,
|
|
}
|
|
}
|