mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-12-27 05:58:51 +00:00
Can get language settings
This commit is contained in:
parent
4cbf57d369
commit
5a1093b33a
21
src/api_data/language_settings_api.rs
Normal file
21
src/api_data/language_settings_api.rs
Normal file
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
@ -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;
|
||||
pub mod general_settings_api;
|
||||
pub mod language_settings_api;
|
@ -96,6 +96,7 @@ pub fn get_routes() -> Vec<Route> {
|
||||
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)),
|
||||
|
@ -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))
|
||||
}
|
@ -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<String>,
|
||||
pub security_answer_1: Option<String>,
|
||||
pub security_question_2: Option<String>,
|
||||
|
@ -65,6 +65,7 @@ fn exec_get_user_query(query: database::QueryInfo) -> ResultBoxError<User> {
|
||||
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")?,
|
||||
|
Loading…
Reference in New Issue
Block a user