feat: add cache validation functions

This commit is contained in:
EETagent 2022-11-16 16:38:23 +01:00
parent e9f3a8042c
commit fc614eadb8
2 changed files with 48 additions and 0 deletions

View file

@ -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<String, Custom<String>> {
let candidate: entity::candidate::Model = session.into();
let exists = CandidateService::is_cover_letter(candidate.application).await;
Ok(exists.to_string())
}
#[post("/portfolio_letter", data = "<letter>")]
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<String, Custom<String>> {
let candidate: entity::candidate::Model = session.into();
let exists = CandidateService::is_portfolio_letter(candidate.application).await;
Ok(exists.to_string())
}
#[post("/portfolio_zip", data = "<portfolio>")]
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<String, Custom<String>> {
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>,

View file

@ -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<u8>,
@ -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<u8>,
@ -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");