mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-06 11:30:44 +00:00
refactor: rename to aplication details
This commit is contained in:
parent
ef2cca94ea
commit
12d25c9ffc
7 changed files with 29 additions and 29 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use std::net::SocketAddr;
|
use std::net::SocketAddr;
|
||||||
|
|
||||||
use portfolio_core::candidate_details::CandidateDetails;
|
use portfolio_core::candidate_details::ApplicationDetails;
|
||||||
use portfolio_core::services::application_service::ApplicationService;
|
use portfolio_core::services::application_service::ApplicationService;
|
||||||
use portfolio_core::services::candidate_service::{CandidateService};
|
use portfolio_core::services::candidate_service::{CandidateService};
|
||||||
use requests::LoginRequest;
|
use requests::LoginRequest;
|
||||||
|
|
@ -61,7 +61,7 @@ pub async fn whoami(session: CandidateAuth) -> Result<String, Custom<String>> {
|
||||||
#[post("/details", data = "<details>")]
|
#[post("/details", data = "<details>")]
|
||||||
pub async fn fill_details(
|
pub async fn fill_details(
|
||||||
conn: Connection<'_, Db>,
|
conn: Connection<'_, Db>,
|
||||||
details: Json<CandidateDetails>,
|
details: Json<ApplicationDetails>,
|
||||||
session: CandidateAuth,
|
session: CandidateAuth,
|
||||||
) -> Result<String, Custom<String>> {
|
) -> Result<String, Custom<String>> {
|
||||||
let db = conn.into_inner();
|
let db = conn.into_inner();
|
||||||
|
|
@ -87,7 +87,7 @@ pub async fn get_details(
|
||||||
conn: Connection<'_, Db>,
|
conn: Connection<'_, Db>,
|
||||||
password_form: Json<PasswordRequest>,
|
password_form: Json<PasswordRequest>,
|
||||||
session: CandidateAuth,
|
session: CandidateAuth,
|
||||||
) -> Result<Json<CandidateDetails>, Custom<String>> {
|
) -> Result<Json<ApplicationDetails>, Custom<String>> {
|
||||||
let db = conn.into_inner();
|
let db = conn.into_inner();
|
||||||
let candidate: entity::candidate::Model = session.into();
|
let candidate: entity::candidate::Model = session.into();
|
||||||
let password = password_form.password.clone();
|
let password = password_form.password.clone();
|
||||||
|
|
|
||||||
|
|
@ -58,7 +58,7 @@ impl TryFrom<Option<NaiveDate>> for EncryptedString { // TODO: take a look at th
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct EncryptedCandidateDetails {
|
pub struct EncryptedApplicationDetails {
|
||||||
// Candidate
|
// Candidate
|
||||||
pub name: EncryptedString,
|
pub name: EncryptedString,
|
||||||
pub surname: EncryptedString,
|
pub surname: EncryptedString,
|
||||||
|
|
@ -78,8 +78,8 @@ pub struct EncryptedCandidateDetails {
|
||||||
pub parent_email: EncryptedString,
|
pub parent_email: EncryptedString,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EncryptedCandidateDetails {
|
impl EncryptedApplicationDetails {
|
||||||
pub async fn new(form: CandidateDetails, recipients: Vec<&str>) -> Result<EncryptedCandidateDetails, ServiceError> {
|
pub async fn new(form: ApplicationDetails, recipients: Vec<&str>) -> Result<EncryptedApplicationDetails, ServiceError> {
|
||||||
let birthdate_str = form.birthdate.format(NAIVE_DATE_FMT).to_string();
|
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),
|
||||||
|
|
@ -99,7 +99,7 @@ impl EncryptedCandidateDetails {
|
||||||
EncryptedString::new(&form.parent_email, &recipients),
|
EncryptedString::new(&form.parent_email, &recipients),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(EncryptedCandidateDetails {
|
Ok(EncryptedApplicationDetails {
|
||||||
name: d.0,
|
name: d.0,
|
||||||
surname: d.1,
|
surname: d.1,
|
||||||
birthplace: d.2,
|
birthplace: d.2,
|
||||||
|
|
@ -118,7 +118,7 @@ impl EncryptedCandidateDetails {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn decrypt(self, priv_key: String) -> Result<CandidateDetails, ServiceError> {
|
pub async fn decrypt(self, priv_key: String) -> Result<ApplicationDetails, ServiceError> {
|
||||||
let d = tokio::try_join!(
|
let d = tokio::try_join!(
|
||||||
self.name.decrypt(&priv_key), // 0
|
self.name.decrypt(&priv_key), // 0
|
||||||
self.surname.decrypt(&priv_key), // 1
|
self.surname.decrypt(&priv_key), // 1
|
||||||
|
|
@ -137,7 +137,7 @@ impl EncryptedCandidateDetails {
|
||||||
self.parent_email.decrypt(&priv_key),
|
self.parent_email.decrypt(&priv_key),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(CandidateDetails {
|
Ok(ApplicationDetails {
|
||||||
name: d.0,
|
name: d.0,
|
||||||
surname: d.1,
|
surname: d.1,
|
||||||
birthplace: d.2,
|
birthplace: d.2,
|
||||||
|
|
@ -157,11 +157,11 @@ impl EncryptedCandidateDetails {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<(candidate::Model, parent::Model)> for EncryptedCandidateDetails {
|
impl TryFrom<(candidate::Model, parent::Model)> for EncryptedApplicationDetails {
|
||||||
type Error = ServiceError;
|
type Error = ServiceError;
|
||||||
|
|
||||||
fn try_from((candidate, parent): (candidate::Model, parent::Model)) -> Result<Self, Self::Error> {
|
fn try_from((candidate, parent): (candidate::Model, parent::Model)) -> Result<Self, Self::Error> {
|
||||||
Ok(EncryptedCandidateDetails {
|
Ok(EncryptedApplicationDetails {
|
||||||
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)?,
|
||||||
|
|
@ -182,7 +182,7 @@ impl TryFrom<(candidate::Model, parent::Model)> for EncryptedCandidateDetails {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct CandidateDetails {
|
pub struct ApplicationDetails {
|
||||||
// Candidate
|
// Candidate
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub surname: String,
|
pub surname: String,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{Mutation, candidate_details::{EncryptedCandidateDetails}};
|
use crate::{Mutation, candidate_details::{EncryptedApplicationDetails}};
|
||||||
|
|
||||||
use ::entity::candidate::{self};
|
use ::entity::candidate::{self};
|
||||||
use sea_orm::{*};
|
use sea_orm::{*};
|
||||||
|
|
@ -29,7 +29,7 @@ impl Mutation {
|
||||||
pub async fn add_candidate_details(
|
pub async fn add_candidate_details(
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
user: candidate::Model,
|
user: candidate::Model,
|
||||||
enc_details: EncryptedCandidateDetails,
|
enc_details: EncryptedApplicationDetails,
|
||||||
) -> Result<candidate::Model, sea_orm::DbErr> {
|
) -> Result<candidate::Model, sea_orm::DbErr> {
|
||||||
let mut user: candidate::ActiveModel = user.into();
|
let mut user: candidate::ActiveModel = user.into();
|
||||||
user.name = Set(Some(enc_details.name.into()));
|
user.name = Set(Some(enc_details.name.into()));
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{Mutation, candidate_details::EncryptedCandidateDetails};
|
use crate::{Mutation, candidate_details::EncryptedApplicationDetails};
|
||||||
|
|
||||||
use ::entity::parent::{self, Model};
|
use ::entity::parent::{self, Model};
|
||||||
use sea_orm::*;
|
use sea_orm::*;
|
||||||
|
|
@ -18,7 +18,7 @@ impl Mutation {
|
||||||
pub async fn add_parent_details(
|
pub async fn add_parent_details(
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
parent: Model,
|
parent: Model,
|
||||||
enc_details: EncryptedCandidateDetails, // TODO: use seperate struct??
|
enc_details: EncryptedApplicationDetails, // TODO: use seperate struct??
|
||||||
) -> Result<Model, sea_orm::DbErr> {
|
) -> Result<Model, sea_orm::DbErr> {
|
||||||
let mut user: parent::ActiveModel = parent.into();
|
let mut user: parent::ActiveModel = parent.into();
|
||||||
user.name = Set(Some(enc_details.parent_name.into()));
|
user.name = Set(Some(enc_details.parent_name.into()));
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use entity::{candidate, parent};
|
use entity::{candidate, parent};
|
||||||
use sea_orm::DbConn;
|
use sea_orm::DbConn;
|
||||||
|
|
||||||
use crate::{error::ServiceError, candidate_details::{CandidateDetails, EncryptedCandidateDetails}, Query, crypto};
|
use crate::{error::ServiceError, candidate_details::{ApplicationDetails, EncryptedApplicationDetails}, Query, crypto};
|
||||||
|
|
||||||
use super::{parent_service::ParentService, candidate_service::CandidateService};
|
use super::{parent_service::ParentService, candidate_service::CandidateService};
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ impl ApplicationService {
|
||||||
pub async fn add_all_details(
|
pub async fn add_all_details(
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
application: i32,
|
application: i32,
|
||||||
form: CandidateDetails,
|
form: ApplicationDetails,
|
||||||
) -> Result<(candidate::Model, parent::Model), ServiceError> {
|
) -> Result<(candidate::Model, parent::Model), ServiceError> {
|
||||||
let candidate = Query::find_candidate_by_id(db, application)
|
let candidate = Query::find_candidate_by_id(db, application)
|
||||||
.await
|
.await
|
||||||
|
|
@ -47,7 +47,7 @@ impl ApplicationService {
|
||||||
let mut recipients = vec![&*candidate.public_key];
|
let mut recipients = vec![&*candidate.public_key];
|
||||||
recipients.append(&mut admin_public_keys_refrence);
|
recipients.append(&mut admin_public_keys_refrence);
|
||||||
|
|
||||||
let enc_details = EncryptedCandidateDetails::new(form, recipients).await?;
|
let enc_details = EncryptedApplicationDetails::new(form, recipients).await?;
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
(
|
(
|
||||||
|
|
@ -61,7 +61,7 @@ impl ApplicationService {
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
application_id: i32,
|
application_id: i32,
|
||||||
password: String,
|
password: String,
|
||||||
) -> Result<CandidateDetails, ServiceError> {
|
) -> Result<ApplicationDetails, ServiceError> {
|
||||||
let candidate = match Query::find_candidate_by_id(db, application_id).await {
|
let candidate = match Query::find_candidate_by_id(db, application_id).await {
|
||||||
Ok(candidate) => candidate.unwrap(),
|
Ok(candidate) => candidate.unwrap(),
|
||||||
Err(_) => return Err(ServiceError::DbError), // TODO: logging
|
Err(_) => return Err(ServiceError::DbError), // TODO: logging
|
||||||
|
|
@ -81,7 +81,7 @@ impl ApplicationService {
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let enc_details = EncryptedCandidateDetails::try_from((candidate, parent))?;
|
let enc_details = EncryptedApplicationDetails::try_from((candidate, parent))?;
|
||||||
|
|
||||||
enc_details.decrypt(dec_priv_key).await
|
enc_details.decrypt(dec_priv_key).await
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use sea_orm::{prelude::Uuid, DbConn};
|
||||||
use crate::{
|
use crate::{
|
||||||
crypto::{self, hash_password},
|
crypto::{self, hash_password},
|
||||||
error::ServiceError,
|
error::ServiceError,
|
||||||
Mutation, Query, candidate_details::{EncryptedCandidateDetails},
|
Mutation, Query, candidate_details::{EncryptedApplicationDetails},
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{session_service::{AdminUser, SessionService}};
|
use super::{session_service::{AdminUser, SessionService}};
|
||||||
|
|
@ -68,7 +68,7 @@ impl CandidateService {
|
||||||
pub(in crate::services) async fn add_candidate_details(
|
pub(in crate::services) async fn add_candidate_details(
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
candidate: candidate::Model,
|
candidate: candidate::Model,
|
||||||
enc_details: EncryptedCandidateDetails,
|
enc_details: EncryptedApplicationDetails,
|
||||||
) -> Result<entity::candidate::Model, ServiceError> {
|
) -> Result<entity::candidate::Model, ServiceError> {
|
||||||
Mutation::add_candidate_details(db, candidate, enc_details.clone())
|
Mutation::add_candidate_details(db, candidate, enc_details.clone())
|
||||||
.await
|
.await
|
||||||
|
|
@ -173,12 +173,12 @@ mod tests {
|
||||||
services::candidate_service::{CandidateService}, Mutation,
|
services::candidate_service::{CandidateService}, Mutation,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::EncryptedCandidateDetails;
|
use super::EncryptedApplicationDetails;
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use entity::{parent, candidate};
|
use entity::{parent, candidate};
|
||||||
|
|
||||||
use crate::services::application_service::ApplicationService;
|
use crate::services::application_service::ApplicationService;
|
||||||
use crate::candidate_details::CandidateDetails;
|
use crate::candidate_details::ApplicationDetails;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_application_id_validation() {
|
async fn test_application_id_validation() {
|
||||||
|
|
@ -259,7 +259,7 @@ mod tests {
|
||||||
.ok()
|
.ok()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let form = CandidateDetails {
|
let form = ApplicationDetails {
|
||||||
name: "test".to_string(),
|
name: "test".to_string(),
|
||||||
surname: "aaa".to_string(),
|
surname: "aaa".to_string(),
|
||||||
birthplace: "b".to_string(),
|
birthplace: "b".to_string(),
|
||||||
|
|
@ -299,7 +299,7 @@ mod tests {
|
||||||
let dec_priv_key = crypto::decrypt_password(enc_candidate.private_key.clone(), password)
|
let dec_priv_key = crypto::decrypt_password(enc_candidate.private_key.clone(), password)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let enc_details = EncryptedCandidateDetails::try_from((enc_candidate, enc_parent)).ok().unwrap();
|
let enc_details = EncryptedApplicationDetails::try_from((enc_candidate, enc_parent)).ok().unwrap();
|
||||||
let dec_details = enc_details.decrypt(dec_priv_key).await.ok().unwrap();
|
let dec_details = enc_details.decrypt(dec_priv_key).await.ok().unwrap();
|
||||||
|
|
||||||
assert_eq!(dec_details.name, "test"); // TODO: test every element
|
assert_eq!(dec_details.name, "test"); // TODO: test every element
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use entity::{parent};
|
use entity::{parent};
|
||||||
use sea_orm::DbConn;
|
use sea_orm::DbConn;
|
||||||
|
|
||||||
use crate::{error::ServiceError, Mutation, candidate_details::EncryptedCandidateDetails};
|
use crate::{error::ServiceError, Mutation, candidate_details::EncryptedApplicationDetails};
|
||||||
|
|
||||||
pub struct ParentService;
|
pub struct ParentService;
|
||||||
|
|
||||||
|
|
@ -20,7 +20,7 @@ impl ParentService {
|
||||||
pub async fn add_parent_details(
|
pub async fn add_parent_details(
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
parent: parent::Model,
|
parent: parent::Model,
|
||||||
enc_details: EncryptedCandidateDetails,
|
enc_details: EncryptedApplicationDetails,
|
||||||
) -> Result<parent::Model, ServiceError> {
|
) -> Result<parent::Model, ServiceError> {
|
||||||
let parent = Mutation::add_parent_details(db, parent, enc_details)
|
let parent = Mutation::add_parent_details(db, parent, enc_details)
|
||||||
.await
|
.await
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue