mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-27 22:12:25 +00:00
feat: use reference as constructor parameter
This commit is contained in:
parent
6499c8ce96
commit
02303d4b31
5 changed files with 9 additions and 9 deletions
|
|
@ -83,7 +83,7 @@ pub struct EncryptedApplicationDetails {
|
||||||
|
|
||||||
impl EncryptedApplicationDetails {
|
impl EncryptedApplicationDetails {
|
||||||
pub async fn new(
|
pub async fn new(
|
||||||
form: ApplicationDetails,
|
form: &ApplicationDetails,
|
||||||
recipients: Vec<&str>,
|
recipients: Vec<&str>,
|
||||||
) -> Result<EncryptedApplicationDetails, ServiceError> {
|
) -> Result<EncryptedApplicationDetails, ServiceError> {
|
||||||
let birthdate_str = form.birthdate.format(NAIVE_DATE_FMT).to_string();
|
let birthdate_str = form.birthdate.format(NAIVE_DATE_FMT).to_string();
|
||||||
|
|
@ -116,7 +116,7 @@ impl EncryptedApplicationDetails {
|
||||||
email: d.7,
|
email: d.7,
|
||||||
sex: d.8,
|
sex: d.8,
|
||||||
personal_id_number: d.9,
|
personal_id_number: d.9,
|
||||||
study: form.study,
|
study: form.study.clone(),
|
||||||
|
|
||||||
parent_name: d.10,
|
parent_name: d.10,
|
||||||
parent_surname: d.11,
|
parent_surname: d.11,
|
||||||
|
|
@ -296,7 +296,7 @@ pub mod tests {
|
||||||
const PRIVATE_KEY: &str =
|
const PRIVATE_KEY: &str =
|
||||||
"AGE-SECRET-KEY-14QG24502DMUUQDT2SPMX2YXPSES0X8UD6NT0PCTDAT6RH8V5Q3GQGSRXPS";
|
"AGE-SECRET-KEY-14QG24502DMUUQDT2SPMX2YXPSES0X8UD6NT0PCTDAT6RH8V5Q3GQGSRXPS";
|
||||||
let encrypted_details = EncryptedApplicationDetails::new(
|
let encrypted_details = EncryptedApplicationDetails::new(
|
||||||
APPLICATION_DETAILS.lock().unwrap().clone(),
|
&APPLICATION_DETAILS.lock().unwrap().clone(),
|
||||||
vec![PUBLIC_KEY],
|
vec![PUBLIC_KEY],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
@ -329,7 +329,7 @@ pub mod tests {
|
||||||
"AGE-SECRET-KEY-14QG24502DMUUQDT2SPMX2YXPSES0X8UD6NT0PCTDAT6RH8V5Q3GQGSRXPS";
|
"AGE-SECRET-KEY-14QG24502DMUUQDT2SPMX2YXPSES0X8UD6NT0PCTDAT6RH8V5Q3GQGSRXPS";
|
||||||
|
|
||||||
let encrypted_details = EncryptedApplicationDetails::new(
|
let encrypted_details = EncryptedApplicationDetails::new(
|
||||||
APPLICATION_DETAILS.lock().unwrap().clone(),
|
&APPLICATION_DETAILS.lock().unwrap().clone(),
|
||||||
vec![PUBLIC_KEY],
|
vec![PUBLIC_KEY],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,7 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let encrypted_details: EncryptedApplicationDetails = EncryptedApplicationDetails::new(
|
let encrypted_details: EncryptedApplicationDetails = EncryptedApplicationDetails::new(
|
||||||
APPLICATION_DETAILS.lock().unwrap().clone(),
|
&APPLICATION_DETAILS.lock().unwrap().clone(),
|
||||||
vec!["age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5"],
|
vec!["age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5"],
|
||||||
).await.unwrap();
|
).await.unwrap();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ mod tests {
|
||||||
let parent = Mutation::create_parent(&db, APPLICATION_ID).await.unwrap();
|
let parent = Mutation::create_parent(&db, APPLICATION_ID).await.unwrap();
|
||||||
|
|
||||||
let encrypted_details: EncryptedApplicationDetails = EncryptedApplicationDetails::new(
|
let encrypted_details: EncryptedApplicationDetails = EncryptedApplicationDetails::new(
|
||||||
APPLICATION_DETAILS.lock().unwrap().clone(),
|
&APPLICATION_DETAILS.lock().unwrap().clone(),
|
||||||
vec!["age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5"],
|
vec!["age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5"],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ impl ApplicationService {
|
||||||
pub async fn add_all_details(
|
pub async fn add_all_details(
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
application: i32,
|
application: i32,
|
||||||
form: ApplicationDetails,
|
form: &ApplicationDetails,
|
||||||
) -> Result<(candidate::Model, parent::Model), ServiceError> {
|
) -> Result<(candidate::Model, parent::Model), ServiceError> {
|
||||||
let candidate = Query::find_candidate_by_id(db, application)
|
let candidate = Query::find_candidate_by_id(db, application)
|
||||||
.await?
|
.await?
|
||||||
|
|
|
||||||
|
|
@ -125,7 +125,7 @@ impl CandidateService {
|
||||||
let enc_details_opt = EncryptedApplicationDetails::try_from((candidate, parent));
|
let enc_details_opt = EncryptedApplicationDetails::try_from((candidate, parent));
|
||||||
if let Ok(enc_details) = enc_details_opt {
|
if let Ok(enc_details) = enc_details_opt {
|
||||||
let application_details = enc_details.decrypt(admin_private_key).await?;
|
let application_details = enc_details.decrypt(admin_private_key).await?;
|
||||||
ApplicationService::add_all_details(db, id, application_details).await?;
|
ApplicationService::add_all_details(db, id, &application_details).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(new_password_plain)
|
Ok(new_password_plain)
|
||||||
|
|
@ -382,7 +382,7 @@ pub mod tests {
|
||||||
|
|
||||||
let form = APPLICATION_DETAILS.lock().unwrap().clone();
|
let form = APPLICATION_DETAILS.lock().unwrap().clone();
|
||||||
|
|
||||||
ApplicationService::add_all_details(&db, candidate.application, form)
|
ApplicationService::add_all_details(&db, candidate.application, &form)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue