mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-18 05:51:17 +00:00
feat: do not encrypt field of study; list candidates filtering
This commit is contained in:
parent
315966acba
commit
d8a269edd3
5 changed files with 29 additions and 20 deletions
|
|
@ -95,6 +95,12 @@ pub async fn list_candidates(
|
|||
) -> Result<Json<Vec<CandidateResponse>>, Custom<String>> {
|
||||
let db = conn.into_inner();
|
||||
let private_key = session.get_private_key();
|
||||
if let Some(field) = field.clone() {
|
||||
if !(field == "KB".to_string() || field == "IT".to_string() || field == "G") {
|
||||
return Err(Custom(Status::BadRequest, "Invalid field of study".to_string()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
let candidates = CandidateService::list_candidates(private_key, db, field)
|
||||
.await
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ pub struct EncryptedApplicationDetails {
|
|||
pub citizenship: EncryptedString,
|
||||
pub email: EncryptedString,
|
||||
pub sex: EncryptedString,
|
||||
pub study: EncryptedString,
|
||||
pub study: String,
|
||||
|
||||
// Parent
|
||||
pub parent_name: EncryptedString,
|
||||
|
|
@ -95,7 +95,7 @@ impl EncryptedApplicationDetails {
|
|||
EncryptedString::new(&form.citizenship, &recipients),
|
||||
EncryptedString::new(&form.email, &recipients),
|
||||
EncryptedString::new(&form.sex, &recipients),
|
||||
EncryptedString::new(&form.study, &recipients),
|
||||
|
||||
EncryptedString::new(&form.parent_name, &recipients),
|
||||
EncryptedString::new(&form.parent_surname, &recipients),
|
||||
EncryptedString::new(&form.parent_telephone, &recipients),
|
||||
|
|
@ -112,12 +112,12 @@ impl EncryptedApplicationDetails {
|
|||
citizenship: d.6,
|
||||
email: d.7,
|
||||
sex: d.8,
|
||||
study: d.9,
|
||||
study: form.study,
|
||||
|
||||
parent_name: d.10,
|
||||
parent_surname: d.11,
|
||||
parent_telephone: d.12,
|
||||
parent_email: d.13,
|
||||
parent_name: d.9,
|
||||
parent_surname: d.10,
|
||||
parent_telephone: d.11,
|
||||
parent_email: d.12,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +132,6 @@ impl EncryptedApplicationDetails {
|
|||
self.citizenship.decrypt(&priv_key), // 6
|
||||
self.email.decrypt(&priv_key), // 7
|
||||
self.sex.decrypt(&priv_key), // 8
|
||||
self.study.decrypt(&priv_key), // 9
|
||||
self.parent_name.decrypt(&priv_key),
|
||||
self.parent_surname.decrypt(&priv_key),
|
||||
self.parent_telephone.decrypt(&priv_key),
|
||||
|
|
@ -149,12 +148,12 @@ impl EncryptedApplicationDetails {
|
|||
citizenship: d.6,
|
||||
email: d.7,
|
||||
sex: d.8,
|
||||
study: d.9,
|
||||
study: self.study,
|
||||
|
||||
parent_name: d.10,
|
||||
parent_surname: d.11,
|
||||
parent_telephone: d.12,
|
||||
parent_email: d.13,
|
||||
parent_name: d.9,
|
||||
parent_surname: d.10,
|
||||
parent_telephone: d.11,
|
||||
parent_email: d.12,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -175,7 +174,7 @@ impl TryFrom<(candidate::Model, parent::Model)> for EncryptedApplicationDetails
|
|||
citizenship: EncryptedString::try_from(candidate.citizenship)?,
|
||||
email: EncryptedString::try_from(candidate.email)?,
|
||||
sex: EncryptedString::try_from(candidate.sex)?,
|
||||
study: EncryptedString::try_from(candidate.study)?,
|
||||
study: candidate.study.ok_or(ServiceError::CandidateDetailsNotSet)?,
|
||||
|
||||
parent_name: EncryptedString::try_from(parent.name)?,
|
||||
parent_surname: EncryptedString::try_from(parent.surname)?,
|
||||
|
|
|
|||
|
|
@ -29,9 +29,14 @@ impl Query {
|
|||
|
||||
pub async fn list_candidates(
|
||||
db: &DbConn,
|
||||
field_of_study: Option<String>,
|
||||
field_of_study_opt: Option<String>,
|
||||
) -> Result<Vec<ApplicationResult>, DbErr> {
|
||||
Candidate::find()
|
||||
let select = Candidate::find();
|
||||
if let Some(study) = field_of_study_opt {
|
||||
select.filter(candidate::Column::Study.eq(study))
|
||||
} else {
|
||||
select
|
||||
}
|
||||
.join(JoinType::InnerJoin, candidate::Relation::Parent.def())
|
||||
.column_as(parent::Column::Name, "parent_name")
|
||||
.column_as(parent::Column::Surname, "parent_surname")
|
||||
|
|
|
|||
|
|
@ -22,13 +22,12 @@ impl CandidateResponse {
|
|||
) -> Result<Self, ServiceError> {
|
||||
let name = decrypt_if_exists(private_key, name_opt).await?;
|
||||
let surname = decrypt_if_exists(private_key, surname_opt).await?;
|
||||
let study = decrypt_if_exists(private_key, study_opt).await?;
|
||||
Ok(
|
||||
Self {
|
||||
application_id,
|
||||
name,
|
||||
application_id,
|
||||
surname,
|
||||
study,
|
||||
study: study_opt.unwrap_or("".to_string()),
|
||||
submitted,
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -147,7 +147,7 @@ impl CandidateService {
|
|||
field_of_study: Option<String>,
|
||||
) -> Result<Vec<CandidateResponse>, ServiceError> {
|
||||
|
||||
let candidates = Query::list_candidates(db, None).await?;
|
||||
let candidates = Query::list_candidates(db, field_of_study).await?;
|
||||
let mut result: Vec<CandidateResponse> = vec![];
|
||||
|
||||
for candidate in candidates {
|
||||
|
|
|
|||
Loading…
Reference in a new issue