Merge branch 'user_changes' into 'main'
User changes See merge request kdeng00/icarus-models!21
This commit is contained in:
14
src/user.rs
14
src/user.rs
@@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
#[serde(skip_serializing_if = "is_zero")]
|
#[serde(skip_serializing_if = "is_id_valid")]
|
||||||
pub id: i32,
|
pub id: i32,
|
||||||
#[serde(skip_serializing_if = "String::is_empty")]
|
#[serde(skip_serializing_if = "String::is_empty")]
|
||||||
pub username: String,
|
pub username: String,
|
||||||
@@ -27,8 +27,8 @@ pub struct User {
|
|||||||
pub last_login: String,
|
pub last_login: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_zero(num: &i32) -> bool {
|
fn is_id_valid(num: &i32) -> bool {
|
||||||
*num == 0
|
*num > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for User {
|
impl Default for User {
|
||||||
@@ -50,7 +50,11 @@ impl Default for User {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl User {
|
impl User {
|
||||||
pub fn to_json(&self) -> Result<String, serde_json::Error> {
|
pub fn to_json(&self, output_pretty: bool) -> Result<String, serde_json::Error> {
|
||||||
return serde_json::to_string_pretty(&self);
|
if output_pretty {
|
||||||
|
return serde_json::to_string_pretty(&self);
|
||||||
|
} else {
|
||||||
|
return serde_json::to_string(&self);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user