From 17db8a71989e6133f27a37bc1c871471aa4f0aba Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Sat, 13 Feb 2021 16:15:25 +0100 Subject: [PATCH] Refactor project --- src/controllers/account_controller.rs | 2 +- src/controllers/calls_controller.rs | 2 +- src/controllers/comments_controller.rs | 2 +- src/controllers/conversations_controller.rs | 2 +- src/controllers/friends_controller.rs | 2 +- src/controllers/groups_controller.rs | 2 +- src/controllers/likes_controller.rs | 2 +- src/controllers/mod.rs | 3 --- src/controllers/notifications_controller.rs | 2 +- src/controllers/posts_controller.rs | 2 +- src/controllers/search_controller.rs | 2 +- src/controllers/server_controller.rs | 2 +- src/controllers/settings_controller.rs | 2 +- src/controllers/surveys_controller.rs | 2 +- src/controllers/user_controller.rs | 2 +- src/controllers/user_ws_controller.rs | 2 +- src/controllers/virtual_directory_controller.rs | 2 +- src/controllers/web_app_controller.rs | 2 +- src/data/base_request_handler.rs | 2 +- src/data/http_request_handler.rs | 2 +- src/data/user_ws_request_handler.rs | 2 +- src/helpers/requests_limit_helper.rs | 2 +- src/lib.rs | 5 ++++- src/main.rs | 2 +- src/{controllers => }/routes.rs | 2 +- src/{controllers => }/server.rs | 4 ++-- src/{controllers => }/user_ws_routes.rs | 0 27 files changed, 29 insertions(+), 29 deletions(-) rename src/{controllers => }/routes.rs (99%) rename src/{controllers => }/server.rs (98%) rename src/{controllers => }/user_ws_routes.rs (100%) diff --git a/src/controllers/account_controller.rs b/src/controllers/account_controller.rs index 7075369..6590b66 100644 --- a/src/controllers/account_controller.rs +++ b/src/controllers/account_controller.rs @@ -8,13 +8,13 @@ use crate::api_data::res_check_security_answers::ResCheckSecurityAnswers; use crate::api_data::res_check_security_questions_exists::ResCheckSecurityQuestionsExists; use crate::api_data::res_get_security_questions::ResGetSecurityQuestions; use crate::constants::PASSWORD_RESET_TOKEN_LENGTH; -use crate::controllers::routes::RequestResult; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::error::ResultBoxError; use crate::data::http_request_handler::HttpRequestHandler; use crate::data::new_account::NewAccount; use crate::data::user::{User, UserID}; use crate::helpers::{account_helper, user_helper}; +use crate::routes::RequestResult; /// Account controller /// diff --git a/src/controllers/calls_controller.rs b/src/controllers/calls_controller.rs index 1f2223b..5df95e0 100644 --- a/src/controllers/calls_controller.rs +++ b/src/controllers/calls_controller.rs @@ -13,7 +13,7 @@ use crate::api_data::joined_call_message::JoinedCallMessage; use crate::api_data::left_call_message::LeftCallMessage; use crate::api_data::new_call_signal::NewCallSignalAPI; use crate::api_data::user_calls_config::UserCallsConfig; -use crate::controllers::routes::RequestResult; +use crate::routes::RequestResult; use crate::controllers::user_ws_controller; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::call_signal::{CallSignal, CloseCallStream, IceCandidate, NewUserCallSignal, SdpType, UserCallOfferRequest}; diff --git a/src/controllers/comments_controller.rs b/src/controllers/comments_controller.rs index 5b5dd11..f3c3f87 100644 --- a/src/controllers/comments_controller.rs +++ b/src/controllers/comments_controller.rs @@ -5,7 +5,7 @@ use crate::api_data::comment_api::CommentAPI; use crate::api_data::res_create_comment::ResCreateComment; use crate::constants::PATH_COMMENTS_IMAGES; -use crate::controllers::routes::RequestResult; +use crate::routes::RequestResult; use crate::controllers::user_ws_controller; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::comment::Comment; diff --git a/src/controllers/conversations_controller.rs b/src/controllers/conversations_controller.rs index 0aa3d8d..fab12bc 100644 --- a/src/controllers/conversations_controller.rs +++ b/src/controllers/conversations_controller.rs @@ -11,7 +11,7 @@ use crate::api_data::list_unread_conversations_api::UnreadConversationAPI; use crate::api_data::res_count_unread_conversations::ResultCountUnreadConversations; use crate::api_data::res_create_conversation::ResCreateConversation; use crate::api_data::res_find_private_conversations::ResFindPrivateConversations; -use crate::controllers::routes::RequestResult; +use crate::routes::RequestResult; use crate::controllers::user_ws_controller; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::error::Res; diff --git a/src/controllers/friends_controller.rs b/src/controllers/friends_controller.rs index 8bdbbfc..be14b39 100644 --- a/src/controllers/friends_controller.rs +++ b/src/controllers/friends_controller.rs @@ -4,7 +4,7 @@ use crate::api_data::friend_api::FriendAPI; use crate::api_data::friendship_status_api::FriendshipStatusAPI; -use crate::controllers::routes::RequestResult; +use crate::routes::RequestResult; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::http_request_handler::HttpRequestHandler; use crate::data::notification::NotifEventType; diff --git a/src/controllers/groups_controller.rs b/src/controllers/groups_controller.rs index 0479a11..ac8359e 100644 --- a/src/controllers/groups_controller.rs +++ b/src/controllers/groups_controller.rs @@ -10,7 +10,7 @@ use crate::api_data::group_member_api::GroupMemberAPI; use crate::api_data::res_change_group_logo::ResChangeGroupLogo; use crate::api_data::res_create_group::GroupCreationResult; use crate::constants::{DEFAULT_GROUP_LOGO, PATH_GROUPS_LOGOS}; -use crate::controllers::routes::RequestResult; +use crate::routes::RequestResult; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::group::{Group, GroupAccessLevel, GroupPostsCreationLevel, GroupRegistrationLevel, GroupVisibilityLevel}; use crate::data::group_id::GroupID; diff --git a/src/controllers/likes_controller.rs b/src/controllers/likes_controller.rs index f883bd7..2000aea 100644 --- a/src/controllers/likes_controller.rs +++ b/src/controllers/likes_controller.rs @@ -2,7 +2,7 @@ //! //! @author Pierre Hubert -use crate::controllers::routes::RequestResult; +use crate::routes::RequestResult; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::error::ExecError; use crate::data::group::GroupAccessLevel; diff --git a/src/controllers/mod.rs b/src/controllers/mod.rs index 2755c14..3dea0f8 100644 --- a/src/controllers/mod.rs +++ b/src/controllers/mod.rs @@ -1,5 +1,3 @@ -pub mod routes; -pub mod server; pub mod server_controller; pub mod user_ws_controller; @@ -19,5 +17,4 @@ pub mod notifications_controller; pub mod virtual_directory_controller; pub mod web_app_controller; pub mod calls_controller; -pub mod user_ws_routes; pub mod user_ws_actions; \ No newline at end of file diff --git a/src/controllers/notifications_controller.rs b/src/controllers/notifications_controller.rs index 6df50b6..3f0cbdb 100644 --- a/src/controllers/notifications_controller.rs +++ b/src/controllers/notifications_controller.rs @@ -5,7 +5,7 @@ use crate::api_data::notification_api::NotificationAPI; use crate::api_data::res_count_all_unreads::ResCountAllUnread; use crate::api_data::res_number_unread_notifications::ResNumberUnreadNotifications; -use crate::controllers::routes::RequestResult; +use crate::routes::RequestResult; use crate::controllers::user_ws_controller; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::error::{Res, ResultBoxError}; diff --git a/src/controllers/posts_controller.rs b/src/controllers/posts_controller.rs index a0480ad..c5e3321 100644 --- a/src/controllers/posts_controller.rs +++ b/src/controllers/posts_controller.rs @@ -6,7 +6,7 @@ use crate::api_data::post_api::PostAPI; use crate::api_data::posts_targets_api::PostsTargets; use crate::api_data::res_create_post::ResCreatePost; use crate::constants::{PATH_POST_IMAGES, PATH_POST_PDF}; -use crate::controllers::routes::RequestResult; +use crate::routes::RequestResult; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::error::{ExecError, ResultBoxError}; use crate::data::group::GroupAccessLevel; diff --git a/src/controllers/search_controller.rs b/src/controllers/search_controller.rs index 2e3a987..80570bb 100644 --- a/src/controllers/search_controller.rs +++ b/src/controllers/search_controller.rs @@ -3,7 +3,7 @@ //! @author Pierre Hubert use crate::api_data::global_search_result_api::GlobalSearchResultAPI; -use crate::controllers::routes::RequestResult; +use crate::routes::RequestResult; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::global_search_result::GlobalSearchResult; use crate::data::http_request_handler::HttpRequestHandler; diff --git a/src/controllers/server_controller.rs b/src/controllers/server_controller.rs index 43a7504..3b5e81b 100644 --- a/src/controllers/server_controller.rs +++ b/src/controllers/server_controller.rs @@ -1,6 +1,6 @@ -use crate::controllers::routes::RequestResult; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::http_request_handler::HttpRequestHandler; +use crate::routes::RequestResult; /// Main server controller /// diff --git a/src/controllers/settings_controller.rs b/src/controllers/settings_controller.rs index 8032a9a..b2bb101 100644 --- a/src/controllers/settings_controller.rs +++ b/src/controllers/settings_controller.rs @@ -8,7 +8,7 @@ use crate::api_data::language_settings_api::LanguageSettingsAPI; use crate::api_data::res_create_custom_emoji::ResCreateCustomEmoji; use crate::api_data::security_settings_api::SecuritySettingsAPI; use crate::constants::SUPPORTED_LANGUAGES; -use crate::controllers::routes::RequestResult; +use crate::routes::RequestResult; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::general_settings::GeneralSettings; use crate::data::http_request_handler::HttpRequestHandler; diff --git a/src/controllers/surveys_controller.rs b/src/controllers/surveys_controller.rs index 337c467..0c2cec1 100644 --- a/src/controllers/surveys_controller.rs +++ b/src/controllers/surveys_controller.rs @@ -4,7 +4,7 @@ use crate::api_data::survey_api::SurveyAPI; use crate::constants::MAXIMUM_NUMBER_SURVEY_CHOICES; -use crate::controllers::routes::RequestResult; +use crate::routes::RequestResult; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::error::ResultBoxError; use crate::data::http_request_handler::HttpRequestHandler; diff --git a/src/controllers/user_controller.rs b/src/controllers/user_controller.rs index 0eaa45f..09149dd 100644 --- a/src/controllers/user_controller.rs +++ b/src/controllers/user_controller.rs @@ -7,7 +7,7 @@ use std::collections::HashMap; use crate::api_data::user_info::APIUserInfo; -use crate::controllers::routes::RequestResult; +use crate::routes::RequestResult; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::http_request_handler::HttpRequestHandler; use crate::data::user::UserID; diff --git a/src/controllers/user_ws_controller.rs b/src/controllers/user_ws_controller.rs index dda6d31..2c77a6d 100644 --- a/src/controllers/user_ws_controller.rs +++ b/src/controllers/user_ws_controller.rs @@ -14,7 +14,6 @@ use serde_json::Value; use crate::api_data::res_get_ws_token::ResGetWsToken; use crate::constants::{USER_LAST_ACTIVITY_REFRESH, WS_ACCESS_TOKEN_LENGTH}; use crate::controllers::user_ws_controller::ws_connections_list::{add_connection, find_connection, get_ws_connections_list, remove_connection}; -use crate::controllers::user_ws_routes::find_user_ws_route; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::config::conf; use crate::data::error::{ExecError, Res, ResultBoxError}; @@ -26,6 +25,7 @@ use crate::data::user_ws_message::UserWsMessage; use crate::data::user_ws_request_handler::{UserWsRequestHandler, UserWsResponseType}; use crate::helpers::{account_helper, events_helper}; use crate::helpers::events_helper::Event; +use crate::user_ws_routes::find_user_ws_route; use crate::utils::crypt_utils::rand_str; use crate::utils::date_utils::time; diff --git a/src/controllers/virtual_directory_controller.rs b/src/controllers/virtual_directory_controller.rs index cb35edb..d836267 100644 --- a/src/controllers/virtual_directory_controller.rs +++ b/src/controllers/virtual_directory_controller.rs @@ -4,7 +4,7 @@ use crate::api_data::res_find_user_by_virtual_directory::FindUserByVirtualDirectoryAPIResult; use crate::api_data::res_find_virtual_directory::ResultFindVirtualDirectory; -use crate::controllers::routes::RequestResult; +use crate::routes::RequestResult; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::http_request_handler::HttpRequestHandler; use crate::helpers::{groups_helper, user_helper}; diff --git a/src/controllers/web_app_controller.rs b/src/controllers/web_app_controller.rs index 781da34..45d76b7 100644 --- a/src/controllers/web_app_controller.rs +++ b/src/controllers/web_app_controller.rs @@ -3,10 +3,10 @@ //! @author Pierre Hubert use crate::api_data::user_membership_api::UserMembershipAPI; -use crate::controllers::routes::RequestResult; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::http_request_handler::HttpRequestHandler; use crate::helpers::webapp_helper; +use crate::routes::RequestResult; /// Get the list of memberships of a given user pub fn get_memberships(r: &mut HttpRequestHandler) -> RequestResult { diff --git a/src/data/base_request_handler.rs b/src/data/base_request_handler.rs index 9db0eae..64626fe 100644 --- a/src/data/base_request_handler.rs +++ b/src/data/base_request_handler.rs @@ -11,7 +11,6 @@ use serde::Serialize; use crate::api_data::http_error::HttpError; use crate::constants::PASSWORD_MIN_LENGTH; -use crate::controllers::routes::RequestResult; use crate::data::comment::Comment; use crate::data::conversation::ConvID; use crate::data::custom_emoji::CustomEmoji; @@ -23,6 +22,7 @@ use crate::data::user::UserID; use crate::data::user_token::UserAccessToken; use crate::helpers::{account_helper, comments_helper, conversations_helper, custom_emojies_helper, friends_helper, groups_helper, posts_helper, user_helper, virtual_directory_helper}; use crate::helpers::virtual_directory_helper::VirtualDirType; +use crate::routes::RequestResult; use crate::utils::pdf_utils::is_valid_pdf; use crate::utils::string_utils::{check_emoji_code, check_string_before_insert, check_url, remove_html_nodes}; use crate::utils::user_data_utils::{generate_new_user_data_file_name, prepare_file_creation, user_data_path}; diff --git a/src/data/http_request_handler.rs b/src/data/http_request_handler.rs index 3aa2d3f..e422747 100644 --- a/src/data/http_request_handler.rs +++ b/src/data/http_request_handler.rs @@ -7,7 +7,7 @@ use actix_web::http::{HeaderName, HeaderValue, StatusCode}; use serde::Serialize; use crate::api_data::http_error::HttpError; -use crate::controllers::routes::RequestResult; +use crate::routes::RequestResult; use crate::data::api_client::APIClient; use crate::data::base_request_handler::{BaseRequestHandler, RequestValue}; use crate::data::config::conf; diff --git a/src/data/user_ws_request_handler.rs b/src/data/user_ws_request_handler.rs index 1e09ca5..52a5d51 100644 --- a/src/data/user_ws_request_handler.rs +++ b/src/data/user_ws_request_handler.rs @@ -5,7 +5,7 @@ use std::collections::HashMap; use serde::Serialize; use crate::api_data::http_error::HttpError; -use crate::controllers::routes::RequestResult; +use crate::routes::RequestResult; use crate::data::base_request_handler::{BaseRequestHandler, RequestValue}; use crate::data::error::ResultBoxError; use crate::data::user_token::UserAccessToken; diff --git a/src/helpers/requests_limit_helper.rs b/src/helpers/requests_limit_helper.rs index e6aaf6e..e67aa1f 100644 --- a/src/helpers/requests_limit_helper.rs +++ b/src/helpers/requests_limit_helper.rs @@ -6,10 +6,10 @@ use std::sync::{Arc, Mutex}; use crate::constants::LIMIT_COUNTER_LIFETIME; -use crate::controllers::routes::{LimitPolicy, Route}; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::error::{ExecError, ResultBoxError}; use crate::data::http_request_handler::HttpRequestHandler; +use crate::routes::{LimitPolicy, Route}; use crate::utils::date_utils; use crate::utils::date_utils::time; diff --git a/src/lib.rs b/src/lib.rs index 840cc69..696580c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,4 +11,7 @@ pub mod controllers; pub mod api_data; pub mod utils; -pub mod constants; \ No newline at end of file +pub mod constants; +pub mod server; +pub mod user_ws_routes; +pub mod routes; \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 3ad1933..6b8e3c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ -use comunic_server::controllers::server; use comunic_server::data::config::{conf, Config}; use comunic_server::helpers::database; +use comunic_server::server; #[actix_rt::main] async fn main() -> std::io::Result<()> { diff --git a/src/controllers/routes.rs b/src/routes.rs similarity index 99% rename from src/controllers/routes.rs rename to src/routes.rs index 4a26ee7..d654eae 100644 --- a/src/controllers/routes.rs +++ b/src/routes.rs @@ -1,8 +1,8 @@ use std::error::Error; use crate::controllers::{account_controller, calls_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, notifications_controller, posts_controller, search_controller, server_controller, settings_controller, surveys_controller, user_controller, user_ws_controller, virtual_directory_controller, web_app_controller}; -use crate::controllers::routes::Method::{GET, POST}; use crate::data::http_request_handler::HttpRequestHandler; +use crate::routes::Method::{GET, POST}; /// Project routes /// diff --git a/src/controllers/server.rs b/src/server.rs similarity index 98% rename from src/controllers/server.rs rename to src/server.rs index 55cb6f8..e78424e 100644 --- a/src/controllers/server.rs +++ b/src/server.rs @@ -15,8 +15,8 @@ use percent_encoding::percent_decode_str; use crate::api_data::http_error::HttpError; use crate::constants::MAX_REQUEST_SIZE; use crate::controllers::{rtc_relay_controller, user_ws_controller}; -use crate::controllers::routes::{get_routes, RequestResult, Route}; -use crate::controllers::routes::Method::{GET, POST}; +use crate::routes::{get_routes, RequestResult, Route}; +use crate::routes::Method::{GET, POST}; use crate::data::base_request_handler::{BaseRequestHandler, PostFile, RequestValue}; use crate::data::config::Config; use crate::data::http_request_handler::HttpRequestHandler; diff --git a/src/controllers/user_ws_routes.rs b/src/user_ws_routes.rs similarity index 100% rename from src/controllers/user_ws_routes.rs rename to src/user_ws_routes.rs