use std::error::Error; use crate::controllers::{account_controller, conversations_controller, groups_controller, search_controller, server_controller, user_controller, virtual_directory_controller}; use crate::controllers::routes::Method::{GET, POST}; use crate::data::http_request_handler::HttpRequestHandler; /// Project routes /// /// @author Pierre Hubert #[derive(PartialEq)] pub enum Method { GET, POST, } /// Define types pub type RequestResult = Result<(), Box>; pub type RequestProcess = Box RequestResult>; pub struct Route { /// The Verb used for the request pub method: Method, /// The URI of the request, with the leading "/" pub uri: &'static str, /// If set to true, unauthenticated requests will be rejected pub need_login: bool, /// The function called to process a request pub func: RequestProcess, } impl Route { pub fn get_without_login(uri: &'static str, func: RequestProcess) -> Route { Route { method: GET, need_login: false, uri, func } } pub fn post_without_login(uri: &'static str, func: RequestProcess) -> Route { Route { method: POST, need_login: false, uri, func } } pub fn post(uri: &'static str, func: RequestProcess) -> Route { Route { method: POST, need_login: true, uri, func } } } /// Get the list of routes available pub fn get_routes() -> Vec { vec![ // Server meta routes Route::get_without_login("/", Box::new(server_controller::main_index)), // Account controller Route::post_without_login("/account/login", Box::new(account_controller::login_user)), Route::post_without_login("/user/connectUSER", Box::new(account_controller::login_user)), Route::post("/account/logout", Box::new(account_controller::logout_user)), Route::post("/user/disconnectUSER", Box::new(account_controller::logout_user)), Route::post("/account/id", Box::new(account_controller::user_id)), Route::post("/user/getCurrentUserID", Box::new(account_controller::user_id)), // User controller Route::post_without_login("/user/getInfo", Box::new(user_controller::get_single)), Route::post_without_login("/user/getInfos", Box::new(user_controller::get_single)), Route::post_without_login("/user/getInfoMultiple", Box::new(user_controller::get_multiple)), Route::post_without_login("/user/getInfosMultiple", Box::new(user_controller::get_multiple)), Route::post_without_login("/user/getAdvancedUserInfo", Box::new(user_controller::get_advanced_info)), Route::post_without_login("/user/getAdvancedUserInfos", Box::new(user_controller::get_advanced_info)), // Conversations controller Route::post("/conversations/create", Box::new(conversations_controller::create)), Route::post("/conversations/getList", Box::new(conversations_controller::get_list)), Route::post("/conversations/getInfoOne", Box::new(conversations_controller::get_single)), Route::post("/conversations/getInfosOne", Box::new(conversations_controller::get_single)), Route::post("/conversations/updateSettings", Box::new(conversations_controller::update_settings)), Route::post("/conversations/getPrivate", Box::new(conversations_controller::find_private)), Route::post("/conversations/refresh", Box::new(conversations_controller::refresh_list)), Route::post("/conversations/refresh_single", Box::new(conversations_controller::refresh_single)), Route::post("/conversations/get_older_messages", Box::new(conversations_controller::get_older_messages)), Route::post("/conversations/sendMessage", Box::new(conversations_controller::send_message)), Route::post("/conversations/get_number_unread", Box::new(conversations_controller::count_unread)), Route::post("/conversations/get_list_unread", Box::new(conversations_controller::list_unread)), Route::post("/conversations/delete", Box::new(conversations_controller::delete_conversation)), Route::post("/conversations/updateMessage", Box::new(conversations_controller::update_message)), Route::post("/conversations/deleteMessage", Box::new(conversations_controller::delete_message)), // Search controller Route::post("/search/user", Box::new(search_controller::search_user)), Route::post("/user/search", Box::new(search_controller::search_user)), Route::post("/search/global", Box::new(search_controller::search_global)), // Groups controller Route::post("/groups/create", Box::new(groups_controller::create)), Route::post("/groups/get_my_list", Box::new(groups_controller::get_list_user)), Route::post("/groups/get_info", Box::new(groups_controller::get_info_single)), Route::post("/groups/get_multiple_info", Box::new(groups_controller::get_info_multiple)), Route::post("/groups/get_advanced_info", Box::new(groups_controller::get_advanced_info)), Route::post("/groups/get_settings", Box::new(groups_controller::get_settings)), Route::post("/groups/set_settings", Box::new(groups_controller::set_settings)), Route::post("/groups/checkVirtualDirectory", Box::new(groups_controller::check_virtual_dir)), Route::post("/groups/upload_logo", Box::new(groups_controller::upload_logo)), Route::post("/groups/delete_logo", Box::new(groups_controller::delete_logo)), Route::post("/groups/get_members", Box::new(groups_controller::get_members)), Route::post("/groups/invite", Box::new(groups_controller::invite_user)), Route::post("/groups/respond_invitation", Box::new(groups_controller::respond_invitation)), Route::post("/groups/send_request", Box::new(groups_controller::send_request)), Route::post("/groups/cancel_request", Box::new(groups_controller::cancel_request)), Route::post("/groups/delete_member", Box::new(groups_controller::delete_member)), Route::post("/groups/update_membership_level", Box::new(groups_controller::update_membership)), Route::post("/groups/respond_request", Box::new(groups_controller::respond_request)), Route::post("/groups/get_membership", Box::new(groups_controller::get_membership)), // Virtual directory controller Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)), Route::post("/virtualDirectory/find", Box::new(virtual_directory_controller::find)), ] }