diff --git a/src/api_data/mod.rs b/src/api_data/mod.rs index faf136d..10e5c8e 100644 --- a/src/api_data/mod.rs +++ b/src/api_data/mod.rs @@ -7,6 +7,7 @@ //! ## Author //! Pierre Hubert +pub mod server_config; pub mod http_error; pub mod login_success; pub mod current_user_id; diff --git a/src/api_data/server_config.rs b/src/api_data/server_config.rs new file mode 100644 index 0000000..b9aced6 --- /dev/null +++ b/src/api_data/server_config.rs @@ -0,0 +1,35 @@ +//! # Server configuration +//! +//! @author Pierre Hubert +use serde::Serialize; +use crate::constants::conservation_policy; + +#[derive(Serialize)] +struct DataConservationPolicy { + min_inactive_account_lifetime: u64, + min_notification_lifetime: u64, + min_comments_lifetime: u64, + min_posts_lifetime: u64, + min_conversation_messages_lifetime: u64, + min_likes_lifetime: u64, +} + +#[derive(Serialize)] +pub struct ServerConfig { + data_conservation_policy: DataConservationPolicy, +} + +impl ServerConfig { + pub fn new() -> Self { + ServerConfig { + data_conservation_policy: DataConservationPolicy { + min_inactive_account_lifetime: conservation_policy::MIN_INACTIVE_ACCOUNT_LIFETIME.as_secs(), + min_notification_lifetime: conservation_policy::MIN_NOTIFICATIONS_LIFETIME.as_secs(), + min_comments_lifetime: conservation_policy::MIN_COMMENTS_LIFETIME.as_secs(), + min_posts_lifetime: conservation_policy::MIN_POSTS_LIFETIME.as_secs(), + min_conversation_messages_lifetime: conservation_policy::MIN_CONVERSATION_MESSAGES_LIFETIME.as_secs(), + min_likes_lifetime: conservation_policy::MIN_LIKES_LIFETIME.as_secs(), + } + } + } +} \ No newline at end of file diff --git a/src/constants.rs b/src/constants.rs index 96f1529..616cf93 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -59,6 +59,29 @@ pub mod database_tables_names { pub const NOTIFICATIONS_TABLE: &str = "comunic_notifications"; } +/// Minimal conversation policy +pub mod conservation_policy { + use std::time::Duration; + + /// Minimum lifetime for inactive account (3 months) + pub const MIN_INACTIVE_ACCOUNT_LIFETIME: Duration = Duration::from_secs(60 * 60 * 24 * 30 * 3); + + /// Minimum lifetime for notifications (7 days) + pub const MIN_NOTIFICATIONS_LIFETIME: Duration = Duration::from_secs(60 * 60 * 24 * 7); + + /// Minimum lifetime for comments (1 month) + pub const MIN_COMMENTS_LIFETIME: Duration = Duration::from_secs(60 * 60 * 24 * 30); + + /// Minimum lifetime for posts (1 month) + pub const MIN_POSTS_LIFETIME: Duration = Duration::from_secs(60 * 60 * 24 * 30); + + /// Minimum conversation messages lifetime (15 days) + pub const MIN_CONVERSATION_MESSAGES_LIFETIME: Duration = Duration::from_secs(60 * 60 * 24 * 15); + + /// Minimum likes lifetime (1 month) + pub const MIN_LIKES_LIFETIME: Duration = Duration::from_secs(60 * 60 * 24 * 30); +} + /// WebSocket access token lifetime, in seconds pub const WS_ACCESS_TOKEN_LIFETIME: u64 = 10; diff --git a/src/controllers/server_controller.rs b/src/controllers/server_controller.rs index 3b5e81b..de8c15f 100644 --- a/src/controllers/server_controller.rs +++ b/src/controllers/server_controller.rs @@ -1,3 +1,4 @@ +use crate::api_data::server_config::ServerConfig; use crate::data::base_request_handler::BaseRequestHandler; use crate::data::http_request_handler::HttpRequestHandler; use crate::routes::RequestResult; @@ -9,4 +10,9 @@ use crate::routes::RequestResult; /// Root server index pub fn main_index(request: &mut HttpRequestHandler) -> RequestResult { request.success("Comunic API server V3. (c) Pierre Hubert 2020") +} + +/// Get server configuration +pub fn get_config(request: &mut HttpRequestHandler) -> RequestResult { + request.set_response(ServerConfig::new()) } \ No newline at end of file diff --git a/src/routes.rs b/src/routes.rs index d654eae..dd7bb83 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -127,6 +127,7 @@ pub fn get_routes() -> Vec { vec![ // Server meta routes Route::get_without_login("/", Box::new(server_controller::main_index)), + Route::post_without_login("/server/config", Box::new(server_controller::get_config)), // Main user WebSocket Route::post("/ws/token", Box::new(user_ws_controller::get_token)),