mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-17 05:21:07 +00:00
feat: parents as vector
This commit is contained in:
parent
1467f0b8c6
commit
617cddd698
6 changed files with 32 additions and 54 deletions
|
|
@ -253,12 +253,14 @@ mod tests {
|
|||
\"personalIdNumber\": \"0000000000\",
|
||||
\"study\": \"KB\"
|
||||
},
|
||||
\"parent\": {
|
||||
\"name\": \"maminka\",
|
||||
\"surname\": \"chad\",
|
||||
\"telephone\": \"420111222333\",
|
||||
\"email\": \"maminka@centrum.cz\"
|
||||
}
|
||||
\"parents\": [
|
||||
{
|
||||
\"name\": \"maminka\",
|
||||
\"surname\": \"chad\",
|
||||
\"telephone\": \"420111222333\",
|
||||
\"email\": \"maminka@centrum.cz\"
|
||||
}
|
||||
]
|
||||
}";
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ mod tests {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
Mutation::add_parent_details(&db, parent, encrypted_details.parent)
|
||||
Mutation::add_parent_details(&db, parent, encrypted_details.parents[0].clone())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
|
|
|
|||
|
|
@ -59,32 +59,8 @@ pub struct ParentDetails {
|
|||
pub struct ApplicationDetails {
|
||||
// Candidate
|
||||
pub candidate: CandidateDetails,
|
||||
pub parent: ParentDetails,
|
||||
// pub opt_parent2: Option<ParentDetails>,
|
||||
pub parents: Vec<ParentDetails>,
|
||||
}
|
||||
/* impl ApplicationDetails {
|
||||
pub fn new_one_parent(
|
||||
candidate: CandidateDetails,
|
||||
parent: ParentDetails,
|
||||
) -> Self {
|
||||
Self {
|
||||
candidate,
|
||||
parent,
|
||||
opt_parent2: None,
|
||||
}
|
||||
}
|
||||
pub fn new_two_parents(
|
||||
candidate: CandidateDetails,
|
||||
parent: ParentDetails,
|
||||
opt_parent2: ParentDetails,
|
||||
) -> Self {
|
||||
Self {
|
||||
candidate,
|
||||
parent,
|
||||
opt_parent2: Some(opt_parent2),
|
||||
}
|
||||
}
|
||||
} */
|
||||
|
||||
/// CSV export (admin endpoint)
|
||||
#[derive(FromQueryResult, Serialize, Default)]
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ pub struct EncryptedParentDetails {
|
|||
#[derive(Clone)]
|
||||
pub struct EncryptedApplicationDetails {
|
||||
pub candidate: EncryptedCandidateDetails,
|
||||
pub parent: EncryptedParentDetails,
|
||||
pub parents: Vec<EncryptedParentDetails>,
|
||||
}
|
||||
|
||||
impl EncryptedString {
|
||||
|
|
@ -244,26 +244,26 @@ impl EncryptedApplicationDetails {
|
|||
form: &ApplicationDetails,
|
||||
recipients: Vec<String>,
|
||||
) -> Result<EncryptedApplicationDetails, ServiceError> {
|
||||
let (candidate, parent) = tokio::try_join!(
|
||||
EncryptedCandidateDetails::new(&form.candidate, recipients.clone()),
|
||||
EncryptedParentDetails::new(&form.parent, recipients),
|
||||
)?;
|
||||
let candidate = EncryptedCandidateDetails::new(&form.candidate, recipients.clone()).await?;
|
||||
let parent = EncryptedParentDetails::new(&form.parents[0], recipients.clone()).await?; // TODO async
|
||||
Ok(
|
||||
EncryptedApplicationDetails {
|
||||
candidate,
|
||||
parent,
|
||||
parents: vec![parent],
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
pub async fn decrypt(self, priv_key: String) -> Result<ApplicationDetails, ServiceError> {
|
||||
let (candidate, parent) = tokio::try_join!(
|
||||
self.candidate.decrypt(priv_key.clone()),
|
||||
self.parent.decrypt(priv_key),
|
||||
)?;
|
||||
/* let (candidate, parent) = tokio::try_join!(
|
||||
&self.candidate.decrypt(priv_key.clone()),
|
||||
self.parents[0].decrypt(priv_key),
|
||||
)?; */
|
||||
let candidate = self.candidate.decrypt(priv_key.clone()).await?;
|
||||
let parent = self.parents[0].clone().decrypt(priv_key).await?;
|
||||
Ok(ApplicationDetails {
|
||||
candidate,
|
||||
parent,
|
||||
parents: vec![parent],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -277,7 +277,7 @@ impl TryFrom<(candidate::Model, parent::Model)> for EncryptedApplicationDetails
|
|||
) -> Result<Self, Self::Error> {
|
||||
Ok(EncryptedApplicationDetails {
|
||||
candidate: EncryptedCandidateDetails::try_from(candidate)?,
|
||||
parent: EncryptedParentDetails::try_from(parent)?,
|
||||
parents: vec![EncryptedParentDetails::try_from(parent)?],
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -302,12 +302,12 @@ impl TryFrom<CandidateWithParent> for EncryptedApplicationDetails {
|
|||
personal_id_number: EncryptedString::try_from(cp.personal_identification_number)?,
|
||||
study: cp.study.ok_or(ServiceError::CandidateDetailsNotSet)?,
|
||||
},
|
||||
parent: EncryptedParentDetails {
|
||||
parents: vec![EncryptedParentDetails {
|
||||
name: EncryptedString::try_from(cp.parent_name)?,
|
||||
surname: EncryptedString::try_from(cp.parent_surname)?,
|
||||
telephone: EncryptedString::try_from(cp.parent_telephone)?,
|
||||
email: EncryptedString::try_from(cp.parent_email)?,
|
||||
}
|
||||
}]
|
||||
|
||||
})
|
||||
}
|
||||
|
|
@ -352,12 +352,12 @@ pub mod tests {
|
|||
personal_id_number: "personal_id_number".to_string(),
|
||||
study: "study".to_string(),
|
||||
},
|
||||
parent: ParentDetails {
|
||||
parents: vec![ParentDetails {
|
||||
email: "parent_email".to_string(),
|
||||
name: "parent_name".to_string(),
|
||||
surname: "parent_surname".to_string(),
|
||||
telephone: "parent_telephone".to_string()
|
||||
}
|
||||
}]
|
||||
})
|
||||
);
|
||||
|
||||
|
|
@ -373,10 +373,10 @@ pub mod tests {
|
|||
assert_eq!(details.candidate.sex, "sex");
|
||||
assert_eq!(details.candidate.study, "study");
|
||||
assert_eq!(details.candidate.personal_id_number, "personal_id_number");
|
||||
assert_eq!(details.parent.name, "parent_name");
|
||||
assert_eq!(details.parent.surname, "parent_surname");
|
||||
assert_eq!(details.parent.telephone, "parent_telephone");
|
||||
assert_eq!(details.parent.email, "parent_email");
|
||||
assert_eq!(details.parents[0].name, "parent_name");
|
||||
assert_eq!(details.parents[0].surname, "parent_surname");
|
||||
assert_eq!(details.parents[0].telephone, "parent_telephone");
|
||||
assert_eq!(details.parents[0].email, "parent_email");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ impl ApplicationService {
|
|||
Ok(
|
||||
tokio::try_join!(
|
||||
CandidateService::add_candidate_details(db, candidate, enc_details.candidate),
|
||||
ParentService::add_parent_details(db, parent, enc_details.parent)
|
||||
ParentService::add_parent_details(db, parent, enc_details.parents[0].clone())
|
||||
)?
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ type Row = CandidateWithParent;
|
|||
impl From<(i32, ApplicationDetails)> for Row {
|
||||
fn from((application, d): (i32, ApplicationDetails)) -> Self {
|
||||
let c = d.candidate;
|
||||
let p = d.parent;
|
||||
let p = d.parents[0].clone();
|
||||
Self {
|
||||
application,
|
||||
name: Some(c.name),
|
||||
|
|
|
|||
Loading…
Reference in a new issue