mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-26 15:29:21 +00:00
Can get account image settings
This commit is contained in:
parent
6c7fa3afa5
commit
364a98634f
29
src/api_data/account_image_settings_api.rs
Normal file
29
src/api_data/account_image_settings_api.rs
Normal file
@ -0,0 +1,29 @@
|
||||
//! # Account image settings API
|
||||
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::constants::DEFAULT_ACCOUNT_IMAGE;
|
||||
use crate::data::user::User;
|
||||
use crate::utils::user_data_utils::user_data_url;
|
||||
|
||||
#[derive(Serialize)]
|
||||
#[allow(non_snake_case)]
|
||||
pub struct AccountImageSettingsAPI
|
||||
{
|
||||
has_image: bool,
|
||||
image_url: String,
|
||||
visibility: String,
|
||||
}
|
||||
|
||||
impl AccountImageSettingsAPI {
|
||||
pub fn new(user: &User) -> AccountImageSettingsAPI
|
||||
{
|
||||
AccountImageSettingsAPI
|
||||
{
|
||||
has_image: user.has_account_image(),
|
||||
image_url: user_data_url(user.account_image_path
|
||||
.as_ref().unwrap_or(&DEFAULT_ACCOUNT_IMAGE.to_string())),
|
||||
visibility: user.account_image_visibility.to_api(),
|
||||
}
|
||||
}
|
||||
}
|
@ -54,3 +54,4 @@ pub mod entities_constructor;
|
||||
pub mod general_settings_api;
|
||||
pub mod language_settings_api;
|
||||
pub mod security_settings_api;
|
||||
pub mod account_image_settings_api;
|
@ -102,6 +102,7 @@ pub fn get_routes() -> Vec<Route> {
|
||||
Route::post("/settings/set_security", Box::new(settings_controller::set_security)),
|
||||
Route::post("/settings/check_password", Box::new(settings_controller::check_password)),
|
||||
Route::post("/settings/update_password", Box::new(settings_controller::update_password)),
|
||||
Route::post("/settings/get_account_image", Box::new(settings_controller::get_account_image_settings)),
|
||||
|
||||
|
||||
// Friends controller
|
||||
|
@ -14,6 +14,7 @@ use crate::data::security_settings::{SecurityQuestion, SecuritySettings};
|
||||
use crate::data::user::UserPageStatus;
|
||||
use crate::helpers::{account_helper, user_helper};
|
||||
use crate::helpers::virtual_directory_helper::VirtualDirType;
|
||||
use crate::api_data::account_image_settings_api::AccountImageSettingsAPI;
|
||||
|
||||
/// Get the general settings of the user
|
||||
pub fn get_general(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
@ -135,3 +136,10 @@ pub fn update_password(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
|
||||
r.success("Password updated !")
|
||||
}
|
||||
|
||||
/// Get account image settings
|
||||
pub fn get_account_image_settings(r: &mut HttpRequestHandler) -> RequestResult {
|
||||
let user = user_helper::find_user_by_id(r.user_id_ref()?)?;
|
||||
|
||||
r.set_response(AccountImageSettingsAPI::new(&user))
|
||||
}
|
@ -59,6 +59,16 @@ pub enum AccountImageVisibility {
|
||||
EVERYONE,
|
||||
}
|
||||
|
||||
impl AccountImageVisibility {
|
||||
pub fn to_api(&self) -> String {
|
||||
match self {
|
||||
AccountImageVisibility::FRIENDS => "friends".to_string(),
|
||||
AccountImageVisibility::COMUNIC_USERS => "public".to_string(),
|
||||
AccountImageVisibility::EVERYONE => "open".to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct User {
|
||||
pub id: UserID,
|
||||
|
Loading…
Reference in New Issue
Block a user