Browse Source

Add user name to user data in the backend.

Lee Morgan 1 năm trước cách đây
mục cha
commit
63e8bcb9f4
2 tập tin đã thay đổi với 5 bổ sung0 xóa
  1. 1 0
      src/dto/user.rs
  2. 4 0
      src/models/user.rs

+ 1 - 0
src/dto/user.rs

@@ -9,6 +9,7 @@ pub struct LoginInput {
 
 #[derive(Deserialize)]
 pub struct CreateInput {
+    pub name: String,
     pub email: String,
     pub password_hash: String,
     pub password_salt: String,

+ 4 - 0
src/models/user.rs

@@ -10,6 +10,7 @@ use crate::dto::user::CreateInput;
 pub struct User {
     #[serde(rename = "_id")]
     pub id: ObjectId,
+    pub name: String,
     pub email: String,
     pub password_hash: String,
     pub password_salt: String,
@@ -20,6 +21,7 @@ pub struct User {
 #[derive(Serialize)]
 pub struct ResponseUser {
     id: String,
+    name: String,
     email: String,
     encryption_salt: String,
     created_at: i64,
@@ -30,6 +32,7 @@ impl User {
     pub async fn insert(collection: &Collection<User>, input: CreateInput) -> Result<(), Error> {
         let user = User {
             id: ObjectId::new(),
+            name: input.name,
             email: input.email,
             password_hash: input.password_hash,
             password_salt: input.password_salt,
@@ -62,6 +65,7 @@ impl User {
     pub fn response(self, accounts: Option<Vec<ResponseAccount>>) -> ResponseUser {
         ResponseUser {
             id: self.id.to_string(),
+            name: self.name.to_string(),
             email: self.email.clone(),
             encryption_salt: self.encryption_salt.clone(),
             created_at: self.created_at.timestamp_millis(),