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