mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-06 19:40:49 +00:00
refactor: change enc user details struct name
This commit is contained in:
parent
b6783c6de4
commit
ced7569086
2 changed files with 12 additions and 12 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{Mutation, services::candidate_service::EncryptedAddUserData};
|
use crate::{Mutation, services::candidate_service::EncryptedUserDetails};
|
||||||
|
|
||||||
use ::entity::candidate::{self};
|
use ::entity::candidate::{self};
|
||||||
use sea_orm::{*};
|
use sea_orm::{*};
|
||||||
|
|
@ -29,7 +29,7 @@ impl Mutation {
|
||||||
pub async fn add_candidate_details(
|
pub async fn add_candidate_details(
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
user: candidate::Model,
|
user: candidate::Model,
|
||||||
enc_details: EncryptedAddUserData,
|
enc_details: EncryptedUserDetails,
|
||||||
) -> Result<candidate::Model, sea_orm::DbErr> {
|
) -> Result<candidate::Model, sea_orm::DbErr> {
|
||||||
let mut user: candidate::ActiveModel = user.into();
|
let mut user: candidate::ActiveModel = user.into();
|
||||||
user.name = Set(Some(enc_details.name));
|
user.name = Set(Some(enc_details.name));
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ use super::session_service::{AdminUser, SessionService};
|
||||||
|
|
||||||
const FIELD_OF_STUDY_PREFIXES: [&str; 3] = ["101", "102", "103"];
|
const FIELD_OF_STUDY_PREFIXES: [&str; 3] = ["101", "102", "103"];
|
||||||
|
|
||||||
pub(crate) struct EncryptedAddUserData {
|
pub(crate) struct EncryptedUserDetails {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub surname: String,
|
pub surname: String,
|
||||||
pub birthplace: String,
|
pub birthplace: String,
|
||||||
|
|
@ -25,8 +25,8 @@ pub(crate) struct EncryptedAddUserData {
|
||||||
pub study: String,
|
pub study: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EncryptedAddUserData {
|
impl EncryptedUserDetails {
|
||||||
pub async fn encrypt_form(form: UserDetails, recipients: Vec<&str>) -> EncryptedAddUserData {
|
pub async fn encrypt_form(form: UserDetails, recipients: Vec<&str>) -> EncryptedUserDetails {
|
||||||
let (
|
let (
|
||||||
Ok(name),
|
Ok(name),
|
||||||
Ok(surname),
|
Ok(surname),
|
||||||
|
|
@ -53,7 +53,7 @@ impl EncryptedAddUserData {
|
||||||
panic!("Failed to encrypt user details"); // TODO
|
panic!("Failed to encrypt user details"); // TODO
|
||||||
};
|
};
|
||||||
|
|
||||||
EncryptedAddUserData {
|
EncryptedUserDetails {
|
||||||
name,
|
name,
|
||||||
surname,
|
surname,
|
||||||
birthplace,
|
birthplace,
|
||||||
|
|
@ -108,11 +108,11 @@ impl EncryptedAddUserData {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_model(candidate: candidate::Model) -> Result<EncryptedAddUserData, ServiceError> {
|
pub fn from_model(candidate: candidate::Model) -> Result<EncryptedUserDetails, ServiceError> {
|
||||||
let Ok(details) = Self::extract_enc_candidate_details(candidate) else {
|
let Ok(details) = Self::extract_enc_candidate_details(candidate) else {
|
||||||
return Err(ServiceError::CandidateDetailsNotSet);
|
return Err(ServiceError::CandidateDetailsNotSet);
|
||||||
};
|
};
|
||||||
Ok(EncryptedAddUserData {
|
Ok(EncryptedUserDetails {
|
||||||
name: details.name,
|
name: details.name,
|
||||||
surname: details.surname,
|
surname: details.surname,
|
||||||
birthplace: details.birthplace,
|
birthplace: details.birthplace,
|
||||||
|
|
@ -257,7 +257,7 @@ impl CandidateService {
|
||||||
|
|
||||||
recipients.append(&mut admin_public_keys_refrence);
|
recipients.append(&mut admin_public_keys_refrence);
|
||||||
|
|
||||||
let enc_details = EncryptedAddUserData::encrypt_form(form, recipients).await;
|
let enc_details = EncryptedUserDetails::encrypt_form(form, recipients).await;
|
||||||
|
|
||||||
Mutation::add_candidate_details(
|
Mutation::add_candidate_details(
|
||||||
db,
|
db,
|
||||||
|
|
@ -289,7 +289,7 @@ impl CandidateService {
|
||||||
}
|
}
|
||||||
|
|
||||||
let dec_priv_key = crypto::decrypt_password(candidate.private_key.clone(), password).await.ok().unwrap();
|
let dec_priv_key = crypto::decrypt_password(candidate.private_key.clone(), password).await.ok().unwrap();
|
||||||
let enc_details = EncryptedAddUserData::from_model(candidate)?;
|
let enc_details = EncryptedUserDetails::from_model(candidate)?;
|
||||||
|
|
||||||
enc_details.decrypt(dec_priv_key).await
|
enc_details.decrypt(dec_priv_key).await
|
||||||
}
|
}
|
||||||
|
|
@ -331,7 +331,7 @@ mod tests {
|
||||||
|
|
||||||
use crate::{crypto, services::candidate_service::{CandidateService, UserDetails}};
|
use crate::{crypto, services::candidate_service::{CandidateService, UserDetails}};
|
||||||
|
|
||||||
use super::EncryptedAddUserData;
|
use super::EncryptedUserDetails;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_application_id_validation() {
|
async fn test_application_id_validation() {
|
||||||
|
|
@ -438,7 +438,7 @@ mod tests {
|
||||||
let dec_priv_key = crypto::decrypt_password(enc_candidate.private_key.clone(), password)
|
let dec_priv_key = crypto::decrypt_password(enc_candidate.private_key.clone(), password)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let dec_candidate = EncryptedAddUserData::from_model(enc_candidate).unwrap().decrypt(dec_priv_key).await.unwrap();
|
let dec_candidate = EncryptedUserDetails::from_model(enc_candidate).unwrap().decrypt(dec_priv_key).await.unwrap();
|
||||||
|
|
||||||
assert_eq!(dec_candidate.name, "test");
|
assert_eq!(dec_candidate.name, "test");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue