feat: use reference as constructor parameter

This commit is contained in:
Sebastian Pravda 2022-11-27 11:03:37 +01:00
parent 6499c8ce96
commit 02303d4b31
No known key found for this signature in database
GPG key ID: F3BC84F08EFA3F57
5 changed files with 9 additions and 9 deletions

View file

@ -83,7 +83,7 @@ pub struct EncryptedApplicationDetails {
impl EncryptedApplicationDetails {
pub async fn new(
form: ApplicationDetails,
form: &ApplicationDetails,
recipients: Vec<&str>,
) -> Result<EncryptedApplicationDetails, ServiceError> {
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

View file

@ -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();

View file

@ -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

View file

@ -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?

View file

@ -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()
}