mirror of
https://gitlab.com/comunic/comunicapiv3
synced 2024-11-22 21:39:21 +00:00
Improve code readability
This commit is contained in:
parent
70d5b50f4c
commit
9271623fd6
@ -18,7 +18,7 @@ pub struct DataConservationSettingsAPI {
|
|||||||
impl DataConservationSettingsAPI {
|
impl DataConservationSettingsAPI {
|
||||||
pub fn new(user: &User) -> Self {
|
pub fn new(user: &User) -> Self {
|
||||||
Self {
|
Self {
|
||||||
inactive_account_lifetime: user.delete_account_after.clone(),
|
inactive_account_lifetime: user.delete_account_after,
|
||||||
notification_lifetime: user.delete_notifications_after,
|
notification_lifetime: user.delete_notifications_after,
|
||||||
comments_lifetime: user.delete_comments_after,
|
comments_lifetime: user.delete_comments_after,
|
||||||
posts_lifetime: user.delete_posts_after,
|
posts_lifetime: user.delete_posts_after,
|
||||||
|
@ -9,7 +9,7 @@ pub trait EntitiesConstructor {
|
|||||||
fn new(i: &Self::Item) -> Self;
|
fn new(i: &Self::Item) -> Self;
|
||||||
|
|
||||||
/// Parse a list of it
|
/// Parse a list of it
|
||||||
fn for_list(l: &Vec<Self::Item>) -> Vec<Self>
|
fn for_list(l: &[Self::Item]) -> Vec<Self>
|
||||||
where Self: std::marker::Sized {
|
where Self: std::marker::Sized {
|
||||||
l.iter().map(Self::new).collect()
|
l.iter().map(Self::new).collect()
|
||||||
}
|
}
|
||||||
|
@ -40,9 +40,9 @@ impl GeneralSettingsAPI {
|
|||||||
allow_comunic_mails: user.allow_mails,
|
allow_comunic_mails: user.allow_mails,
|
||||||
public_friends_list: user.public_friends_list,
|
public_friends_list: user.public_friends_list,
|
||||||
public_email: user.is_email_public,
|
public_email: user.is_email_public,
|
||||||
virtual_directory: user.virtual_directory.clone().unwrap_or(String::new()),
|
virtual_directory: user.virtual_directory.clone().unwrap_or_default(),
|
||||||
personnal_website: user.personal_website.clone().unwrap_or(String::new()),
|
personnal_website: user.personal_website.clone().unwrap_or_default(),
|
||||||
publicNote: user.public_note.clone().unwrap_or(String::new()),
|
publicNote: user.public_note.clone().unwrap_or_default(),
|
||||||
location: user.location.clone(),
|
location: user.location.clone(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,10 @@ impl SecuritySettingsAPI {
|
|||||||
pub fn new(user: &User) -> SecuritySettingsAPI {
|
pub fn new(user: &User) -> SecuritySettingsAPI {
|
||||||
SecuritySettingsAPI {
|
SecuritySettingsAPI {
|
||||||
id: user.id.id(),
|
id: user.id.id(),
|
||||||
security_question_1: user.security_question_1.clone().unwrap_or(String::new()),
|
security_question_1: user.security_question_1.clone().unwrap_or_default(),
|
||||||
security_answer_1: user.security_answer_1.clone().unwrap_or(String::new()),
|
security_answer_1: user.security_answer_1.clone().unwrap_or_default(),
|
||||||
security_question_2: user.security_question_2.clone().unwrap_or(String::new()),
|
security_question_2: user.security_question_2.clone().unwrap_or_default(),
|
||||||
security_answer_2: user.security_answer_2.clone().unwrap_or(String::new()),
|
security_answer_2: user.security_answer_2.clone().unwrap_or_default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -27,7 +27,7 @@ impl UserLikeAPI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn for_list(l: &Vec<UserLike>) -> Vec<Self> {
|
pub fn for_list(l: &[UserLike]) -> Vec<Self> {
|
||||||
l.iter().map(Self::new).collect()
|
l.iter().map(Self::new).collect()
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -28,7 +28,7 @@ pub fn time() -> u64 {
|
|||||||
pub fn time_to_mysql_date(time: u64) -> String {
|
pub fn time_to_mysql_date(time: u64) -> String {
|
||||||
let utc = Utc.timestamp(time as i64, 0);
|
let utc = Utc.timestamp(time as i64, 0);
|
||||||
let str = utc.to_rfc3339();
|
let str = utc.to_rfc3339();
|
||||||
(&str[..19]).replace("T", " ")
|
(&str[..19]).replace('T', " ")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get current Mysql formatted date
|
/// Get current Mysql formatted date
|
||||||
|
@ -48,7 +48,7 @@ pub fn prepare_file_creation(user_id: &UserID, folder: &str) -> ResultBoxError<P
|
|||||||
|
|
||||||
/// Generate a new file name to store user data
|
/// Generate a new file name to store user data
|
||||||
pub fn generate_new_user_data_file_name(dir: &Path, ext: &str) -> ResultBoxError<PathBuf> {
|
pub fn generate_new_user_data_file_name(dir: &Path, ext: &str) -> ResultBoxError<PathBuf> {
|
||||||
let sys_dir = user_data_path(&dir);
|
let sys_dir = user_data_path(dir);
|
||||||
|
|
||||||
if !sys_dir.exists() {
|
if !sys_dir.exists() {
|
||||||
return Err(ExecError::boxed_string(format!("Directory {:?} does not exists!", dir)));
|
return Err(ExecError::boxed_string(format!("Directory {:?} does not exists!", dir)));
|
||||||
|
Loading…
Reference in New Issue
Block a user