mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-24 12:35:31 +00:00
Merge pull request #103 from EETagent/admin_list_candidates
Change Candidate List data format
This commit is contained in:
commit
9f35f6fa89
5 changed files with 44 additions and 46 deletions
|
|
@ -129,7 +129,7 @@ pub async fn list_candidates(
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let candidates = CandidateService::list_candidates(private_key, db, field, page)
|
let candidates = CandidateService::list_candidates(&private_key, db, field, page)
|
||||||
.await
|
.await
|
||||||
.map_err(to_custom_error)?;
|
.map_err(to_custom_error)?;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,16 +17,15 @@ impl ApplicationId {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(FromQueryResult)]
|
#[derive(FromQueryResult, Clone)]
|
||||||
pub struct CandidateParentResult {
|
pub struct CandidateResult {
|
||||||
pub application: i32,
|
pub application: i32,
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub surname: Option<String>,
|
pub surname: Option<String>,
|
||||||
|
pub email: Option<String>,
|
||||||
|
pub telephone: Option<String>,
|
||||||
pub study: Option<String>,
|
pub study: Option<String>,
|
||||||
pub citizenship: Option<String>,
|
pub citizenship: Option<String>,
|
||||||
|
|
||||||
pub parent_name: Option<String>,
|
|
||||||
pub parent_surname: Option<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Query {
|
impl Query {
|
||||||
|
|
@ -43,7 +42,7 @@ impl Query {
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
field_of_study_opt: Option<String>,
|
field_of_study_opt: Option<String>,
|
||||||
page: Option<u64>,
|
page: Option<u64>,
|
||||||
) -> Result<Vec<CandidateParentResult>, DbErr> {
|
) -> Result<Vec<CandidateResult>, DbErr> {
|
||||||
let select = Candidate::find();
|
let select = Candidate::find();
|
||||||
let query = if let Some(study) = field_of_study_opt {
|
let query = if let Some(study) = field_of_study_opt {
|
||||||
select.filter(candidate::Column::Study.eq(study))
|
select.filter(candidate::Column::Study.eq(study))
|
||||||
|
|
@ -51,16 +50,15 @@ impl Query {
|
||||||
select
|
select
|
||||||
}
|
}
|
||||||
.order_by(candidate::Column::Application, Order::Asc)
|
.order_by(candidate::Column::Application, Order::Asc)
|
||||||
.join(JoinType::InnerJoin, candidate::Relation::Parent.def())
|
.into_model::<CandidateResult>();
|
||||||
.column_as(parent::Column::Name, "parent_name")
|
|
||||||
.column_as(parent::Column::Surname, "parent_surname")
|
|
||||||
.into_model::<CandidateParentResult>()
|
|
||||||
.paginate(db, PAGE_SIZE);
|
|
||||||
|
|
||||||
if let Some(page) = page {
|
if let Some(page) = page {
|
||||||
query.fetch_page(page).await
|
query
|
||||||
|
.paginate(db, PAGE_SIZE)
|
||||||
|
.fetch_page(page).await
|
||||||
} else {
|
} else {
|
||||||
query.fetch().await
|
query
|
||||||
|
.all(db).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use chrono::NaiveDate;
|
||||||
use sea_orm::FromQueryResult;
|
use sea_orm::FromQueryResult;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
use crate::{error::ServiceError};
|
use crate::{error::ServiceError, database::query::candidate::CandidateResult, services::portfolio_service::SubmissionProgress};
|
||||||
|
|
||||||
use super::candidate_details::decrypt_if_exists;
|
use super::candidate_details::decrypt_if_exists;
|
||||||
|
|
||||||
|
|
@ -23,8 +23,10 @@ pub struct BaseCandidateResponse {
|
||||||
pub application_id: i32,
|
pub application_id: i32,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub surname: String,
|
pub surname: String,
|
||||||
|
pub email: String,
|
||||||
|
pub telephone: String,
|
||||||
pub study: String,
|
pub study: String,
|
||||||
pub submitted: bool,
|
pub progress: SubmissionProgress,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
|
#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)]
|
||||||
|
|
@ -91,21 +93,23 @@ pub struct Row {
|
||||||
impl BaseCandidateResponse {
|
impl BaseCandidateResponse {
|
||||||
pub async fn from_encrypted(
|
pub async fn from_encrypted(
|
||||||
private_key: &String,
|
private_key: &String,
|
||||||
application_id: i32,
|
c: CandidateResult,
|
||||||
name_opt: Option<String>,
|
progress: Option<SubmissionProgress>,
|
||||||
surname_opt: Option<String>,
|
|
||||||
study_opt: Option<String>,
|
|
||||||
submitted: bool,
|
|
||||||
) -> Result<Self, ServiceError> {
|
) -> Result<Self, ServiceError> {
|
||||||
let name = decrypt_if_exists(private_key, name_opt).await?;
|
let name = decrypt_if_exists(private_key, c.name).await?;
|
||||||
let surname = decrypt_if_exists(private_key, surname_opt).await?;
|
let surname = decrypt_if_exists(private_key, c.surname).await?;
|
||||||
|
let email = decrypt_if_exists(private_key, c.email).await?;
|
||||||
|
let telephone = decrypt_if_exists(private_key, c.telephone).await?;
|
||||||
|
let progress = progress.unwrap_or(SubmissionProgress::NoneInCache);
|
||||||
Ok(
|
Ok(
|
||||||
Self {
|
Self {
|
||||||
|
application_id: c.application,
|
||||||
name,
|
name,
|
||||||
application_id,
|
|
||||||
surname,
|
surname,
|
||||||
study: study_opt.unwrap_or("".to_string()),
|
email,
|
||||||
submitted,
|
telephone,
|
||||||
|
study: c.study.unwrap_or("".to_string()),
|
||||||
|
progress,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -161,7 +161,7 @@ impl CandidateService {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn list_candidates(
|
pub async fn list_candidates(
|
||||||
private_key: String,
|
private_key: &String,
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
field_of_study: Option<String>,
|
field_of_study: Option<String>,
|
||||||
page: Option<u64>,
|
page: Option<u64>,
|
||||||
|
|
@ -173,22 +173,17 @@ impl CandidateService {
|
||||||
page
|
page
|
||||||
).await?;
|
).await?;
|
||||||
|
|
||||||
let mut result: Vec<BaseCandidateResponse> = vec![];
|
futures::future::try_join_all(
|
||||||
|
candidates
|
||||||
for candidate in candidates {
|
.iter()
|
||||||
result.push(
|
.map(|c| async move {
|
||||||
BaseCandidateResponse::from_encrypted(
|
BaseCandidateResponse::from_encrypted(
|
||||||
&private_key,
|
private_key,
|
||||||
candidate.application,
|
c.clone(),
|
||||||
candidate.name,
|
PortfolioService::get_submission_progress(c.application).await.ok()
|
||||||
candidate.surname,
|
).await
|
||||||
candidate.study,
|
})
|
||||||
true
|
).await
|
||||||
).await?
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(result)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_candidate_info(candidate: &candidate::Model) -> bool {
|
pub fn is_candidate_info(candidate: &candidate::Model) -> bool {
|
||||||
|
|
@ -372,12 +367,12 @@ pub mod tests {
|
||||||
let db = get_memory_sqlite_connection().await;
|
let db = get_memory_sqlite_connection().await;
|
||||||
let admin = create_admin(&db).await;
|
let admin = create_admin(&db).await;
|
||||||
let private_key = crypto::decrypt_password(admin.private_key, "admin".to_string()).await.unwrap();
|
let private_key = crypto::decrypt_password(admin.private_key, "admin".to_string()).await.unwrap();
|
||||||
let candidates = CandidateService::list_candidates(private_key.clone(), &db, None, None).await.unwrap();
|
let candidates = CandidateService::list_candidates(&private_key, &db, None, None).await.unwrap();
|
||||||
assert_eq!(candidates.len(), 0);
|
assert_eq!(candidates.len(), 0);
|
||||||
|
|
||||||
put_user_data(&db).await;
|
put_user_data(&db).await;
|
||||||
|
|
||||||
let candidates = CandidateService::list_candidates(private_key.clone(), &db, None, None).await.unwrap();
|
let candidates = CandidateService::list_candidates(&private_key, &db, None, None).await.unwrap();
|
||||||
assert_eq!(candidates.len(), 1);
|
assert_eq!(candidates.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||||
|
|
||||||
use crate::{error::ServiceError, Query, crypto};
|
use crate::{error::ServiceError, Query, crypto};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
pub enum SubmissionProgress {
|
pub enum SubmissionProgress {
|
||||||
NoneInCache,
|
NoneInCache,
|
||||||
SomeInCache(Vec<FileType>),
|
SomeInCache(Vec<FileType>),
|
||||||
|
|
@ -49,7 +50,7 @@ impl Serialize for SubmissionProgress {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Debug, Copy, Clone)]
|
||||||
pub enum FileType {
|
pub enum FileType {
|
||||||
CoverLetterPdf = 1,
|
CoverLetterPdf = 1,
|
||||||
PortfolioLetterPdf = 2,
|
PortfolioLetterPdf = 2,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue