diff --git a/core/src/database/query/candidate.rs b/core/src/database/query/candidate.rs index 9268b40..9ff39ee 100644 --- a/core/src/database/query/candidate.rs +++ b/core/src/database/query/candidate.rs @@ -50,13 +50,15 @@ impl Query { select } .order_by(candidate::Column::Application, Order::Asc) - .into_model::() - .paginate(db, PAGE_SIZE); + .into_model::(); if let Some(page) = page { - query.fetch_page(page).await + query + .paginate(db, PAGE_SIZE) + .fetch_page(page).await } else { - query.fetch().await + query + .all(db).await } } diff --git a/core/src/models/candidate.rs b/core/src/models/candidate.rs index 70cdf86..c875763 100644 --- a/core/src/models/candidate.rs +++ b/core/src/models/candidate.rs @@ -2,7 +2,7 @@ use chrono::NaiveDate; use sea_orm::FromQueryResult; use serde::{Serialize, Deserialize}; -use crate::{error::ServiceError, database::query::candidate::CandidateResult}; +use crate::{error::ServiceError, database::query::candidate::CandidateResult, services::portfolio_service::SubmissionProgress}; use super::candidate_details::decrypt_if_exists; @@ -26,7 +26,7 @@ pub struct BaseCandidateResponse { pub email: String, pub telephone: String, pub study: String, - pub submitted: bool, + pub progress: SubmissionProgress, } #[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Clone)] @@ -94,12 +94,13 @@ impl BaseCandidateResponse { pub async fn from_encrypted( private_key: &String, c: CandidateResult, - submitted: bool, + progress: Option, ) -> Result { let name = decrypt_if_exists(private_key, c.name).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( Self { application_id: c.application, @@ -108,7 +109,7 @@ impl BaseCandidateResponse { email, telephone, study: c.study.unwrap_or("".to_string()), - submitted, + progress, } ) } diff --git a/core/src/services/candidate_service.rs b/core/src/services/candidate_service.rs index 93f2182..60b1292 100644 --- a/core/src/services/candidate_service.rs +++ b/core/src/services/candidate_service.rs @@ -178,9 +178,10 @@ impl CandidateService { .iter() .map(|c| async move { BaseCandidateResponse::from_encrypted( - private_key, - c.clone(), - true).await + private_key, + c.clone(), + PortfolioService::get_submission_progress(c.application).await.ok() + ).await }) ).await } diff --git a/core/src/services/portfolio_service.rs b/core/src/services/portfolio_service.rs index 58ce4f2..f43714b 100644 --- a/core/src/services/portfolio_service.rs +++ b/core/src/services/portfolio_service.rs @@ -8,6 +8,7 @@ use tokio::io::{AsyncReadExt, AsyncWriteExt}; use crate::{error::ServiceError, Query, crypto}; +#[derive(Debug)] pub enum SubmissionProgress { NoneInCache, SomeInCache(Vec), @@ -49,7 +50,7 @@ impl Serialize for SubmissionProgress { } -#[derive(Copy, Clone)] +#[derive(Debug, Copy, Clone)] pub enum FileType { CoverLetterPdf = 1, PortfolioLetterPdf = 2,