From fc614eadb8af683485a01547eedd1de0055becbe Mon Sep 17 00:00:00 2001 From: EETagent Date: Wed, 16 Nov 2022 16:38:23 +0100 Subject: [PATCH] feat: add cache validation functions --- api/src/routes/candidate.rs | 30 ++++++++++++++++++++++++++ core/src/services/candidate_service.rs | 18 ++++++++++++++++ 2 files changed, 48 insertions(+) diff --git a/api/src/routes/candidate.rs b/api/src/routes/candidate.rs index 040433d..3d2dcd2 100644 --- a/api/src/routes/candidate.rs +++ b/api/src/routes/candidate.rs @@ -127,6 +127,16 @@ pub async fn upload_cover_letter( Ok("Letter added".to_string()) } +// TODO: JSON +#[get["/is_cover_letter"]] +pub async fn is_cover_letter(session: CandidateAuth) -> Result> { + let candidate: entity::candidate::Model = session.into(); + + let exists = CandidateService::is_cover_letter(candidate.application).await; + + Ok(exists.to_string()) +} + #[post("/portfolio_letter", data = "")] pub async fn upload_portfolio_letter( session: CandidateAuth, @@ -149,6 +159,16 @@ pub async fn upload_portfolio_letter( Ok("Letter added".to_string()) } +// TODO: JSON +#[get["/is_portfolio_letter"]] +pub async fn is_portfolio_letter(session: CandidateAuth) -> Result> { + let candidate: entity::candidate::Model = session.into(); + + let exists = CandidateService::is_portfolio_letter(candidate.application).await; + + Ok(exists.to_string()) +} + #[post("/portfolio_zip", data = "")] pub async fn upload_portfolio_zip( session: CandidateAuth, @@ -171,6 +191,16 @@ pub async fn upload_portfolio_zip( Ok("Portfolio added".to_string()) } +// TODO: JSON +#[get["/is_portfolio_zip"]] +pub async fn is_portfolio_zip(session: CandidateAuth) -> Result> { + let candidate: entity::candidate::Model = session.into(); + + let exists = CandidateService::is_portfolio_zip(candidate.application).await; + + Ok(exists.to_string()) +} + #[post("/submit")] pub async fn submit_portfolio( conn: Connection<'_, Db>, diff --git a/core/src/services/candidate_service.rs b/core/src/services/candidate_service.rs index affd052..44a4045 100644 --- a/core/src/services/candidate_service.rs +++ b/core/src/services/candidate_service.rs @@ -110,6 +110,12 @@ impl CandidateService { Self::write_portfolio_file(candidate_id, letter, "MOTIVACNI_DOPIS.pdf").await } + pub async fn is_cover_letter(candidate_id: i32) -> bool { + let cache_path = Path::new(&candidate_id.to_string()).join("cache"); + + tokio::fs::metadata(cache_path.join(cache_path.join("MOTIVACNI_DOPIS.pdf"))).await.is_ok() + } + pub async fn add_portfolio_letter_to_cache( candidate_id: i32, letter: Vec, @@ -117,6 +123,12 @@ impl CandidateService { Self::write_portfolio_file(candidate_id, letter, "PORTFOLIO.pdf").await } + pub async fn is_portfolio_letter(candidate_id: i32) -> bool { + let cache_path = Path::new(&candidate_id.to_string()).join("cache"); + + tokio::fs::metadata(cache_path.join(cache_path.join("PORTFOLIO.pdf"))).await.is_ok() + } + pub async fn add_portfolio_zip_to_cache( candidate_id: i32, zip: Vec, @@ -124,6 +136,12 @@ impl CandidateService { Self::write_portfolio_file(candidate_id, zip, "PORTFOLIO.zip").await } + pub async fn is_portfolio_zip(candidate_id: i32) -> bool { + let cache_path = Path::new(&candidate_id.to_string()).join("cache"); + + tokio::fs::metadata(cache_path.join(cache_path.join("PORTFOLIO.zip"))).await.is_ok() + } + pub async fn is_portfolio_prepared(candidate_id: i32) -> bool { let cache_path = Path::new(&candidate_id.to_string()).join("cache");