diff --git a/api/src/routes/candidate.rs b/api/src/routes/candidate.rs index f4322c5..85486a8 100644 --- a/api/src/routes/candidate.rs +++ b/api/src/routes/candidate.rs @@ -1,6 +1,6 @@ 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::candidate_service::{CandidateService}; use requests::LoginRequest; @@ -61,7 +61,7 @@ pub async fn whoami(session: CandidateAuth) -> Result> { #[post("/details", data = "
")] pub async fn fill_details( conn: Connection<'_, Db>, - details: Json, + details: Json, session: CandidateAuth, ) -> Result> { let db = conn.into_inner(); @@ -87,7 +87,7 @@ pub async fn get_details( conn: Connection<'_, Db>, password_form: Json, session: CandidateAuth, -) -> Result, Custom> { +) -> Result, Custom> { let db = conn.into_inner(); let candidate: entity::candidate::Model = session.into(); let password = password_form.password.clone(); diff --git a/core/src/candidate_details.rs b/core/src/candidate_details.rs index 7b20ab2..2bf1961 100644 --- a/core/src/candidate_details.rs +++ b/core/src/candidate_details.rs @@ -58,7 +58,7 @@ impl TryFrom> for EncryptedString { // TODO: take a look at th } #[derive(Clone)] -pub struct EncryptedCandidateDetails { +pub struct EncryptedApplicationDetails { // Candidate pub name: EncryptedString, pub surname: EncryptedString, @@ -78,8 +78,8 @@ pub struct EncryptedCandidateDetails { pub parent_email: EncryptedString, } -impl EncryptedCandidateDetails { - pub async fn new(form: CandidateDetails, recipients: Vec<&str>) -> Result { +impl EncryptedApplicationDetails { + pub async fn new(form: ApplicationDetails, recipients: Vec<&str>) -> Result { let birthdate_str = form.birthdate.format(NAIVE_DATE_FMT).to_string(); let d = tokio::try_join!( EncryptedString::new(&form.name, &recipients), @@ -99,7 +99,7 @@ impl EncryptedCandidateDetails { EncryptedString::new(&form.parent_email, &recipients), )?; - Ok(EncryptedCandidateDetails { + Ok(EncryptedApplicationDetails { name: d.0, surname: d.1, birthplace: d.2, @@ -118,7 +118,7 @@ impl EncryptedCandidateDetails { }) } - pub async fn decrypt(self, priv_key: String) -> Result { + pub async fn decrypt(self, priv_key: String) -> Result { let d = tokio::try_join!( self.name.decrypt(&priv_key), // 0 self.surname.decrypt(&priv_key), // 1 @@ -137,7 +137,7 @@ impl EncryptedCandidateDetails { self.parent_email.decrypt(&priv_key), )?; - Ok(CandidateDetails { + Ok(ApplicationDetails { name: d.0, surname: d.1, 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; fn try_from((candidate, parent): (candidate::Model, parent::Model)) -> Result { - Ok(EncryptedCandidateDetails { + Ok(EncryptedApplicationDetails { name: EncryptedString::try_from(candidate.name)?, surname: EncryptedString::try_from(candidate.surname)?, birthplace: EncryptedString::try_from(candidate.birthplace)?, @@ -182,7 +182,7 @@ impl TryFrom<(candidate::Model, parent::Model)> for EncryptedCandidateDetails { } #[derive(Debug, Serialize, Deserialize)] -pub struct CandidateDetails { +pub struct ApplicationDetails { // Candidate pub name: String, pub surname: String, diff --git a/core/src/database/mutation/candidate.rs b/core/src/database/mutation/candidate.rs index 9b191b0..8ffda50 100644 --- a/core/src/database/mutation/candidate.rs +++ b/core/src/database/mutation/candidate.rs @@ -1,4 +1,4 @@ -use crate::{Mutation, candidate_details::{EncryptedCandidateDetails}}; +use crate::{Mutation, candidate_details::{EncryptedApplicationDetails}}; use ::entity::candidate::{self}; use sea_orm::{*}; @@ -29,7 +29,7 @@ impl Mutation { pub async fn add_candidate_details( db: &DbConn, user: candidate::Model, - enc_details: EncryptedCandidateDetails, + enc_details: EncryptedApplicationDetails, ) -> Result { let mut user: candidate::ActiveModel = user.into(); user.name = Set(Some(enc_details.name.into())); diff --git a/core/src/database/mutation/parent.rs b/core/src/database/mutation/parent.rs index 2855a29..a464e42 100644 --- a/core/src/database/mutation/parent.rs +++ b/core/src/database/mutation/parent.rs @@ -1,4 +1,4 @@ -use crate::{Mutation, candidate_details::EncryptedCandidateDetails}; +use crate::{Mutation, candidate_details::EncryptedApplicationDetails}; use ::entity::parent::{self, Model}; use sea_orm::*; @@ -18,7 +18,7 @@ impl Mutation { pub async fn add_parent_details( db: &DbConn, parent: Model, - enc_details: EncryptedCandidateDetails, // TODO: use seperate struct?? + enc_details: EncryptedApplicationDetails, // TODO: use seperate struct?? ) -> Result { let mut user: parent::ActiveModel = parent.into(); user.name = Set(Some(enc_details.parent_name.into())); diff --git a/core/src/services/application_service.rs b/core/src/services/application_service.rs index 1e7a413..0c7b083 100644 --- a/core/src/services/application_service.rs +++ b/core/src/services/application_service.rs @@ -1,7 +1,7 @@ use entity::{candidate, parent}; 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}; @@ -25,7 +25,7 @@ impl ApplicationService { pub async fn add_all_details( db: &DbConn, application: i32, - form: CandidateDetails, + form: ApplicationDetails, ) -> Result<(candidate::Model, parent::Model), ServiceError> { let candidate = Query::find_candidate_by_id(db, application) .await @@ -47,7 +47,7 @@ impl ApplicationService { let mut recipients = vec![&*candidate.public_key]; recipients.append(&mut admin_public_keys_refrence); - let enc_details = EncryptedCandidateDetails::new(form, recipients).await?; + let enc_details = EncryptedApplicationDetails::new(form, recipients).await?; Ok( ( @@ -61,7 +61,7 @@ impl ApplicationService { db: &DbConn, application_id: i32, password: String, - ) -> Result { + ) -> Result { let candidate = match Query::find_candidate_by_id(db, application_id).await { Ok(candidate) => candidate.unwrap(), Err(_) => return Err(ServiceError::DbError), // TODO: logging @@ -81,7 +81,7 @@ impl ApplicationService { .await .ok() .unwrap(); - let enc_details = EncryptedCandidateDetails::try_from((candidate, parent))?; + let enc_details = EncryptedApplicationDetails::try_from((candidate, parent))?; enc_details.decrypt(dec_priv_key).await } diff --git a/core/src/services/candidate_service.rs b/core/src/services/candidate_service.rs index 338eb9a..b5ced20 100644 --- a/core/src/services/candidate_service.rs +++ b/core/src/services/candidate_service.rs @@ -4,7 +4,7 @@ use sea_orm::{prelude::Uuid, DbConn}; use crate::{ crypto::{self, hash_password}, error::ServiceError, - Mutation, Query, candidate_details::{EncryptedCandidateDetails}, + Mutation, Query, candidate_details::{EncryptedApplicationDetails}, }; use super::{session_service::{AdminUser, SessionService}}; @@ -68,7 +68,7 @@ impl CandidateService { pub(in crate::services) async fn add_candidate_details( db: &DbConn, candidate: candidate::Model, - enc_details: EncryptedCandidateDetails, + enc_details: EncryptedApplicationDetails, ) -> Result { Mutation::add_candidate_details(db, candidate, enc_details.clone()) .await @@ -173,12 +173,12 @@ mod tests { services::candidate_service::{CandidateService}, Mutation, }; - use super::EncryptedCandidateDetails; + use super::EncryptedApplicationDetails; use chrono::NaiveDate; use entity::{parent, candidate}; use crate::services::application_service::ApplicationService; - use crate::candidate_details::CandidateDetails; + use crate::candidate_details::ApplicationDetails; #[tokio::test] async fn test_application_id_validation() { @@ -259,7 +259,7 @@ mod tests { .ok() .unwrap(); - let form = CandidateDetails { + let form = ApplicationDetails { name: "test".to_string(), surname: "aaa".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) .await .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(); assert_eq!(dec_details.name, "test"); // TODO: test every element diff --git a/core/src/services/parent_service.rs b/core/src/services/parent_service.rs index ba6363e..79ce638 100644 --- a/core/src/services/parent_service.rs +++ b/core/src/services/parent_service.rs @@ -1,7 +1,7 @@ use entity::{parent}; use sea_orm::DbConn; -use crate::{error::ServiceError, Mutation, candidate_details::EncryptedCandidateDetails}; +use crate::{error::ServiceError, Mutation, candidate_details::EncryptedApplicationDetails}; pub struct ParentService; @@ -20,7 +20,7 @@ impl ParentService { pub async fn add_parent_details( db: &DbConn, parent: parent::Model, - enc_details: EncryptedCandidateDetails, + enc_details: EncryptedApplicationDetails, ) -> Result { let parent = Mutation::add_parent_details(db, parent, enc_details) .await