Implement User conversions
This commit is contained in:
parent
35eee117d7
commit
ee5e869442
@ -44,6 +44,17 @@ pub struct NewUser {
|
|||||||
pub password: String,
|
pub password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert a User into a NewUser, omitting the id and created_at fields
|
||||||
|
impl From<User> for NewUser {
|
||||||
|
fn from(user: User) -> NewUser {
|
||||||
|
NewUser {
|
||||||
|
username: user.username,
|
||||||
|
email: user.email,
|
||||||
|
password: user.password,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Model for a "Public User", used for returning user data to the client
|
/// Model for a "Public User", used for returning user data to the client
|
||||||
/// This model omits the password field, so that the hashed password is not sent to the client
|
/// This model omits the password field, so that the hashed password is not sent to the client
|
||||||
#[cfg_attr(feature = "ssr", derive(Queryable, Selectable))]
|
#[cfg_attr(feature = "ssr", derive(Queryable, Selectable))]
|
||||||
@ -60,3 +71,15 @@ pub struct PublicUser {
|
|||||||
/// The time the user was created
|
/// The time the user was created
|
||||||
pub created_at: SystemTime,
|
pub created_at: SystemTime,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Convert a User into a PublicUser, omitting the password field
|
||||||
|
impl From<User> for PublicUser {
|
||||||
|
fn from(user: User) -> PublicUser {
|
||||||
|
PublicUser {
|
||||||
|
id: user.id,
|
||||||
|
username: user.username,
|
||||||
|
email: user.email,
|
||||||
|
created_at: user.created_at,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user