From 02303d4b31a1e2ce64d5e0e1ba697e14ce9889dc Mon Sep 17 00:00:00 2001 From: Sebastian Pravda Date: Sun, 27 Nov 2022 11:03:37 +0100 Subject: [PATCH] feat: use reference as constructor parameter --- core/src/candidate_details.rs | 8 ++++---- core/src/database/mutation/candidate.rs | 2 +- core/src/database/mutation/parent.rs | 2 +- core/src/services/application_service.rs | 2 +- core/src/services/candidate_service.rs | 4 ++-- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/core/src/candidate_details.rs b/core/src/candidate_details.rs index d0739dc..f235b08 100644 --- a/core/src/candidate_details.rs +++ b/core/src/candidate_details.rs @@ -83,7 +83,7 @@ pub struct EncryptedApplicationDetails { impl EncryptedApplicationDetails { pub async fn new( - form: ApplicationDetails, + form: &ApplicationDetails, recipients: Vec<&str>, ) -> Result { let birthdate_str = form.birthdate.format(NAIVE_DATE_FMT).to_string(); @@ -116,7 +116,7 @@ impl EncryptedApplicationDetails { email: d.7, sex: d.8, personal_id_number: d.9, - study: form.study, + study: form.study.clone(), parent_name: d.10, parent_surname: d.11, @@ -296,7 +296,7 @@ pub mod tests { const PRIVATE_KEY: &str = "AGE-SECRET-KEY-14QG24502DMUUQDT2SPMX2YXPSES0X8UD6NT0PCTDAT6RH8V5Q3GQGSRXPS"; let encrypted_details = EncryptedApplicationDetails::new( - APPLICATION_DETAILS.lock().unwrap().clone(), + &APPLICATION_DETAILS.lock().unwrap().clone(), vec![PUBLIC_KEY], ) .await @@ -329,7 +329,7 @@ pub mod tests { "AGE-SECRET-KEY-14QG24502DMUUQDT2SPMX2YXPSES0X8UD6NT0PCTDAT6RH8V5Q3GQGSRXPS"; let encrypted_details = EncryptedApplicationDetails::new( - APPLICATION_DETAILS.lock().unwrap().clone(), + &APPLICATION_DETAILS.lock().unwrap().clone(), vec![PUBLIC_KEY], ) .await diff --git a/core/src/database/mutation/candidate.rs b/core/src/database/mutation/candidate.rs index 2de10e1..7921f74 100644 --- a/core/src/database/mutation/candidate.rs +++ b/core/src/database/mutation/candidate.rs @@ -113,7 +113,7 @@ mod tests { .unwrap(); let encrypted_details: EncryptedApplicationDetails = EncryptedApplicationDetails::new( - APPLICATION_DETAILS.lock().unwrap().clone(), + &APPLICATION_DETAILS.lock().unwrap().clone(), vec!["age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5"], ).await.unwrap(); diff --git a/core/src/database/mutation/parent.rs b/core/src/database/mutation/parent.rs index 2b8ed6c..4c49ded 100644 --- a/core/src/database/mutation/parent.rs +++ b/core/src/database/mutation/parent.rs @@ -82,7 +82,7 @@ mod tests { let parent = Mutation::create_parent(&db, APPLICATION_ID).await.unwrap(); let encrypted_details: EncryptedApplicationDetails = EncryptedApplicationDetails::new( - APPLICATION_DETAILS.lock().unwrap().clone(), + &APPLICATION_DETAILS.lock().unwrap().clone(), vec!["age1u889gp407hsz309wn09kxx9anl6uns30m27lfwnctfyq9tq4qpus8tzmq5"], ) .await diff --git a/core/src/services/application_service.rs b/core/src/services/application_service.rs index eec9931..5eedd36 100644 --- a/core/src/services/application_service.rs +++ b/core/src/services/application_service.rs @@ -31,7 +31,7 @@ impl ApplicationService { pub async fn add_all_details( db: &DbConn, application: i32, - form: ApplicationDetails, + form: &ApplicationDetails, ) -> Result<(candidate::Model, parent::Model), ServiceError> { let candidate = Query::find_candidate_by_id(db, application) .await? diff --git a/core/src/services/candidate_service.rs b/core/src/services/candidate_service.rs index 6a86932..d127705 100644 --- a/core/src/services/candidate_service.rs +++ b/core/src/services/candidate_service.rs @@ -125,7 +125,7 @@ impl CandidateService { let enc_details_opt = EncryptedApplicationDetails::try_from((candidate, parent)); if let Ok(enc_details) = enc_details_opt { 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) @@ -382,7 +382,7 @@ pub mod tests { let form = APPLICATION_DETAILS.lock().unwrap().clone(); - ApplicationService::add_all_details(&db, candidate.application, form) + ApplicationService::add_all_details(&db, candidate.application, &form) .await .unwrap() }