Refactor struct conversion in create_account() handler

This commit is contained in:
silverpill 2022-02-14 21:36:52 +00:00
parent e756bbacf4
commit d3e3c1eb3e
3 changed files with 11 additions and 17 deletions

View file

@ -38,6 +38,7 @@ pub struct Image {
#[derive(Clone, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct ActorCapabilities {
// Actpr accepts ChatMessage objects
accepts_chat_messages: Option<bool>,
}

View file

@ -15,7 +15,6 @@ use crate::models::users::types::{
validate_local_username,
validate_wallet_address,
User,
UserCreateData,
};
use crate::utils::files::{FileError, save_validated_b64_file, get_file_url};
@ -122,20 +121,6 @@ impl AccountCreateData {
};
Ok(())
}
pub fn into_user_data(
self,
password_hash: String,
private_key_pem: String,
) -> UserCreateData {
UserCreateData {
username: self.username,
password_hash,
private_key_pem,
wallet_address: self.wallet_address,
invite_code: self.invite_code,
}
}
}
#[derive(Deserialize)]

View file

@ -40,6 +40,7 @@ use crate::models::users::queries::{
is_valid_invite_code,
create_user,
};
use crate::models::users::types::UserCreateData;
use crate::utils::crypto::{
hash_password,
generate_private_key,
@ -90,8 +91,15 @@ pub async fn create_account(
let private_key_pem = serialize_private_key(private_key)
.map_err(|_| HttpError::InternalError)?;
let user_data = account_data.into_inner()
.into_user_data(password_hash, private_key_pem);
let AccountCreateData { username, wallet_address, invite_code, .. } =
account_data.into_inner();
let user_data = UserCreateData {
username,
password_hash,
private_key_pem,
wallet_address,
invite_code,
};
let user = match create_user(db_client, user_data).await {
Ok(user) => user,
Err(DatabaseError::AlreadyExists(_)) =>