Skip to content

Commit 2f86d54

Browse files
committed
refactor: [#1217] extract HttpApiContainer
1 parent a2bf1cd commit 2f86d54

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

src/container.rs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::sync::Arc;
22

33
use tokio::sync::RwLock;
4-
use torrust_tracker_configuration::{Core, HttpTracker, UdpTracker};
4+
use torrust_tracker_configuration::{Core, HttpApi, HttpTracker, UdpTracker};
55

66
use crate::core::announce_handler::AnnounceHandler;
77
use crate::core::authentication::handler::KeysHandler;
@@ -83,3 +83,30 @@ impl HttpTrackerContainer {
8383
}
8484
}
8585
}
86+
87+
pub struct HttpApiContainer {
88+
pub core_config: Arc<Core>,
89+
pub http_api_config: Arc<HttpApi>,
90+
pub in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
91+
pub keys_handler: Arc<KeysHandler>,
92+
pub whitelist_manager: Arc<WhitelistManager>,
93+
pub ban_service: Arc<RwLock<BanService>>,
94+
pub stats_event_sender: Arc<Option<Box<dyn Sender>>>,
95+
pub stats_repository: Arc<Repository>,
96+
}
97+
98+
impl HttpApiContainer {
99+
#[must_use]
100+
pub fn from_app_container(http_api_config: &Arc<HttpApi>, app_container: &Arc<AppContainer>) -> Self {
101+
Self {
102+
http_api_config: http_api_config.clone(),
103+
core_config: app_container.core_config.clone(),
104+
in_memory_torrent_repository: app_container.in_memory_torrent_repository.clone(),
105+
keys_handler: app_container.keys_handler.clone(),
106+
whitelist_manager: app_container.whitelist_manager.clone(),
107+
ban_service: app_container.ban_service.clone(),
108+
stats_event_sender: app_container.stats_event_sender.clone(),
109+
stats_repository: app_container.stats_repository.clone(),
110+
}
111+
}
112+
}

0 commit comments

Comments
 (0)