2020-05-21 13:28:07 +00:00
|
|
|
use std::error::Error;
|
|
|
|
|
2020-07-10 08:53:37 +00:00
|
|
|
use crate::controllers::{account_controller, comments_controller, conversations_controller, friends_controller, groups_controller, likes_controller, movies_controller, posts_controller, search_controller, server_controller, surveys_controller, user_controller, virtual_directory_controller};
|
2020-05-21 13:43:53 +00:00
|
|
|
use crate::controllers::routes::Method::{GET, POST};
|
2020-05-21 13:28:07 +00:00
|
|
|
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<dyn Error>>;
|
|
|
|
pub type RequestProcess = Box<dyn Fn(&mut HttpRequestHandler) -> 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,
|
|
|
|
}
|
|
|
|
|
2020-05-21 13:39:20 +00:00
|
|
|
impl Route {
|
|
|
|
|
|
|
|
pub fn get_without_login(uri: &'static str, func: RequestProcess) -> Route {
|
|
|
|
Route {
|
|
|
|
method: GET,
|
|
|
|
need_login: false,
|
|
|
|
uri,
|
|
|
|
func
|
|
|
|
}
|
|
|
|
}
|
2020-05-21 13:43:53 +00:00
|
|
|
|
|
|
|
pub fn post_without_login(uri: &'static str, func: RequestProcess) -> Route {
|
|
|
|
Route {
|
|
|
|
method: POST,
|
|
|
|
need_login: false,
|
|
|
|
uri,
|
|
|
|
func
|
|
|
|
}
|
|
|
|
}
|
2020-05-24 15:57:47 +00:00
|
|
|
|
|
|
|
pub fn post(uri: &'static str, func: RequestProcess) -> Route {
|
|
|
|
Route {
|
|
|
|
method: POST,
|
|
|
|
need_login: true,
|
|
|
|
uri,
|
|
|
|
func
|
|
|
|
}
|
|
|
|
}
|
2020-05-21 13:39:20 +00:00
|
|
|
}
|
|
|
|
|
2020-05-21 13:28:07 +00:00
|
|
|
/// Get the list of routes available
|
|
|
|
pub fn get_routes() -> Vec<Route> {
|
|
|
|
vec![
|
|
|
|
// Server meta routes
|
2020-05-21 13:43:53 +00:00
|
|
|
Route::get_without_login("/", Box::new(server_controller::main_index)),
|
|
|
|
|
|
|
|
// Account controller
|
|
|
|
Route::post_without_login("/account/login", Box::new(account_controller::login_user)),
|
2020-05-23 12:08:22 +00:00
|
|
|
Route::post_without_login("/user/connectUSER", Box::new(account_controller::login_user)),
|
2020-05-24 15:57:47 +00:00
|
|
|
|
2020-05-24 17:19:07 +00:00
|
|
|
Route::post("/account/logout", Box::new(account_controller::logout_user)),
|
|
|
|
Route::post("/user/disconnectUSER", Box::new(account_controller::logout_user)),
|
|
|
|
|
2020-05-24 15:57:47 +00:00
|
|
|
Route::post("/account/id", Box::new(account_controller::user_id)),
|
|
|
|
Route::post("/user/getCurrentUserID", Box::new(account_controller::user_id)),
|
2020-05-25 11:25:51 +00:00
|
|
|
|
|
|
|
// 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)),
|
2020-05-27 11:20:08 +00:00
|
|
|
|
|
|
|
Route::post_without_login("/user/getInfoMultiple", Box::new(user_controller::get_multiple)),
|
|
|
|
Route::post_without_login("/user/getInfosMultiple", Box::new(user_controller::get_multiple)),
|
2020-05-27 11:28:00 +00:00
|
|
|
|
|
|
|
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)),
|
2020-06-01 15:17:18 +00:00
|
|
|
|
2020-06-29 13:45:26 +00:00
|
|
|
// Friends controller
|
|
|
|
Route::post("/friends/getList", Box::new(friends_controller::get_list)),
|
|
|
|
|
2020-06-30 06:14:58 +00:00
|
|
|
Route::post("/friends/get_single_infos", Box::new(friends_controller::get_single_friendship_info)),
|
|
|
|
|
2020-06-30 05:49:23 +00:00
|
|
|
Route::post("/friends/get_user_list", Box::new(friends_controller::get_other_user_list)),
|
|
|
|
|
2020-06-30 07:50:31 +00:00
|
|
|
Route::post("/friends/getStatus", Box::new(friends_controller::get_status)),
|
|
|
|
|
2020-06-30 08:06:53 +00:00
|
|
|
Route::post("/friends/sendRequest", Box::new(friends_controller::send_request)),
|
|
|
|
|
2020-06-30 08:24:18 +00:00
|
|
|
Route::post("/friends/removeRequest", Box::new(friends_controller::cancel_request)),
|
|
|
|
|
2020-06-30 12:05:36 +00:00
|
|
|
Route::post("/friends/respondRequest", Box::new(friends_controller::respond_request)),
|
|
|
|
|
2020-06-30 12:27:31 +00:00
|
|
|
Route::post("/friends/remove", Box::new(friends_controller::remove_friend)),
|
|
|
|
|
2020-06-30 12:48:39 +00:00
|
|
|
Route::post("/friends/setFollowing", Box::new(friends_controller::set_following)),
|
|
|
|
|
2020-06-30 12:54:45 +00:00
|
|
|
Route::post("/friends/set_can_post_texts", Box::new(friends_controller::set_can_post_texts)),
|
|
|
|
|
2020-06-30 08:24:18 +00:00
|
|
|
|
2020-06-03 11:36:19 +00:00
|
|
|
// Conversations controller
|
|
|
|
Route::post("/conversations/create", Box::new(conversations_controller::create)),
|
|
|
|
|
2020-06-04 15:51:22 +00:00
|
|
|
Route::post("/conversations/getList", Box::new(conversations_controller::get_list)),
|
|
|
|
|
2020-06-12 06:50:09 +00:00
|
|
|
Route::post("/conversations/getInfoOne", Box::new(conversations_controller::get_single)),
|
|
|
|
Route::post("/conversations/getInfosOne", Box::new(conversations_controller::get_single)),
|
|
|
|
|
2020-06-12 07:23:02 +00:00
|
|
|
Route::post("/conversations/updateSettings", Box::new(conversations_controller::update_settings)),
|
|
|
|
|
2020-06-18 07:06:59 +00:00
|
|
|
Route::post("/conversations/getPrivate", Box::new(conversations_controller::find_private)),
|
|
|
|
|
2020-06-18 07:55:02 +00:00
|
|
|
Route::post("/conversations/refresh", Box::new(conversations_controller::refresh_list)),
|
|
|
|
|
2020-06-20 05:42:18 +00:00
|
|
|
Route::post("/conversations/refresh_single", Box::new(conversations_controller::refresh_single)),
|
|
|
|
|
2020-06-22 12:16:52 +00:00
|
|
|
Route::post("/conversations/get_older_messages", Box::new(conversations_controller::get_older_messages)),
|
|
|
|
|
2020-06-20 09:55:39 +00:00
|
|
|
Route::post("/conversations/sendMessage", Box::new(conversations_controller::send_message)),
|
|
|
|
|
2020-06-22 12:32:14 +00:00
|
|
|
Route::post("/conversations/get_number_unread", Box::new(conversations_controller::count_unread)),
|
|
|
|
|
2020-06-22 12:41:14 +00:00
|
|
|
Route::post("/conversations/get_list_unread", Box::new(conversations_controller::list_unread)),
|
|
|
|
|
2020-06-22 17:02:34 +00:00
|
|
|
Route::post("/conversations/delete", Box::new(conversations_controller::delete_conversation)),
|
|
|
|
|
2020-06-23 12:02:16 +00:00
|
|
|
Route::post("/conversations/updateMessage", Box::new(conversations_controller::update_message)),
|
|
|
|
|
2020-06-23 12:09:52 +00:00
|
|
|
Route::post("/conversations/deleteMessage", Box::new(conversations_controller::delete_message)),
|
|
|
|
|
2020-06-01 15:17:18 +00:00
|
|
|
|
2020-06-23 13:06:26 +00:00
|
|
|
|
|
|
|
// Search controller
|
|
|
|
Route::post("/search/user", Box::new(search_controller::search_user)),
|
|
|
|
Route::post("/user/search", Box::new(search_controller::search_user)),
|
|
|
|
|
2020-06-23 13:14:17 +00:00
|
|
|
Route::post("/search/global", Box::new(search_controller::search_global)),
|
|
|
|
|
2020-06-23 13:06:26 +00:00
|
|
|
|
2020-06-23 17:04:32 +00:00
|
|
|
// Groups controller
|
|
|
|
Route::post("/groups/create", Box::new(groups_controller::create)),
|
|
|
|
|
2020-06-24 07:21:24 +00:00
|
|
|
Route::post("/groups/get_my_list", Box::new(groups_controller::get_list_user)),
|
|
|
|
|
2020-06-24 11:34:09 +00:00
|
|
|
Route::post("/groups/get_info", Box::new(groups_controller::get_info_single)),
|
|
|
|
|
2020-06-25 07:26:58 +00:00
|
|
|
Route::post("/groups/get_multiple_info", Box::new(groups_controller::get_info_multiple)),
|
|
|
|
|
2020-06-25 11:39:37 +00:00
|
|
|
Route::post("/groups/get_advanced_info", Box::new(groups_controller::get_advanced_info)),
|
|
|
|
|
2020-06-25 11:45:21 +00:00
|
|
|
Route::post("/groups/get_settings", Box::new(groups_controller::get_settings)),
|
|
|
|
|
2020-06-25 15:55:46 +00:00
|
|
|
Route::post("/groups/set_settings", Box::new(groups_controller::set_settings)),
|
|
|
|
|
2020-06-26 07:52:19 +00:00
|
|
|
Route::post("/groups/checkVirtualDirectory", Box::new(groups_controller::check_virtual_dir)),
|
|
|
|
|
2020-06-26 07:55:53 +00:00
|
|
|
Route::post("/groups/upload_logo", Box::new(groups_controller::upload_logo)),
|
|
|
|
|
2020-06-26 08:35:54 +00:00
|
|
|
Route::post("/groups/delete_logo", Box::new(groups_controller::delete_logo)),
|
|
|
|
|
2020-06-26 09:00:12 +00:00
|
|
|
Route::post("/groups/get_members", Box::new(groups_controller::get_members)),
|
|
|
|
|
2020-06-27 05:29:23 +00:00
|
|
|
Route::post("/groups/invite", Box::new(groups_controller::invite_user)),
|
|
|
|
|
2020-06-29 06:46:57 +00:00
|
|
|
Route::post("/groups/cancel_invitation", Box::new(groups_controller::cancel_invitation)),
|
|
|
|
|
2020-06-27 11:19:56 +00:00
|
|
|
Route::post("/groups/respond_invitation", Box::new(groups_controller::respond_invitation)),
|
|
|
|
|
2020-06-27 12:37:49 +00:00
|
|
|
Route::post("/groups/send_request", Box::new(groups_controller::send_request)),
|
|
|
|
|
2020-06-27 12:50:14 +00:00
|
|
|
Route::post("/groups/cancel_request", Box::new(groups_controller::cancel_request)),
|
|
|
|
|
2020-06-27 16:06:13 +00:00
|
|
|
Route::post("/groups/delete_member", Box::new(groups_controller::delete_member)),
|
|
|
|
|
2020-06-27 16:36:53 +00:00
|
|
|
Route::post("/groups/update_membership_level", Box::new(groups_controller::update_membership)),
|
|
|
|
|
2020-06-29 06:31:07 +00:00
|
|
|
Route::post("/groups/respond_request", Box::new(groups_controller::respond_request)),
|
|
|
|
|
2020-06-29 06:39:21 +00:00
|
|
|
Route::post("/groups/get_membership", Box::new(groups_controller::get_membership)),
|
|
|
|
|
2020-06-29 06:55:36 +00:00
|
|
|
Route::post("/groups/remove_membership", Box::new(groups_controller::remove_membership)),
|
|
|
|
|
2020-06-29 07:03:32 +00:00
|
|
|
Route::post("/groups/set_following", Box::new(groups_controller::set_following)),
|
|
|
|
|
2020-06-29 07:10:57 +00:00
|
|
|
Route::post("/groups/delete", Box::new(groups_controller::delete_group)),
|
|
|
|
|
2020-07-06 07:20:31 +00:00
|
|
|
|
2020-07-02 16:19:04 +00:00
|
|
|
// Posts controller
|
|
|
|
Route::post("/posts/get_user", Box::new(posts_controller::get_list_user)),
|
|
|
|
|
2020-07-06 07:20:31 +00:00
|
|
|
Route::post("/posts/get_group", Box::new(posts_controller::get_list_group)),
|
|
|
|
|
2020-07-06 08:01:54 +00:00
|
|
|
Route::post("/posts/get_latest", Box::new(posts_controller::get_latest)),
|
|
|
|
|
2020-07-06 09:00:59 +00:00
|
|
|
Route::post("/posts/get_single", Box::new(posts_controller::get_single)),
|
|
|
|
|
2020-07-06 15:31:23 +00:00
|
|
|
Route::post("/posts/create", Box::new(posts_controller::create_post)),
|
|
|
|
|
2020-07-09 07:10:42 +00:00
|
|
|
Route::post("/posts/set_visibility_level", Box::new(posts_controller::set_visibility_level)),
|
|
|
|
|
2020-07-09 07:27:47 +00:00
|
|
|
Route::post("/posts/update_content", Box::new(posts_controller::update_content)),
|
|
|
|
|
2020-07-09 07:32:45 +00:00
|
|
|
Route::post("/posts/delete", Box::new(posts_controller::delete)),
|
|
|
|
|
2020-07-09 11:26:39 +00:00
|
|
|
Route::post("/posts/getAvailableTargets", Box::new(posts_controller::get_targets)),
|
|
|
|
|
2020-06-23 17:04:32 +00:00
|
|
|
|
2020-07-10 06:21:40 +00:00
|
|
|
|
|
|
|
// Comments controller
|
|
|
|
Route::post("/comments/create", Box::new(comments_controller::create)),
|
|
|
|
|
2020-07-10 06:45:53 +00:00
|
|
|
Route::post("/comments/get_single", Box::new(comments_controller::get_single)),
|
|
|
|
|
2020-07-10 07:02:16 +00:00
|
|
|
Route::post("/comments/edit", Box::new(comments_controller::edit)),
|
|
|
|
|
|
|
|
Route::post("/comments/delete", Box::new(comments_controller::delete)),
|
2020-07-10 06:57:46 +00:00
|
|
|
|
2020-07-10 06:21:40 +00:00
|
|
|
|
2020-07-10 08:24:39 +00:00
|
|
|
// Likes controller
|
|
|
|
Route::post("/likes/update", Box::new(likes_controller::update)),
|
|
|
|
|
2020-07-10 09:20:11 +00:00
|
|
|
|
2020-07-10 08:53:37 +00:00
|
|
|
// Surveys controller
|
|
|
|
Route::post("/surveys/get_info", Box::new(surveys_controller::get_info_single)),
|
|
|
|
|
2020-07-10 09:14:59 +00:00
|
|
|
Route::post("/surveys/send_response", Box::new(surveys_controller::send_response)),
|
|
|
|
|
2020-07-10 09:20:11 +00:00
|
|
|
Route::post("/surveys/cancel_response", Box::new(surveys_controller::cancel_response)),
|
|
|
|
|
2020-07-10 09:59:18 +00:00
|
|
|
Route::post("/surveys/create_new_choice", Box::new(surveys_controller::create_new_choice)),
|
|
|
|
|
|
|
|
|
2020-07-10 06:21:40 +00:00
|
|
|
|
2020-07-08 11:45:01 +00:00
|
|
|
// Movies controller
|
|
|
|
Route::post("/movies/get_list", Box::new(movies_controller::get_list)),
|
|
|
|
|
2020-07-08 11:46:54 +00:00
|
|
|
Route::post("/movies/delete", Box::new(movies_controller::delete)),
|
|
|
|
|
2020-07-08 11:45:01 +00:00
|
|
|
|
2020-06-01 15:17:18 +00:00
|
|
|
// Virtual directory controller
|
|
|
|
Route::post("/user/findbyfolder", Box::new(virtual_directory_controller::find_user)),
|
2020-06-02 11:29:10 +00:00
|
|
|
|
|
|
|
Route::post("/virtualDirectory/find", Box::new(virtual_directory_controller::find)),
|
2020-05-21 13:28:07 +00:00
|
|
|
]
|
|
|
|
}
|