refactor: remove study field

This commit is contained in:
Sebastian Pravda 2023-01-14 22:08:31 +01:00
parent 0595f3c044
commit 156bd3e739
No known key found for this signature in database
GPG key ID: F3BC84F08EFA3F57
13 changed files with 15 additions and 73 deletions

View file

@ -310,8 +310,7 @@ mod tests {
\"sex\": \"MALE\",
\"personalIdNumber\": \"0101010000\",
\"schoolName\": \"29988383\",
\"healthInsurance\": \"000\",
\"study\": \"KB\"
\"healthInsurance\": \"000\"
},
\"parents\": [
{

View file

@ -54,7 +54,6 @@ impl Mutation {
candidate.personal_identification_number = Set(enc_candidate.personal_id_number.map(|e| e.into()).unwrap_or_default()); // TODO: do not set this here, it is already set in the create_candidate 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.study = Set(enc_candidate.study.map(|e| e.into()));
candidate.encrypted_by_id = Set(Some(encrypted_by_id));
candidate.updated_at = Set(chrono::offset::Local::now().naive_local());
@ -127,6 +126,6 @@ mod tests {
.await
.unwrap().unwrap();
assert!(candidate.study.is_some());
assert!(candidate.name.is_some());
}
}

View file

@ -10,7 +10,6 @@ pub struct ApplicationCandidateJoin {
pub surname: Option<String>,
pub email: Option<String>,
pub telephone: Option<String>,
pub study: Option<String>,
}
use crate::Query;
@ -47,7 +46,6 @@ impl Query {
.column_as(candidate::Column::Surname, "surname")
.column_as(candidate::Column::Email, "email")
.column_as(candidate::Column::Telephone, "telephone")
.column_as(candidate::Column::Study, "study")
.into_model::<ApplicationCandidateJoin>()
.all(db)
.await

View file

@ -44,30 +44,6 @@ impl Query {
.await
}
pub async fn list_candidates_preview(
db: &DbConn,
field_of_study_opt: Option<String>,
page: Option<u64>,
) -> Result<Vec<CandidateResult>, DbErr> {
let select = Candidate::find();
let query = if let Some(study) = field_of_study_opt {
select.filter(candidate::Column::Study.eq(study))
} else {
select
}
.order_by(candidate::Column::Id, Order::Asc)
.into_model::<CandidateResult>();
if let Some(page) = page {
query
.paginate(db, PAGE_SIZE)
.fetch_page(page).await
} else {
query
.all(db).await
}
}
pub async fn list_candidates_full(
db: &DbConn
) -> Result<Vec<candidate::Model>, DbErr> {

View file

@ -14,7 +14,6 @@ pub struct ApplicationResponse {
pub surname: String,
pub email: String,
pub telephone: String,
pub study: String,
}
impl ApplicationResponse {
@ -34,7 +33,6 @@ impl ApplicationResponse {
surname: surname.unwrap_or_default(),
email: email.unwrap_or_default(),
telephone: telephone.unwrap_or_default(),
study: c.study.unwrap_or_default(),
candidate_id: c.candidate_id,
}
)

View file

@ -50,7 +50,6 @@ pub struct CandidateDetails {
pub citizenship: String,
pub email: String,
pub sex: String,
pub study: String,
pub personal_id_number: String,
pub school_name: String,
pub health_insurance: String,

View file

@ -26,7 +26,6 @@ pub struct EncryptedCandidateDetails {
pub personal_id_number: Option<EncryptedString>,
pub school_name: Option<EncryptedString>,
pub health_insurance: Option<EncryptedString>,
pub study: Option<String>,
}
#[derive(Debug, Clone)]
@ -148,7 +147,6 @@ impl EncryptedCandidateDetails {
personal_id_number: d.9,
school_name: d.10,
health_insurance: d.11,
study: Some(form.study.clone()),
}
)
}
@ -182,7 +180,6 @@ impl EncryptedCandidateDetails {
personal_id_number: d.9.unwrap_or_default(),
school_name: d.10.unwrap_or_default(),
health_insurance: d.11.unwrap_or_default(),
study: self.study.clone().unwrap_or_default(),
}
)
}
@ -197,8 +194,7 @@ impl EncryptedCandidateDetails {
self.citizenship.is_some() &&
self.email.is_some() &&
self.sex.is_some() &&
self.personal_id_number.is_some() &&
self.study.is_some()
self.personal_id_number.is_some()
}
}
impl From<&candidate::Model> for EncryptedCandidateDetails {
@ -218,7 +214,6 @@ impl From<&candidate::Model> for EncryptedCandidateDetails {
personal_id_number: Some(EncryptedString::from(candidate.personal_identification_number.to_owned())),
school_name: EncryptedString::try_from(&candidate.school_name).ok(),
health_insurance: EncryptedString::try_from(&candidate.health_insurance).ok(),
study: candidate.study.clone(),
}
}
}
@ -356,7 +351,6 @@ impl TryFrom<Row> 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(),
study: cp.study.ok_or(ServiceError::CandidateDetailsNotSet).ok(),
},
parents: vec![EncryptedParentDetails {
name: EncryptedString::try_from(&cp.parent_name).ok(),
@ -410,7 +404,6 @@ pub mod tests {
personal_id_number: "personal_id_number".to_string(),
school_name: "school_name".to_string(),
health_insurance: "health_insurance".to_string(),
study: "study".to_string(),
},
parents: vec![ParentDetails {
name: "parent_name".to_string(),
@ -431,7 +424,6 @@ pub mod tests {
assert_eq!(details.candidate.citizenship, "citizenship");
assert_eq!(details.candidate.email, "email");
assert_eq!(details.candidate.sex, "sex");
assert_eq!(details.candidate.study, "study");
assert_eq!(details.candidate.personal_id_number, "personal_id_number");
for parent in &details.parents {
assert_eq!(parent.name, "parent_name");

View file

@ -56,32 +56,6 @@ impl CandidateService {
).await?;
Ok(model)
}
pub async fn list_candidates(
private_key: &String,
db: &DbConn,
field_of_study: Option<String>,
page: Option<u64>,
) -> Result<Vec<BaseCandidateResponse>, ServiceError> {
let candidates = Query::list_candidates_preview(
db,
field_of_study,
page
).await?;
futures::future::try_join_all(
candidates
.iter()
.map(|c| async move {
BaseCandidateResponse::from_encrypted(
private_key,
c.clone(),
PortfolioService::get_submission_progress(c.application).await.ok()
).await
})
).await
}
}
#[cfg(test)]

View file

@ -71,7 +71,6 @@ mod tests {
personal_id_number: "personal_id_number".to_string(),
school_name: "school_name".to_string(),
health_insurance: "health_insurance".to_string(),
study: "study".to_string(),
},
parents: vec![ParentDetails {
name: "parent_name".to_string(),

View file

@ -15,7 +15,7 @@ impl From<(i32, ApplicationDetails)> for Row {
citizenship: Some(c.citizenship),
email: Some(c.email),
sex: Some(c.sex),
study: Some(c.study),
study: Some("TODO".to_string()),
health_insurance: Some(c.health_insurance),
school_name: Some(c.school_name),
personal_identification_number: Some(c.personal_id_number),

View file

@ -17,7 +17,6 @@ pub struct Model {
pub citizenship: Option<String>,
pub email: Option<String>,
pub sex: Option<String>,
pub study: Option<String>,
pub personal_identification_number: String,
pub school_name: Option<String>,
pub health_insurance: Option<String>,

View file

@ -28,7 +28,6 @@ impl MigrationTrait for Migration {
.col(ColumnDef::new(Candidate::Citizenship).string())
.col(ColumnDef::new(Candidate::Email).string())
.col(ColumnDef::new(Candidate::Sex).string())
.col(ColumnDef::new(Candidate::Study).string())
.col(ColumnDef::new(Candidate::PersonalIdentificationNumber).string().not_null())
.col(ColumnDef::new(Candidate::SchoolName).string())
.col(ColumnDef::new(Candidate::HealthInsurance).string())

View file

@ -26,7 +26,17 @@ impl MigrationTrait for Migration {
.col(ColumnDef::new(Application::UpdatedAt).date_time().not_null())
.to_owned(),
)
.await
.await?;
manager.create_index(
Index::create()
.name("idx_application_candidate_id")
.table(Application::Table)
.col(Application::CandidateId)
.to_owned(),
).await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {