From e5e91aff9a702c853447a3641990b4947205fe88 Mon Sep 17 00:00:00 2001 From: Sebastian Pravda Date: Wed, 14 Dec 2022 17:10:00 +0100 Subject: [PATCH] feat: map application details --- core/src/models/candidate_details.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/core/src/models/candidate_details.rs b/core/src/models/candidate_details.rs index acef00c..d620d43 100644 --- a/core/src/models/candidate_details.rs +++ b/core/src/models/candidate_details.rs @@ -245,12 +245,10 @@ impl EncryptedApplicationDetails { recipients: Vec, ) -> Result { let candidate = EncryptedCandidateDetails::new(&form.candidate, &recipients).await?; - let mut enc_parents= vec![]; - for parent in form.parents.iter() { - enc_parents.push( - EncryptedParentDetails::new(parent, &recipients).await? - ); - } + let enc_parents = future::try_join_all( + form.parents.iter() + .map(|d| EncryptedParentDetails::new(d, &recipients)) + ).await?; Ok( EncryptedApplicationDetails { candidate, @@ -282,12 +280,10 @@ impl TryFrom<(candidate::Model, Vec)> for EncryptedApplicationDet fn try_from( (candidate, parents): (candidate::Model, Vec), ) -> Result { - let mut enc_parents = vec![]; - for parent in parents.iter() { - enc_parents.push( - EncryptedParentDetails::try_from(parent.clone())? - ); - } + let enc_parents = parents.iter() + .map(|m| EncryptedParentDetails::try_from(m.clone())) + .collect::, ServiceError>>()?; + Ok(EncryptedApplicationDetails { candidate: EncryptedCandidateDetails::try_from(candidate)?, parents: enc_parents,