use std::error::Error; use crate::controllers::routes::Method::{GET, POST}; use crate::controllers::{server_controller, account_controller}; 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 } } } /// 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)), ] }