Skip to content

Commit

Permalink
feat!: letterAddress, birthSurname fields
Browse files Browse the repository at this point in the history
  • Loading branch information
starvy committed Jan 19, 2023
1 parent 29ce461 commit 79d5a29
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 41 deletions.
2 changes: 2 additions & 0 deletions api/src/routes/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,11 @@ mod tests {
\"candidate\": {
\"name\": \"idk\",
\"surname\": \"idk\",
\"birthSurname\": \"surname\",
\"birthplace\": \"Praha 1\",
\"birthdate\": \"2015-09-18\",
\"address\": \"Stefanikova jidelna\",
\"letterAddress\": \"Stefanikova jidelna\",
\"telephone\": \"000111222333\",
\"citizenship\": \"Czech Republic\",
\"email\": \"magor@magor.cz\",
Expand Down
2 changes: 2 additions & 0 deletions core/src/database/mutation/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ impl Mutation {

candidate.name = Set(enc_candidate.name.map(|e| e.into()));
candidate.surname = Set(enc_candidate.surname.map(|e| e.into()));
candidate.birth_surname = Set(enc_candidate.birth_surname.map(|e| e.into()));
candidate.birthplace = Set(enc_candidate.birthplace.map(|e| e.into()));
candidate.birthdate = Set(enc_candidate.birthdate.map(|e| e.into()));
candidate.address = Set(enc_candidate.address.map(|e| e.into()));
candidate.letter_address = Set(enc_candidate.letter_address.map(|e| e.into()));
candidate.telephone = Set(enc_candidate.telephone.map(|e| e.into()));
candidate.citizenship = Set(enc_candidate.citizenship.map(|e| e.into()));
candidate.email = Set(enc_candidate.email.map(|e| e.into()));
Expand Down
2 changes: 2 additions & 0 deletions core/src/models/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ pub struct CreateCandidateResponse {
pub struct CandidateDetails {
pub name: String,
pub surname: String,
pub birth_surname: String,
pub birthplace: String,
pub birthdate: NaiveDate,
pub address: String,
pub letter_address: String,
pub telephone: String,
pub citizenship: String,
pub email: String,
Expand Down
101 changes: 60 additions & 41 deletions core/src/models/candidate_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ pub struct EncryptedString(String);
pub struct EncryptedCandidateDetails {
pub name: Option<EncryptedString>,
pub surname: Option<EncryptedString>,
pub birth_surname: Option<EncryptedString>,
pub birthplace: Option<EncryptedString>,
pub birthdate: Option<EncryptedString>,
pub address: Option<EncryptedString>,
pub letter_address: Option<EncryptedString>,
pub telephone: Option<EncryptedString>,
pub citizenship: Option<EncryptedString>,
pub email: Option<EncryptedString>,
Expand Down Expand Up @@ -128,9 +130,11 @@ impl EncryptedCandidateDetails {
let d = tokio::try_join!(
EncryptedString::new_option(&form.name, recipients),
EncryptedString::new_option(&form.surname, recipients),
EncryptedString::new_option(&form.birth_surname, recipients),
EncryptedString::new_option(&form.birthplace, recipients),
EncryptedString::new_option(&birthdate_str, recipients),
EncryptedString::new_option(&form.address, recipients),
EncryptedString::new_option(&form.letter_address, recipients),
EncryptedString::new_option(&form.telephone, recipients),
EncryptedString::new_option(&form.citizenship, recipients),
EncryptedString::new_option(&form.email, recipients),
Expand All @@ -147,19 +151,21 @@ impl EncryptedCandidateDetails {
EncryptedCandidateDetails {
name: d.0,
surname: d.1,
birthplace: d.2,
birthdate: d.3,
address: d.4,
telephone: d.5,
citizenship: d.6,
email: d.7,
sex: d.8,
personal_id_number: d.9,
school_name: d.10,
health_insurance: d.11,
grades_json: d.12,
first_school: d.13,
second_school: d.14,
birth_surname: d.2,
birthplace: d.3,
birthdate: d.4,
address: d.5,
letter_address: d.6,
telephone: d.7,
citizenship: d.8,
email: d.9,
sex: d.10,
personal_id_number: d.11,
school_name: d.12,
health_insurance: d.13,
grades_json: d.14,
first_school: d.15,
second_school: d.16,
test_language: Some(form.test_language.to_owned()),
}
)
Expand All @@ -169,37 +175,41 @@ impl EncryptedCandidateDetails {
let d = tokio::try_join!(
EncryptedString::decrypt_option(&self.name, priv_key), // 0
EncryptedString::decrypt_option(&self.surname, priv_key), // 1
EncryptedString::decrypt_option(&self.birthplace, priv_key), // 2
EncryptedString::decrypt_option(&self.birthdate, priv_key), // 3
EncryptedString::decrypt_option(&self.address, priv_key), // 4
EncryptedString::decrypt_option(&self.telephone, priv_key), // 5
EncryptedString::decrypt_option(&self.citizenship, priv_key), // 6
EncryptedString::decrypt_option(&self.email, priv_key), // 7
EncryptedString::decrypt_option(&self.sex, priv_key), // 8
EncryptedString::decrypt_option(&self.personal_id_number, priv_key),// 9
EncryptedString::decrypt_option(&self.school_name, priv_key), // 10
EncryptedString::decrypt_option(&self.health_insurance, priv_key), // 11
EncryptedString::decrypt_option(&self.grades_json, priv_key), // 12
EncryptedString::decrypt_option(&self.first_school, priv_key), // 13
EncryptedString::decrypt_option(&self.second_school, priv_key), // 14
EncryptedString::decrypt_option(&self.birth_surname, priv_key), // 2
EncryptedString::decrypt_option(&self.birthplace, priv_key), // 3
EncryptedString::decrypt_option(&self.birthdate, priv_key), // 4
EncryptedString::decrypt_option(&self.address, priv_key), // 5
EncryptedString::decrypt_option(&self.letter_address, priv_key), // 6
EncryptedString::decrypt_option(&self.telephone, priv_key), // 7
EncryptedString::decrypt_option(&self.citizenship, priv_key), // 8
EncryptedString::decrypt_option(&self.email, priv_key), // 9
EncryptedString::decrypt_option(&self.sex, priv_key), // 10
EncryptedString::decrypt_option(&self.personal_id_number, priv_key),// 11
EncryptedString::decrypt_option(&self.school_name, priv_key), // 12
EncryptedString::decrypt_option(&self.health_insurance, priv_key), // 13
EncryptedString::decrypt_option(&self.grades_json, priv_key), // 14
EncryptedString::decrypt_option(&self.first_school, priv_key), // 15
EncryptedString::decrypt_option(&self.second_school, priv_key), // 16
)?;

Ok(CandidateDetails {
name: d.0.unwrap_or_default(),
surname: d.1.unwrap_or_default(),
birthplace: d.2.unwrap_or_default(),
birthdate: parse_naive_date_from_opt_str(d.3, NAIVE_DATE_FMT)?,
address: d.4.unwrap_or_default(),
telephone: d.5.unwrap_or_default(),
citizenship: d.6.unwrap_or_default(),
email: d.7.unwrap_or_default(),
sex: d.8.unwrap_or_default(),
personal_id_number: d.9.unwrap_or_default(),
school_name: d.10.unwrap_or_default(),
health_insurance: d.11.unwrap_or_default(),
grades: GradeList::from_opt_str(d.12).unwrap_or_default(),
first_school: School::from_opt_str(d.13).unwrap_or_default(),
second_school: School::from_opt_str(d.14).unwrap_or_default(),
birth_surname: d.2.unwrap_or_default(),
birthplace: d.3.unwrap_or_default(),
birthdate: parse_naive_date_from_opt_str(d.4, NAIVE_DATE_FMT)?,
address: d.5.unwrap_or_default(),
letter_address: d.6.unwrap_or_default(),
telephone: d.7.unwrap_or_default(),
citizenship: d.8.unwrap_or_default(),
email: d.9.unwrap_or_default(),
sex: d.10.unwrap_or_default(),
personal_id_number: d.11.unwrap_or_default(),
school_name: d.12.unwrap_or_default(),
health_insurance: d.13.unwrap_or_default(),
grades: GradeList::from_opt_str(d.14).unwrap_or_default(),
first_school: School::from_opt_str(d.15).unwrap_or_default(),
second_school: School::from_opt_str(d.16).unwrap_or_default(),
test_language: self.test_language.to_owned().unwrap_or_default().to_string(),
}
)
Expand All @@ -214,8 +224,13 @@ impl EncryptedCandidateDetails {
self.telephone.is_some() &&
self.citizenship.is_some() &&
self.email.is_some() &&
// self.sex.is_some() &&
self.personal_id_number.is_some()
self.personal_id_number.is_some() &&
self.school_name.is_some() &&
self.health_insurance.is_some() &&
self.grades_json.is_some() &&
self.first_school.is_some() &&
self.second_school.is_some()

}
}
impl From<&candidate::Model> for EncryptedCandidateDetails {
Expand All @@ -225,9 +240,11 @@ impl From<&candidate::Model> for EncryptedCandidateDetails {
EncryptedCandidateDetails {
name: EncryptedString::try_from(&candidate.name).ok(),
surname: EncryptedString::try_from(&candidate.surname).ok(),
birth_surname: EncryptedString::try_from(&candidate.birth_surname).ok(),
birthplace: EncryptedString::try_from(&candidate.birthplace).ok(),
birthdate: EncryptedString::try_from(&candidate.birthdate).ok(),
address: EncryptedString::try_from(&candidate.address).ok(),
letter_address: EncryptedString::try_from(&candidate.letter_address).ok(),
telephone: EncryptedString::try_from(&candidate.telephone).ok(),
citizenship: EncryptedString::try_from(&candidate.citizenship).ok(),
email: EncryptedString::try_from(&candidate.email).ok(),
Expand Down Expand Up @@ -377,9 +394,11 @@ pub mod tests {
candidate: CandidateDetails {
name: "name".to_string(),
surname: "surname".to_string(),
birth_surname: "birth_surname".to_string(),
birthplace: "birthplace".to_string(),
birthdate: chrono::NaiveDate::from_ymd_opt(2000, 1, 1).unwrap(),
address: "address".to_string(),
letter_address: "letter_address".to_string(),
telephone: "telephone".to_string(),
citizenship: "citizenship".to_string(),
email: "email".to_string(),
Expand Down
2 changes: 2 additions & 0 deletions core/src/services/parent_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ mod tests {
candidate: CandidateDetails {
name: "name".to_string(),
surname: "surname".to_string(),
birth_surname: "birth_surname".to_string(),
birthplace: "birthplace".to_string(),
birthdate: chrono::NaiveDate::from_ymd_opt(2000, 1, 1).unwrap(),
address: "address".to_string(),
letter_address: "letter_address".to_string(),
telephone: "telephone".to_string(),
citizenship: "citizenship".to_string(),
email: "email".to_string(),
Expand Down
1 change: 1 addition & 0 deletions entity/src/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub struct Model {
pub birthplace: Option<String>,
pub birthdate: Option<String>,
pub address: Option<String>,
pub letter_address: Option<String>,
pub telephone: Option<String>,
pub citizenship: Option<String>,
pub email: Option<String>,
Expand Down
2 changes: 2 additions & 0 deletions migration/src/m20221024_121621_create_candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ impl MigrationTrait for Migration {
.col(ColumnDef::new(Candidate::Birthplace).string())
.col(ColumnDef::new(Candidate::Birthdate).string())
.col(ColumnDef::new(Candidate::Address).string())
.col(ColumnDef::new(Candidate::LetterAddress).string())
.col(ColumnDef::new(Candidate::Telephone).string())
.col(ColumnDef::new(Candidate::Citizenship).string())
.col(ColumnDef::new(Candidate::Email).string())
Expand Down Expand Up @@ -60,6 +61,7 @@ pub enum Candidate {
Birthplace,
Birthdate,
Address,
LetterAddress,
Telephone,
Citizenship,
Email,
Expand Down

0 comments on commit 79d5a29

Please sign in to comment.