mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-19 14:31:05 +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 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<String, Custom<String>> {
|
|||
#[post("/details", data = "<details>")]
|
||||
pub async fn fill_details(
|
||||
conn: Connection<'_, Db>,
|
||||
details: Json<CandidateDetails>,
|
||||
details: Json<ApplicationDetails>,
|
||||
session: CandidateAuth,
|
||||
) -> Result<String, Custom<String>> {
|
||||
let db = conn.into_inner();
|
||||
|
|
@ -87,7 +87,7 @@ pub async fn get_details(
|
|||
conn: Connection<'_, Db>,
|
||||
password_form: Json<PasswordRequest>,
|
||||
session: CandidateAuth,
|
||||
) -> Result<Json<CandidateDetails>, Custom<String>> {
|
||||
) -> Result<Json<ApplicationDetails>, Custom<String>> {
|
||||
let db = conn.into_inner();
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
let password = password_form.password.clone();
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ impl TryFrom<Option<NaiveDate>> 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<EncryptedCandidateDetails, ServiceError> {
|
||||
impl EncryptedApplicationDetails {
|
||||
pub async fn new(form: ApplicationDetails, recipients: Vec<&str>) -> Result<EncryptedApplicationDetails, ServiceError> {
|
||||
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<CandidateDetails, ServiceError> {
|
||||
pub async fn decrypt(self, priv_key: String) -> Result<ApplicationDetails, ServiceError> {
|
||||
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<Self, Self::Error> {
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -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<candidate::Model, sea_orm::DbErr> {
|
||||
let mut user: candidate::ActiveModel = user.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 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<Model, sea_orm::DbErr> {
|
||||
let mut user: parent::ActiveModel = parent.into();
|
||||
user.name = Set(Some(enc_details.parent_name.into()));
|
||||
|
|
|
|||
|
|
@ -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<CandidateDetails, ServiceError> {
|
||||
) -> Result<ApplicationDetails, ServiceError> {
|
||||
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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<entity::candidate::Model, ServiceError> {
|
||||
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
|
||||
|
|
|
|||
|
|
@ -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<parent::Model, ServiceError> {
|
||||
let parent = Mutation::add_parent_details(db, parent, enc_details)
|
||||
.await
|
||||
|
|
|
|||
Loading…
Reference in a new issue