mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-04 02:20:50 +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\",
|
\"personalIdNumber\": \"0000000000\",
|
||||||
\"study\": \"KB\"
|
\"study\": \"KB\"
|
||||||
},
|
},
|
||||||
\"parent\": {
|
\"parents\": [
|
||||||
\"name\": \"maminka\",
|
{
|
||||||
\"surname\": \"chad\",
|
\"name\": \"maminka\",
|
||||||
\"telephone\": \"420111222333\",
|
\"surname\": \"chad\",
|
||||||
\"email\": \"maminka@centrum.cz\"
|
\"telephone\": \"420111222333\",
|
||||||
}
|
\"email\": \"maminka@centrum.cz\"
|
||||||
|
}
|
||||||
|
]
|
||||||
}";
|
}";
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ mod tests {
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Mutation::add_parent_details(&db, parent, encrypted_details.parent)
|
Mutation::add_parent_details(&db, parent, encrypted_details.parents[0].clone())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -59,32 +59,8 @@ pub struct ParentDetails {
|
||||||
pub struct ApplicationDetails {
|
pub struct ApplicationDetails {
|
||||||
// Candidate
|
// Candidate
|
||||||
pub candidate: CandidateDetails,
|
pub candidate: CandidateDetails,
|
||||||
pub parent: ParentDetails,
|
pub parents: Vec<ParentDetails>,
|
||||||
// pub opt_parent2: Option<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)
|
/// CSV export (admin endpoint)
|
||||||
#[derive(FromQueryResult, Serialize, Default)]
|
#[derive(FromQueryResult, Serialize, Default)]
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ pub struct EncryptedParentDetails {
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct EncryptedApplicationDetails {
|
pub struct EncryptedApplicationDetails {
|
||||||
pub candidate: EncryptedCandidateDetails,
|
pub candidate: EncryptedCandidateDetails,
|
||||||
pub parent: EncryptedParentDetails,
|
pub parents: Vec<EncryptedParentDetails>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EncryptedString {
|
impl EncryptedString {
|
||||||
|
|
@ -244,26 +244,26 @@ impl EncryptedApplicationDetails {
|
||||||
form: &ApplicationDetails,
|
form: &ApplicationDetails,
|
||||||
recipients: Vec<String>,
|
recipients: Vec<String>,
|
||||||
) -> Result<EncryptedApplicationDetails, ServiceError> {
|
) -> Result<EncryptedApplicationDetails, ServiceError> {
|
||||||
let (candidate, parent) = tokio::try_join!(
|
let candidate = EncryptedCandidateDetails::new(&form.candidate, recipients.clone()).await?;
|
||||||
EncryptedCandidateDetails::new(&form.candidate, recipients.clone()),
|
let parent = EncryptedParentDetails::new(&form.parents[0], recipients.clone()).await?; // TODO async
|
||||||
EncryptedParentDetails::new(&form.parent, recipients),
|
|
||||||
)?;
|
|
||||||
Ok(
|
Ok(
|
||||||
EncryptedApplicationDetails {
|
EncryptedApplicationDetails {
|
||||||
candidate,
|
candidate,
|
||||||
parent,
|
parents: vec![parent],
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn decrypt(self, priv_key: String) -> Result<ApplicationDetails, ServiceError> {
|
pub async fn decrypt(self, priv_key: String) -> Result<ApplicationDetails, ServiceError> {
|
||||||
let (candidate, parent) = tokio::try_join!(
|
/* let (candidate, parent) = tokio::try_join!(
|
||||||
self.candidate.decrypt(priv_key.clone()),
|
&self.candidate.decrypt(priv_key.clone()),
|
||||||
self.parent.decrypt(priv_key),
|
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 {
|
Ok(ApplicationDetails {
|
||||||
candidate,
|
candidate,
|
||||||
parent,
|
parents: vec![parent],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -277,7 +277,7 @@ impl TryFrom<(candidate::Model, parent::Model)> for EncryptedApplicationDetails
|
||||||
) -> Result<Self, Self::Error> {
|
) -> Result<Self, Self::Error> {
|
||||||
Ok(EncryptedApplicationDetails {
|
Ok(EncryptedApplicationDetails {
|
||||||
candidate: EncryptedCandidateDetails::try_from(candidate)?,
|
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)?,
|
personal_id_number: EncryptedString::try_from(cp.personal_identification_number)?,
|
||||||
study: cp.study.ok_or(ServiceError::CandidateDetailsNotSet)?,
|
study: cp.study.ok_or(ServiceError::CandidateDetailsNotSet)?,
|
||||||
},
|
},
|
||||||
parent: EncryptedParentDetails {
|
parents: vec![EncryptedParentDetails {
|
||||||
name: EncryptedString::try_from(cp.parent_name)?,
|
name: EncryptedString::try_from(cp.parent_name)?,
|
||||||
surname: EncryptedString::try_from(cp.parent_surname)?,
|
surname: EncryptedString::try_from(cp.parent_surname)?,
|
||||||
telephone: EncryptedString::try_from(cp.parent_telephone)?,
|
telephone: EncryptedString::try_from(cp.parent_telephone)?,
|
||||||
email: EncryptedString::try_from(cp.parent_email)?,
|
email: EncryptedString::try_from(cp.parent_email)?,
|
||||||
}
|
}]
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -352,12 +352,12 @@ pub mod tests {
|
||||||
personal_id_number: "personal_id_number".to_string(),
|
personal_id_number: "personal_id_number".to_string(),
|
||||||
study: "study".to_string(),
|
study: "study".to_string(),
|
||||||
},
|
},
|
||||||
parent: ParentDetails {
|
parents: vec![ParentDetails {
|
||||||
email: "parent_email".to_string(),
|
email: "parent_email".to_string(),
|
||||||
name: "parent_name".to_string(),
|
name: "parent_name".to_string(),
|
||||||
surname: "parent_surname".to_string(),
|
surname: "parent_surname".to_string(),
|
||||||
telephone: "parent_telephone".to_string()
|
telephone: "parent_telephone".to_string()
|
||||||
}
|
}]
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
@ -373,10 +373,10 @@ pub mod tests {
|
||||||
assert_eq!(details.candidate.sex, "sex");
|
assert_eq!(details.candidate.sex, "sex");
|
||||||
assert_eq!(details.candidate.study, "study");
|
assert_eq!(details.candidate.study, "study");
|
||||||
assert_eq!(details.candidate.personal_id_number, "personal_id_number");
|
assert_eq!(details.candidate.personal_id_number, "personal_id_number");
|
||||||
assert_eq!(details.parent.name, "parent_name");
|
assert_eq!(details.parents[0].name, "parent_name");
|
||||||
assert_eq!(details.parent.surname, "parent_surname");
|
assert_eq!(details.parents[0].surname, "parent_surname");
|
||||||
assert_eq!(details.parent.telephone, "parent_telephone");
|
assert_eq!(details.parents[0].telephone, "parent_telephone");
|
||||||
assert_eq!(details.parent.email, "parent_email");
|
assert_eq!(details.parents[0].email, "parent_email");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ impl ApplicationService {
|
||||||
Ok(
|
Ok(
|
||||||
tokio::try_join!(
|
tokio::try_join!(
|
||||||
CandidateService::add_candidate_details(db, candidate, enc_details.candidate),
|
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 {
|
impl From<(i32, ApplicationDetails)> for Row {
|
||||||
fn from((application, d): (i32, ApplicationDetails)) -> Self {
|
fn from((application, d): (i32, ApplicationDetails)) -> Self {
|
||||||
let c = d.candidate;
|
let c = d.candidate;
|
||||||
let p = d.parent;
|
let p = d.parents[0].clone();
|
||||||
Self {
|
Self {
|
||||||
application,
|
application,
|
||||||
name: Some(c.name),
|
name: Some(c.name),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue