refactor: adapters configured from config crate
This commit is contained in:
@@ -4,6 +4,7 @@ version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
config = { workspace = true }
|
||||
domain = { workspace = true }
|
||||
async-trait = { workspace = true }
|
||||
reqwest = { workspace = true }
|
||||
|
||||
@@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
)?))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user