refactor: adapters configured from config crate

This commit is contained in:
2026-10-25 21:07:19 +01:00
parent 1f724bb064
commit 04f9c13625
45 changed files with 277 additions and 177 deletions

View File

@@ -4,6 +4,7 @@ version = "0.1.0"
edition = "2021"
[dependencies]
config = { workspace = true }
domain = { workspace = true }
async-trait = { workspace = true }
reqwest = { workspace = true }

View File

@@ -3,11 +3,9 @@ pub struct PosterFetcherConfig {
}
impl PosterFetcherConfig {
pub fn from_env() -> Self {
let timeout_seconds = std::env::var("POSTER_FETCH_TIMEOUT_SECONDS")
.ok()
.and_then(|v| v.parse().ok())
.unwrap_or(30);
Self { timeout_seconds }
pub fn from_config(config: &::config::MetadataConfig) -> Self {
Self {
timeout_seconds: config.poster_fetch_timeout_seconds,
}
}
}

View File

@@ -59,14 +59,18 @@ impl ImageFetcher for ReqwestPosterFetcher {
}
}
pub fn create() -> anyhow::Result<std::sync::Arc<dyn domain::ports::PosterFetcherClient>> {
pub fn create(
config: &::config::MetadataConfig,
) -> anyhow::Result<std::sync::Arc<dyn domain::ports::PosterFetcherClient>> {
Ok(std::sync::Arc::new(ReqwestPosterFetcher::new(
PosterFetcherConfig::from_env(),
PosterFetcherConfig::from_config(config),
)?))
}
pub fn create_image_fetcher() -> anyhow::Result<std::sync::Arc<dyn domain::ports::ImageFetcher>> {
pub fn create_image_fetcher(
config: &::config::MetadataConfig,
) -> anyhow::Result<std::sync::Arc<dyn domain::ports::ImageFetcher>> {
Ok(std::sync::Arc::new(ReqwestPosterFetcher::new(
PosterFetcherConfig::from_env(),
PosterFetcherConfig::from_config(config),
)?))
}