torrust_index/
common.rs

1use std::sync::Arc;
2
3use crate::cache::image::manager::ImageCacheService;
4use crate::config::Configuration;
5use crate::databases::database::Database;
6use crate::services::authentication::{DbUserAuthenticationRepository, JsonWebToken, Service};
7use crate::services::category::{self, DbCategoryRepository};
8use crate::services::tag::{self, DbTagRepository};
9use crate::services::torrent::{
10    DbCanonicalInfoHashGroupRepository, DbTorrentAnnounceUrlRepository, DbTorrentFileRepository, DbTorrentInfoRepository,
11    DbTorrentListingGenerator, DbTorrentRepository, DbTorrentTagRepository,
12};
13use crate::services::user::{self, DbBannedUserList, DbUserProfileRepository, Repository};
14use crate::services::{about, proxy, settings, torrent};
15use crate::tracker::statistics_importer::StatisticsImporter;
16use crate::web::api::server::v1::auth::Authentication;
17use crate::{mailer, tracker};
18
19pub type Username = String;
20
21pub struct AppData {
22    pub cfg: Arc<Configuration>,
23    pub database: Arc<Box<dyn Database>>,
24    pub json_web_token: Arc<JsonWebToken>,
25    pub auth: Arc<Authentication>,
26    pub authentication_service: Arc<Service>,
27    pub tracker_service: Arc<tracker::service::Service>,
28    pub tracker_statistics_importer: Arc<StatisticsImporter>,
29    pub mailer: Arc<mailer::Service>,
30    pub image_cache_manager: Arc<ImageCacheService>,
31    // Repositories
32    pub category_repository: Arc<DbCategoryRepository>,
33    pub tag_repository: Arc<DbTagRepository>,
34    pub user_repository: Arc<Box<dyn Repository>>,
35    pub user_authentication_repository: Arc<DbUserAuthenticationRepository>,
36    pub user_profile_repository: Arc<DbUserProfileRepository>,
37    pub torrent_repository: Arc<DbTorrentRepository>,
38    pub torrent_info_hash_repository: Arc<DbCanonicalInfoHashGroupRepository>,
39    pub torrent_info_repository: Arc<DbTorrentInfoRepository>,
40    pub torrent_file_repository: Arc<DbTorrentFileRepository>,
41    pub torrent_announce_url_repository: Arc<DbTorrentAnnounceUrlRepository>,
42    pub torrent_tag_repository: Arc<DbTorrentTagRepository>,
43    pub torrent_listing_generator: Arc<DbTorrentListingGenerator>,
44    pub banned_user_list: Arc<DbBannedUserList>,
45    // Services
46    pub category_service: Arc<category::Service>,
47    pub tag_service: Arc<tag::Service>,
48    pub proxy_service: Arc<proxy::Service>,
49    pub settings_service: Arc<settings::Service>,
50    pub torrent_service: Arc<torrent::Index>,
51    pub registration_service: Arc<user::RegistrationService>,
52    pub profile_service: Arc<user::ProfileService>,
53    pub ban_service: Arc<user::BanService>,
54    pub about_service: Arc<about::Service>,
55}
56
57impl AppData {
58    #[allow(clippy::too_many_arguments)]
59    pub fn new(
60        cfg: Arc<Configuration>,
61        database: Arc<Box<dyn Database>>,
62        json_web_token: Arc<JsonWebToken>,
63        auth: Arc<Authentication>,
64        authentication_service: Arc<Service>,
65        tracker_service: Arc<tracker::service::Service>,
66        tracker_statistics_importer: Arc<StatisticsImporter>,
67        mailer: Arc<mailer::Service>,
68        image_cache_manager: Arc<ImageCacheService>,
69        // Repositories
70        category_repository: Arc<DbCategoryRepository>,
71        tag_repository: Arc<DbTagRepository>,
72        user_repository: Arc<Box<dyn Repository>>,
73        user_authentication_repository: Arc<DbUserAuthenticationRepository>,
74        user_profile_repository: Arc<DbUserProfileRepository>,
75        torrent_repository: Arc<DbTorrentRepository>,
76        torrent_info_hash_repository: Arc<DbCanonicalInfoHashGroupRepository>,
77        torrent_info_repository: Arc<DbTorrentInfoRepository>,
78        torrent_file_repository: Arc<DbTorrentFileRepository>,
79        torrent_announce_url_repository: Arc<DbTorrentAnnounceUrlRepository>,
80        torrent_tag_repository: Arc<DbTorrentTagRepository>,
81        torrent_listing_generator: Arc<DbTorrentListingGenerator>,
82        banned_user_list: Arc<DbBannedUserList>,
83        // Services
84        category_service: Arc<category::Service>,
85        tag_service: Arc<tag::Service>,
86        proxy_service: Arc<proxy::Service>,
87        settings_service: Arc<settings::Service>,
88        torrent_service: Arc<torrent::Index>,
89        registration_service: Arc<user::RegistrationService>,
90        profile_service: Arc<user::ProfileService>,
91        ban_service: Arc<user::BanService>,
92        about_service: Arc<about::Service>,
93    ) -> AppData {
94        AppData {
95            cfg,
96            database,
97            json_web_token,
98            auth,
99            authentication_service,
100            tracker_service,
101            tracker_statistics_importer,
102            mailer,
103            image_cache_manager,
104            // Repositories
105            category_repository,
106            tag_repository,
107            user_repository,
108            user_authentication_repository,
109            user_profile_repository,
110            torrent_repository,
111            torrent_info_hash_repository,
112            torrent_info_repository,
113            torrent_file_repository,
114            torrent_announce_url_repository,
115            torrent_tag_repository,
116            torrent_listing_generator,
117            banned_user_list,
118            // Services
119            category_service,
120            tag_service,
121            proxy_service,
122            settings_service,
123            torrent_service,
124            registration_service,
125            profile_service,
126            ban_service,
127            about_service,
128        }
129    }
130}