diff --git a/src/api_data/language_settings_api.rs b/src/api_data/language_settings_api.rs new file mode 100644 index 0000000..577bed4 --- /dev/null +++ b/src/api_data/language_settings_api.rs @@ -0,0 +1,21 @@ +//! # Language settings API +//! +//! @author Pierre Hubert + +use serde::Serialize; + +use crate::data::user::User; + +#[derive(Serialize)] +#[allow(non_snake_case)] +pub struct LanguageSettingsAPI { + lang: String, +} + +impl LanguageSettingsAPI { + pub fn new(user: &User) -> LanguageSettingsAPI { + LanguageSettingsAPI { + lang: user.lang.clone() + } + } +} \ No newline at end of file diff --git a/src/api_data/mod.rs b/src/api_data/mod.rs index a84f2d7..9d723e9 100644 --- a/src/api_data/mod.rs +++ b/src/api_data/mod.rs @@ -51,4 +51,5 @@ pub mod account_export_api; pub mod user_like_api; pub mod survey_response_api; pub mod entities_constructor; -pub mod general_settings_api; \ No newline at end of file +pub mod general_settings_api; +pub mod language_settings_api; \ No newline at end of file diff --git a/src/controllers/routes.rs b/src/controllers/routes.rs index c94f02a..76e4ee0 100644 --- a/src/controllers/routes.rs +++ b/src/controllers/routes.rs @@ -96,6 +96,7 @@ pub fn get_routes() -> Vec { Route::post("/settings/get_general", Box::new(settings_controller::get_general)), Route::post("/settings/set_general", Box::new(settings_controller::set_general)), Route::post("/settings/check_user_directory_availability", Box::new(settings_controller::check_virtual_directory)), + Route::post("/settings/get_language", Box::new(settings_controller::get_language)), // Friends controller Route::post("/friends/getList", Box::new(friends_controller::get_list)), diff --git a/src/controllers/settings_controller.rs b/src/controllers/settings_controller.rs index 8c7d905..7f6dfef 100644 --- a/src/controllers/settings_controller.rs +++ b/src/controllers/settings_controller.rs @@ -3,6 +3,7 @@ //! @author Pierre Hubert use crate::api_data::general_settings_api::GeneralSettingsAPI; +use crate::api_data::language_settings_api::LanguageSettingsAPI; use crate::controllers::routes::RequestResult; use crate::data::general_settings::GeneralSettings; use crate::data::http_request_handler::HttpRequestHandler; @@ -55,4 +56,11 @@ pub fn check_virtual_directory(r: &mut HttpRequestHandler) -> RequestResult { r.post_checked_virtual_directory_opt("directory", r.user_id()?.id(), VirtualDirType::USER)?; r.success("The directory is available!") +} + +/// Get the current language of the user +pub fn get_language(r: &mut HttpRequestHandler) -> RequestResult { + let user = user_helper::find_user_by_id(r.user_id_ref()?)?; + + r.set_response(LanguageSettingsAPI::new(&user)) } \ No newline at end of file diff --git a/src/data/user.rs b/src/data/user.rs index 7dc0cc5..e66c200 100644 --- a/src/data/user.rs +++ b/src/data/user.rs @@ -77,6 +77,7 @@ pub struct User { pub allow_posts_from_friends: bool, pub account_creation_time: u64, pub allow_mails: bool, + pub lang: String, pub security_question_1: Option, pub security_answer_1: Option, pub security_question_2: Option, diff --git a/src/helpers/user_helper.rs b/src/helpers/user_helper.rs index b3d9e25..dd32c8a 100644 --- a/src/helpers/user_helper.rs +++ b/src/helpers/user_helper.rs @@ -65,6 +65,7 @@ fn exec_get_user_query(query: database::QueryInfo) -> ResultBoxError { allow_posts_from_friends: res.get_legacy_bool("autoriser_post_amis")?, account_creation_time: res.get_date_as_time("date_creation")?, allow_mails: res.get_legacy_bool("autorise_mail")?, + lang: res.get_str("lang")?, security_question_1: res.get_optional_str("question1")?, security_answer_1: res.get_optional_str("reponse1")?, security_question_2: res.get_optional_str("question2")?,