mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-20 06:51:10 +00:00
feat!: school order selection
*database* - firstSchool - secondSchool *CandidateDetails* School struct with 'name' & 'field' attributes
This commit is contained in:
parent
4201a84961
commit
8fd8ee6624
9 changed files with 71 additions and 5 deletions
|
|
@ -319,6 +319,8 @@ mod tests {
|
|||
\"schoolName\": \"29988383\",
|
||||
\"healthInsurance\": \"000\",
|
||||
\"grades\": [],
|
||||
\"firstSchool\": {\"name\": \"SSPŠ\", \"field\": \"KB\"},
|
||||
\"secondSchool\": {\"name\": \"SSPŠ\", \"field\": \"IT\"},
|
||||
\"testLanguage\": \"CZ\"
|
||||
},
|
||||
\"parents\": [
|
||||
|
|
|
|||
|
|
@ -54,6 +54,8 @@ impl Mutation {
|
|||
candidate.school_name = Set(enc_candidate.school_name.map(|e| e.into()));
|
||||
candidate.health_insurance = Set(enc_candidate.health_insurance.map(|e| e.into()));
|
||||
candidate.grades_json = Set(enc_candidate.grades_json.map(|e| e.into()));
|
||||
candidate.first_school = Set(enc_candidate.first_school.map(|e| e.into()));
|
||||
candidate.second_school = Set(enc_candidate.second_school.map(|e| e.into()));
|
||||
candidate.test_language = Set(enc_candidate.test_language.map(|s| s));
|
||||
candidate.encrypted_by_id = Set(Some(encrypted_by_id));
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::{
|
|||
error::ServiceError,
|
||||
};
|
||||
|
||||
use super::{candidate_details::{EncryptedString, EncryptedCandidateDetails}, grade::GradeList};
|
||||
use super::{candidate_details::{EncryptedString, EncryptedCandidateDetails}, grade::GradeList, school::School};
|
||||
|
||||
pub enum FieldOfStudy {
|
||||
G,
|
||||
|
|
@ -73,6 +73,8 @@ pub struct CandidateDetails {
|
|||
pub school_name: String,
|
||||
pub health_insurance: String,
|
||||
pub grades: GradeList,
|
||||
pub first_school: School,
|
||||
pub second_school: School,
|
||||
pub test_language: String,
|
||||
}
|
||||
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use futures::future;
|
|||
|
||||
use crate::{crypto, models::candidate::{ApplicationDetails}, error::ServiceError, utils::date::parse_naive_date_from_opt_str};
|
||||
|
||||
use super::{candidate::{CandidateDetails, ParentDetails}, application::ApplicationRow, grade::GradeList};
|
||||
use super::{candidate::{CandidateDetails, ParentDetails}, application::ApplicationRow, grade::GradeList, school::School};
|
||||
|
||||
pub const NAIVE_DATE_FMT: &str = "%Y-%m-%d";
|
||||
|
||||
|
|
@ -27,6 +27,8 @@ pub struct EncryptedCandidateDetails {
|
|||
pub school_name: Option<EncryptedString>,
|
||||
pub health_insurance: Option<EncryptedString>,
|
||||
pub grades_json: Option<EncryptedString>,
|
||||
pub first_school: Option<EncryptedString>,
|
||||
pub second_school: Option<EncryptedString>,
|
||||
pub test_language: Option<String>,
|
||||
}
|
||||
|
||||
|
|
@ -121,6 +123,8 @@ impl EncryptedCandidateDetails {
|
|||
) -> Result<EncryptedCandidateDetails, ServiceError> {
|
||||
let birthdate_str = form.birthdate.format(NAIVE_DATE_FMT).to_string();
|
||||
let grades_str = form.grades.to_string();
|
||||
let (first_school_str, second_school_str) =
|
||||
(form.first_school.to_string(), form.second_school.to_string());
|
||||
let d = tokio::try_join!(
|
||||
EncryptedString::new_option(&form.name, recipients),
|
||||
EncryptedString::new_option(&form.surname, recipients),
|
||||
|
|
@ -135,6 +139,8 @@ impl EncryptedCandidateDetails {
|
|||
EncryptedString::new_option(&form.school_name, recipients),
|
||||
EncryptedString::new_option(&form.health_insurance, recipients),
|
||||
EncryptedString::new_option(&grades_str, recipients),
|
||||
EncryptedString::new_option(&first_school_str, recipients),
|
||||
EncryptedString::new_option(&second_school_str, recipients),
|
||||
)?;
|
||||
|
||||
Ok(
|
||||
|
|
@ -152,6 +158,8 @@ impl EncryptedCandidateDetails {
|
|||
school_name: d.10,
|
||||
health_insurance: d.11,
|
||||
grades_json: d.12,
|
||||
first_school: d.13,
|
||||
second_school: d.14,
|
||||
test_language: Some(form.test_language.to_owned()),
|
||||
}
|
||||
)
|
||||
|
|
@ -172,8 +180,12 @@ impl EncryptedCandidateDetails {
|
|||
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
|
||||
)?;
|
||||
|
||||
println!("d: {:?}", d.12);
|
||||
|
||||
Ok(CandidateDetails {
|
||||
name: d.0.unwrap_or_default(),
|
||||
surname: d.1.unwrap_or_default(),
|
||||
|
|
@ -188,6 +200,8 @@ impl EncryptedCandidateDetails {
|
|||
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(),
|
||||
test_language: self.test_language.to_owned().unwrap_or_default().to_string(),
|
||||
}
|
||||
)
|
||||
|
|
@ -224,6 +238,8 @@ impl From<&candidate::Model> for EncryptedCandidateDetails {
|
|||
school_name: EncryptedString::try_from(&candidate.school_name).ok(),
|
||||
health_insurance: EncryptedString::try_from(&candidate.health_insurance).ok(),
|
||||
grades_json: EncryptedString::try_from(&candidate.grades_json).ok(),
|
||||
first_school: EncryptedString::try_from(&candidate.first_school).ok(),
|
||||
second_school: EncryptedString::try_from(&candidate.second_school).ok(),
|
||||
test_language: candidate.test_language.to_owned(),
|
||||
}
|
||||
}
|
||||
|
|
@ -362,6 +378,8 @@ impl TryFrom<ApplicationRow> for EncryptedApplicationDetails {
|
|||
personal_id_number: EncryptedString::try_from(&cp.personal_identification_number).ok(),
|
||||
school_name: EncryptedString::try_from(&cp.school_name).ok(),
|
||||
health_insurance: EncryptedString::try_from(&cp.health_insurance).ok(),
|
||||
first_school: None, // TODO
|
||||
second_school: None, // TODO
|
||||
grades_json: None, // TODO
|
||||
test_language: None // TODO
|
||||
},
|
||||
|
|
@ -395,7 +413,7 @@ pub mod tests {
|
|||
use once_cell::sync::Lazy;
|
||||
use sea_orm::{DbConn, Set, ActiveModelTrait};
|
||||
|
||||
use crate::{crypto, models::{candidate::{CandidateDetails, ParentDetails}, grade::GradeList}, utils::db::get_memory_sqlite_connection, services::candidate_service::tests::put_user_data};
|
||||
use crate::{crypto, models::{candidate::{CandidateDetails, ParentDetails}, grade::GradeList, school::School}, utils::db::get_memory_sqlite_connection, services::candidate_service::tests::put_user_data};
|
||||
|
||||
use super::{ApplicationDetails, EncryptedApplicationDetails, EncryptedString};
|
||||
|
||||
|
|
@ -418,6 +436,8 @@ pub mod tests {
|
|||
school_name: "school_name".to_string(),
|
||||
health_insurance: "health_insurance".to_string(),
|
||||
grades: GradeList::from(vec![]),
|
||||
first_school: School::from_opt_str(Some("{\"name\": \"SSPS\", \"field\": \"KB\"}".to_string())).unwrap(),
|
||||
second_school: School::from_opt_str(Some("{\"name\": \"SSPS\", \"field\": \"IT\"}".to_string())).unwrap(),
|
||||
test_language: "test_language".to_string(),
|
||||
},
|
||||
parents: vec![ParentDetails {
|
||||
|
|
|
|||
|
|
@ -2,4 +2,5 @@ pub mod candidate_details;
|
|||
pub mod candidate;
|
||||
pub mod auth;
|
||||
pub mod application;
|
||||
pub mod grade;
|
||||
pub mod grade;
|
||||
pub mod school;
|
||||
31
core/src/models/school.rs
Normal file
31
core/src/models/school.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct School {
|
||||
name: String,
|
||||
field: String,
|
||||
}
|
||||
|
||||
impl School {
|
||||
pub fn from_opt_str(school: Option<String>) -> Option<Self> {
|
||||
println!("School: {:?}", school);
|
||||
school.map(
|
||||
|school| serde_json::from_str(&school).unwrap() // TODO: handle error
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl ToString for School {
|
||||
fn to_string(&self) -> String {
|
||||
serde_json::to_string(&self).unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for School {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
name: String::default(),
|
||||
field: String::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -54,7 +54,7 @@ mod tests {
|
|||
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::{utils::db::get_memory_sqlite_connection, models::{candidate::{ParentDetails, ApplicationDetails, CandidateDetails}, candidate_details::EncryptedApplicationDetails, grade::GradeList}, services::{candidate_service::{CandidateService, tests::put_user_data}, application_service::ApplicationService, parent_service::ParentService}, crypto};
|
||||
use crate::{utils::db::get_memory_sqlite_connection, models::{candidate::{ParentDetails, ApplicationDetails, CandidateDetails}, candidate_details::EncryptedApplicationDetails, grade::GradeList, school::School}, services::{candidate_service::{CandidateService, tests::put_user_data}, application_service::ApplicationService, parent_service::ParentService}, crypto};
|
||||
|
||||
pub static APPLICATION_DETAILS_TWO_PARENTS: Lazy<Mutex<ApplicationDetails>> = Lazy::new(||
|
||||
Mutex::new(ApplicationDetails {
|
||||
|
|
@ -72,6 +72,8 @@ mod tests {
|
|||
school_name: "school_name".to_string(),
|
||||
health_insurance: "health_insurance".to_string(),
|
||||
grades: GradeList::from(vec![]),
|
||||
first_school: School::from_opt_str(Some("{\"name\": \"SSPS\", \"field\": \"KB\"}".to_string())).unwrap(),
|
||||
second_school: School::from_opt_str(Some("{\"name\": \"SSPS\", \"field\": \"IT\"}".to_string())).unwrap(),
|
||||
test_language: "test_language".to_string(),
|
||||
},
|
||||
parents: vec![ParentDetails {
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ pub struct Model {
|
|||
pub school_name: Option<String>,
|
||||
pub health_insurance: Option<String>,
|
||||
pub grades_json: Option<String>,
|
||||
pub first_school: Option<String>,
|
||||
pub second_school: Option<String>,
|
||||
pub test_language: Option<String>,
|
||||
pub encrypted_by_id: Option<i32>,
|
||||
pub created_at: DateTime,
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ impl MigrationTrait for Migration {
|
|||
.col(ColumnDef::new(Candidate::SchoolName).string())
|
||||
.col(ColumnDef::new(Candidate::HealthInsurance).string())
|
||||
.col(ColumnDef::new(Candidate::GradesJson).string())
|
||||
.col(ColumnDef::new(Candidate::FirstSchool).string())
|
||||
.col(ColumnDef::new(Candidate::SecondSchool).string())
|
||||
.col(ColumnDef::new(Candidate::TestLanguage).string())
|
||||
.col(ColumnDef::new(Candidate::EncryptedById).integer())
|
||||
.col(ColumnDef::new(Candidate::CreatedAt).date_time().not_null())
|
||||
|
|
@ -66,6 +68,8 @@ pub enum Candidate {
|
|||
SchoolName,
|
||||
HealthInsurance,
|
||||
GradesJson,
|
||||
FirstSchool,
|
||||
SecondSchool,
|
||||
TestLanguage,
|
||||
EncryptedById,
|
||||
CreatedAt,
|
||||
|
|
|
|||
Loading…
Reference in a new issue