Add User constructor
This commit is contained in:
parent
3d537f5987
commit
8da194e8a2
2 changed files with 19 additions and 21 deletions
|
@ -68,13 +68,7 @@ pub async fn get_user_by_id(
|
|||
let row = maybe_row.ok_or(DatabaseError::NotFound("user"))?;
|
||||
let db_user: DbUser = row.try_get("user_account")?;
|
||||
let db_profile: DbActorProfile = row.try_get("actor_profile")?;
|
||||
let user = User {
|
||||
id: db_user.id,
|
||||
wallet_address: db_user.wallet_address,
|
||||
password_hash: db_user.password_hash,
|
||||
private_key: db_user.private_key,
|
||||
profile: db_profile,
|
||||
};
|
||||
let user = User::new(db_user, db_profile);
|
||||
Ok(user)
|
||||
}
|
||||
|
||||
|
@ -93,13 +87,7 @@ pub async fn get_user_by_name(
|
|||
let row = maybe_row.ok_or(DatabaseError::NotFound("user"))?;
|
||||
let db_user: DbUser = row.try_get("user_account")?;
|
||||
let db_profile: DbActorProfile = row.try_get("actor_profile")?;
|
||||
let user = User {
|
||||
id: db_user.id,
|
||||
wallet_address: db_user.wallet_address,
|
||||
password_hash: db_user.password_hash,
|
||||
private_key: db_user.private_key,
|
||||
profile: db_profile,
|
||||
};
|
||||
let user = User::new(db_user, db_profile);
|
||||
Ok(user)
|
||||
}
|
||||
|
||||
|
@ -168,13 +156,7 @@ pub async fn create_user(
|
|||
],
|
||||
).await.map_err(catch_unique_violation("user"))?;
|
||||
let db_user: DbUser = row.try_get("user_account")?;
|
||||
let user = User {
|
||||
id: db_user.id,
|
||||
wallet_address: db_user.wallet_address,
|
||||
password_hash: db_user.password_hash,
|
||||
private_key: db_user.private_key,
|
||||
profile,
|
||||
};
|
||||
let user = User::new(db_user, profile);
|
||||
transaction.commit().await?;
|
||||
Ok(user)
|
||||
}
|
||||
|
|
|
@ -28,6 +28,22 @@ pub struct User {
|
|||
pub profile: DbActorProfile,
|
||||
}
|
||||
|
||||
impl User {
|
||||
pub fn new(
|
||||
db_user: DbUser,
|
||||
db_profile: DbActorProfile,
|
||||
) -> Self {
|
||||
assert_eq!(db_user.id, db_profile.id);
|
||||
Self {
|
||||
id: db_user.id,
|
||||
wallet_address: db_user.wallet_address,
|
||||
password_hash: db_user.password_hash,
|
||||
private_key: db_user.private_key,
|
||||
profile: db_profile,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UserCreateData {
|
||||
pub username: String,
|
||||
|
|
Loading…
Reference in a new issue