mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-24 12:35:31 +00:00
feat: birthdate in candidate details
This commit is contained in:
parent
22ea58d521
commit
3dff252a0a
5 changed files with 36 additions and 18 deletions
|
|
@ -1,8 +1,11 @@
|
||||||
|
use chrono::{NaiveDate};
|
||||||
use entity::candidate;
|
use entity::candidate;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
use crate::{error::ServiceError, crypto};
|
use crate::{error::ServiceError, crypto};
|
||||||
|
|
||||||
|
pub const NAIVE_DATE_FMT: &str = "%Y-%m-%d";
|
||||||
|
|
||||||
pub struct EncryptedString(String);
|
pub struct EncryptedString(String);
|
||||||
|
|
||||||
impl EncryptedString {
|
impl EncryptedString {
|
||||||
|
|
@ -20,7 +23,7 @@ impl EncryptedString {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn to_string(self) -> String {
|
pub fn to_string(self) -> String {
|
||||||
self.0
|
self.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -42,11 +45,22 @@ impl TryFrom<Option<String>> for EncryptedString {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl TryFrom<Option<NaiveDate>> for EncryptedString { // TODO: take a look at this
|
||||||
|
type Error = ServiceError;
|
||||||
|
|
||||||
|
fn try_from(d: Option<NaiveDate>) -> Result<Self, Self::Error> {
|
||||||
|
match d {
|
||||||
|
Some(d) => Ok(Self(d.to_string())),
|
||||||
|
None => Err(ServiceError::CandidateDetailsNotSet),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) struct EncryptedCandidateDetails {
|
pub(crate) struct EncryptedCandidateDetails {
|
||||||
pub name: EncryptedString,
|
pub name: EncryptedString,
|
||||||
pub surname: EncryptedString,
|
pub surname: EncryptedString,
|
||||||
pub birthplace: EncryptedString,
|
pub birthplace: EncryptedString,
|
||||||
// pub birthdate: NaiveDate,
|
pub birthdate: EncryptedString,
|
||||||
pub address: EncryptedString,
|
pub address: EncryptedString,
|
||||||
pub telephone: EncryptedString,
|
pub telephone: EncryptedString,
|
||||||
pub citizenship: EncryptedString,
|
pub citizenship: EncryptedString,
|
||||||
|
|
@ -57,11 +71,12 @@ pub(crate) struct EncryptedCandidateDetails {
|
||||||
|
|
||||||
impl EncryptedCandidateDetails {
|
impl EncryptedCandidateDetails {
|
||||||
pub async fn new(form: CandidateDetails, recipients: Vec<&str>) -> Result<EncryptedCandidateDetails, ServiceError> {
|
pub async fn new(form: CandidateDetails, recipients: Vec<&str>) -> Result<EncryptedCandidateDetails, ServiceError> {
|
||||||
|
let birthdate_str = form.birthdate.format(NAIVE_DATE_FMT).to_string();
|
||||||
let d = tokio::try_join!(
|
let d = tokio::try_join!(
|
||||||
EncryptedString::new(&form.name, &recipients),
|
EncryptedString::new(&form.name, &recipients),
|
||||||
EncryptedString::new(&form.surname, &recipients),
|
EncryptedString::new(&form.surname, &recipients),
|
||||||
EncryptedString::new(&form.birthplace, &recipients),
|
EncryptedString::new(&form.birthplace, &recipients),
|
||||||
EncryptedString::new("&form.birthdate", &recipients), // TODO
|
EncryptedString::new(&birthdate_str, &recipients), // TODO
|
||||||
EncryptedString::new(&form.address, &recipients),
|
EncryptedString::new(&form.address, &recipients),
|
||||||
EncryptedString::new(&form.telephone, &recipients),
|
EncryptedString::new(&form.telephone, &recipients),
|
||||||
EncryptedString::new(&form.citizenship, &recipients),
|
EncryptedString::new(&form.citizenship, &recipients),
|
||||||
|
|
@ -74,7 +89,7 @@ impl EncryptedCandidateDetails {
|
||||||
name: d.0,
|
name: d.0,
|
||||||
surname: d.1,
|
surname: d.1,
|
||||||
birthplace: d.2,
|
birthplace: d.2,
|
||||||
// birthdate: NaiveDate::from_ymd(2000, 1, 1),
|
birthdate: d.3,
|
||||||
address: d.4,
|
address: d.4,
|
||||||
telephone: d.5,
|
telephone: d.5,
|
||||||
citizenship: d.6,
|
citizenship: d.6,
|
||||||
|
|
@ -89,7 +104,7 @@ impl EncryptedCandidateDetails {
|
||||||
self.name.decrypt(&priv_key),
|
self.name.decrypt(&priv_key),
|
||||||
self.surname.decrypt(&priv_key),
|
self.surname.decrypt(&priv_key),
|
||||||
self.birthplace.decrypt(&priv_key),
|
self.birthplace.decrypt(&priv_key),
|
||||||
// self.birthdate.decrypt(&priv_key),
|
self.birthdate.decrypt(&priv_key),
|
||||||
self.address.decrypt(&priv_key),
|
self.address.decrypt(&priv_key),
|
||||||
self.telephone.decrypt(&priv_key),
|
self.telephone.decrypt(&priv_key),
|
||||||
self.citizenship.decrypt(&priv_key),
|
self.citizenship.decrypt(&priv_key),
|
||||||
|
|
@ -102,13 +117,13 @@ impl EncryptedCandidateDetails {
|
||||||
name: d.0,
|
name: d.0,
|
||||||
surname: d.1,
|
surname: d.1,
|
||||||
birthplace: d.2,
|
birthplace: d.2,
|
||||||
// birthdate: NaiveDate::from_ymd(2000, 1, 1), // TODO
|
birthdate: NaiveDate::parse_from_str(&d.3, NAIVE_DATE_FMT).unwrap(), // TODO
|
||||||
address: d.3,
|
address: d.4,
|
||||||
telephone: d.4,
|
telephone: d.5,
|
||||||
citizenship: d.5,
|
citizenship: d.6,
|
||||||
email: d.6,
|
email: d.7,
|
||||||
sex: d.7,
|
sex: d.8,
|
||||||
study: d.8,
|
study: d.9,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -121,7 +136,7 @@ impl TryFrom<candidate::Model> for EncryptedCandidateDetails {
|
||||||
name: EncryptedString::try_from(candidate.name)?,
|
name: EncryptedString::try_from(candidate.name)?,
|
||||||
surname: EncryptedString::try_from(candidate.surname)?,
|
surname: EncryptedString::try_from(candidate.surname)?,
|
||||||
birthplace: EncryptedString::try_from(candidate.birthplace)?,
|
birthplace: EncryptedString::try_from(candidate.birthplace)?,
|
||||||
// birthdate?,
|
birthdate: EncryptedString::try_from(candidate.birthdate)?,
|
||||||
address: EncryptedString::try_from(candidate.address)?,
|
address: EncryptedString::try_from(candidate.address)?,
|
||||||
telephone: EncryptedString::try_from(candidate.telephone)?,
|
telephone: EncryptedString::try_from(candidate.telephone)?,
|
||||||
citizenship: EncryptedString::try_from(candidate.citizenship)?,
|
citizenship: EncryptedString::try_from(candidate.citizenship)?,
|
||||||
|
|
@ -137,7 +152,7 @@ pub struct CandidateDetails {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub surname: String,
|
pub surname: String,
|
||||||
pub birthplace: String,
|
pub birthplace: String,
|
||||||
// pub birthdate: NaiveDate,
|
pub birthdate: NaiveDate, // TODO: User NaiveDate or String?
|
||||||
pub address: String,
|
pub address: String,
|
||||||
pub telephone: String,
|
pub telephone: String,
|
||||||
pub citizenship: String,
|
pub citizenship: String,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{Mutation, candidate_details::EncryptedCandidateDetails};
|
use crate::{Mutation, candidate_details::{EncryptedCandidateDetails}};
|
||||||
|
|
||||||
use ::entity::candidate::{self};
|
use ::entity::candidate::{self};
|
||||||
use sea_orm::{*};
|
use sea_orm::{*};
|
||||||
|
|
@ -35,6 +35,7 @@ impl Mutation {
|
||||||
user.name = Set(Some(enc_details.name.into()));
|
user.name = Set(Some(enc_details.name.into()));
|
||||||
user.surname = Set(Some(enc_details.surname.into()));
|
user.surname = Set(Some(enc_details.surname.into()));
|
||||||
user.birthplace = Set(Some(enc_details.birthplace.into()));
|
user.birthplace = Set(Some(enc_details.birthplace.into()));
|
||||||
|
user.birthdate = Set(Some(enc_details.birthdate.into()));
|
||||||
user.address = Set(Some(enc_details.address.into()));
|
user.address = Set(Some(enc_details.address.into()));
|
||||||
user.telephone = Set(Some(enc_details.telephone.into()));
|
user.telephone = Set(Some(enc_details.telephone.into()));
|
||||||
user.citizenship = Set(Some(enc_details.citizenship.into()));
|
user.citizenship = Set(Some(enc_details.citizenship.into()));
|
||||||
|
|
|
||||||
|
|
@ -293,6 +293,8 @@ mod tests {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
async fn put_user_data(db: &DbConn) -> Model {
|
async fn put_user_data(db: &DbConn) -> Model {
|
||||||
|
use chrono::NaiveDate;
|
||||||
|
|
||||||
let plain_text_password = "test".to_string();
|
let plain_text_password = "test".to_string();
|
||||||
let candidate = CandidateService::create(&db, 103151, &plain_text_password, "".to_string())
|
let candidate = CandidateService::create(&db, 103151, &plain_text_password, "".to_string())
|
||||||
.await
|
.await
|
||||||
|
|
@ -303,7 +305,7 @@ mod tests {
|
||||||
name: "test".to_string(),
|
name: "test".to_string(),
|
||||||
surname: "a".to_string(),
|
surname: "a".to_string(),
|
||||||
birthplace: "b".to_string(),
|
birthplace: "b".to_string(),
|
||||||
// birthdate: NaiveDate::from_ymd(1999, 1, 1),
|
birthdate: NaiveDate::from_ymd(1999, 1, 1),
|
||||||
address: "test".to_string(),
|
address: "test".to_string(),
|
||||||
telephone: "test".to_string(),
|
telephone: "test".to_string(),
|
||||||
citizenship: "test".to_string(),
|
citizenship: "test".to_string(),
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ pub struct Model {
|
||||||
pub surname: Option<String>,
|
pub surname: Option<String>,
|
||||||
pub birth_surname: Option<String>,
|
pub birth_surname: Option<String>,
|
||||||
pub birthplace: Option<String>,
|
pub birthplace: Option<String>,
|
||||||
pub birthdate: Option<Date>,
|
pub birthdate: Option<String>,
|
||||||
pub address: Option<String>,
|
pub address: Option<String>,
|
||||||
pub telephone: Option<String>,
|
pub telephone: Option<String>,
|
||||||
pub citizenship: Option<String>,
|
pub citizenship: Option<String>,
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ impl MigrationTrait for Migration {
|
||||||
.col(ColumnDef::new(Candidate::Surname).string())
|
.col(ColumnDef::new(Candidate::Surname).string())
|
||||||
.col(ColumnDef::new(Candidate::BirthSurname).string())
|
.col(ColumnDef::new(Candidate::BirthSurname).string())
|
||||||
.col(ColumnDef::new(Candidate::Birthplace).string())
|
.col(ColumnDef::new(Candidate::Birthplace).string())
|
||||||
.col(ColumnDef::new(Candidate::Birthdate).date())
|
.col(ColumnDef::new(Candidate::Birthdate).string())
|
||||||
.col(ColumnDef::new(Candidate::Address).string())
|
.col(ColumnDef::new(Candidate::Address).string())
|
||||||
.col(ColumnDef::new(Candidate::Telephone).string())
|
.col(ColumnDef::new(Candidate::Telephone).string())
|
||||||
.col(ColumnDef::new(Candidate::Citizenship).string())
|
.col(ColumnDef::new(Candidate::Citizenship).string())
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue