Refactor struct conversion in create_account() handler
This commit is contained in:
parent
e756bbacf4
commit
d3e3c1eb3e
3 changed files with 11 additions and 17 deletions
|
@ -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>,
|
||||
}
|
||||
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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(_)) =>
|
||||
|
|
Loading…
Reference in a new issue