mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-18 22:11:14 +00:00
refactor: candidate variables
This commit is contained in:
parent
015607322d
commit
5b70d8df4f
4 changed files with 13 additions and 13 deletions
|
|
@ -67,7 +67,7 @@ pub async fn fill_details(
|
|||
let form = details.into_inner();
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
|
||||
let candidate = CandidateService::add_user_details(db, candidate, form).await;
|
||||
let candidate = CandidateService::add_candidate_details(db, candidate, form).await;
|
||||
|
||||
if candidate.is_err() {
|
||||
// TODO cleanup
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ impl AdminService {
|
|||
match SessionService::auth_user_session(db, session_uuid).await {
|
||||
Ok(user) => match user {
|
||||
AdminUser::Admin(admin) => Ok(admin),
|
||||
AdminUser::User(_) => Err(ServiceError::DbError),
|
||||
AdminUser::Candidate(_) => Err(ServiceError::DbError),
|
||||
},
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,9 +68,9 @@ impl CandidateService {
|
|||
.map_err(|_| ServiceError::DbError)
|
||||
}
|
||||
|
||||
pub async fn add_user_details(
|
||||
pub async fn add_candidate_details(
|
||||
db: &DbConn,
|
||||
user: candidate::Model,
|
||||
candidate: candidate::Model,
|
||||
form: CandidateDetails,
|
||||
) -> Result<entity::candidate::Model, ServiceError> {
|
||||
let Ok(admin_public_keys) = Query::get_all_admin_public_keys(db).await else {
|
||||
|
|
@ -80,13 +80,13 @@ impl CandidateService {
|
|||
let mut admin_public_keys_refrence: Vec<&str> =
|
||||
admin_public_keys.iter().map(|s| &**s).collect();
|
||||
|
||||
let mut recipients = vec![&*user.public_key];
|
||||
let mut recipients = vec![&*candidate.public_key];
|
||||
|
||||
recipients.append(&mut admin_public_keys_refrence);
|
||||
|
||||
let enc_details = EncryptedCandidateDetails::new(form, recipients).await;
|
||||
|
||||
Mutation::add_candidate_details(db, user, enc_details)
|
||||
Mutation::add_candidate_details(db, candidate, enc_details)
|
||||
.await
|
||||
.map_err(|_| ServiceError::DbError)
|
||||
}
|
||||
|
|
@ -178,15 +178,15 @@ impl CandidateService {
|
|||
|
||||
pub async fn login(
|
||||
db: &DbConn,
|
||||
user_id: i32,
|
||||
candidate_id: i32,
|
||||
password: String,
|
||||
ip_addr: String,
|
||||
) -> Result<(String, String), ServiceError> {
|
||||
let session_id =
|
||||
SessionService::new_session(db, Some(user_id), None, password.clone(), ip_addr).await;
|
||||
SessionService::new_session(db, Some(candidate_id), None, password.clone(), ip_addr).await;
|
||||
match session_id {
|
||||
Ok(session_id) => {
|
||||
let private_key = Self::decrypt_private_key(db, user_id, password).await?;
|
||||
let private_key = Self::decrypt_private_key(db, candidate_id, password).await?;
|
||||
Ok((session_id, private_key))
|
||||
}
|
||||
Err(e) => Err(e),
|
||||
|
|
@ -196,7 +196,7 @@ impl CandidateService {
|
|||
pub async fn auth(db: &DbConn, session_uuid: Uuid) -> Result<candidate::Model, ServiceError> {
|
||||
match SessionService::auth_user_session(db, session_uuid).await {
|
||||
Ok(user) => match user {
|
||||
AdminUser::User(candidate) => Ok(candidate),
|
||||
AdminUser::Candidate(candidate) => Ok(candidate),
|
||||
AdminUser::Admin(_) => Err(ServiceError::DbError),
|
||||
},
|
||||
Err(e) => Err(e),
|
||||
|
|
@ -311,7 +311,7 @@ mod tests {
|
|||
sex: "test".to_string(),
|
||||
study: "test".to_string(),
|
||||
};
|
||||
CandidateService::add_user_details(&db, candidate, form)
|
||||
CandidateService::add_candidate_details(&db, candidate, form)
|
||||
.await
|
||||
.ok()
|
||||
.unwrap()
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use crate::{
|
|||
|
||||
pub enum AdminUser {
|
||||
Admin(entity::admin::Model),
|
||||
User(entity::candidate::Model),
|
||||
Candidate(entity::candidate::Model),
|
||||
}
|
||||
|
||||
pub(in crate::services) struct SessionService;
|
||||
|
|
@ -147,7 +147,7 @@ impl SessionService {
|
|||
|
||||
if candidate.is_ok() {
|
||||
if let Some(candidate) = candidate.unwrap() {
|
||||
return Ok(AdminUser::User(candidate));
|
||||
return Ok(AdminUser::Candidate(candidate));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue