mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-16 04:51:18 +00:00
fix: portfolio cleanup after unsuccessful request
This commit is contained in:
parent
5821c7c190
commit
a93549c906
2 changed files with 21 additions and 2 deletions
|
|
@ -182,9 +182,10 @@ pub async fn submit_portfolio(
|
|||
let submit = CandidateService::add_portfolio(candidate.application, &db).await;
|
||||
|
||||
if submit.is_err() {
|
||||
// TODO cleanup
|
||||
// Cleanup
|
||||
// TODO: unwrap pryč
|
||||
CandidateService::delete_portfolio(candidate.application).await.unwrap();
|
||||
let e = submit.err().unwrap();
|
||||
eprintln!("{}", e);
|
||||
return Err(Custom(
|
||||
Status::from_code(e.code()).unwrap_or_default(),
|
||||
e.to_string(),
|
||||
|
|
@ -193,6 +194,7 @@ pub async fn submit_portfolio(
|
|||
|
||||
Ok("Portfolio submitted".to_string())
|
||||
}
|
||||
|
||||
#[get("/is_prepared")]
|
||||
pub async fn is_portfolio_prepared(
|
||||
session: CandidateAuth,
|
||||
|
|
|
|||
|
|
@ -191,6 +191,23 @@ impl CandidateService {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn delete_portfolio(candidate_id: i32) -> Result<(), ServiceError> {
|
||||
let path = Path::new(&candidate_id.to_string()).to_path_buf();
|
||||
|
||||
let portfolio_path = path.join("PORTFOLIO.zip");
|
||||
let portfolio_age_path = portfolio_path.with_extension("age");
|
||||
|
||||
if tokio::fs::metadata(&portfolio_path).await.is_ok() {
|
||||
tokio::fs::remove_file(&portfolio_path).await?;
|
||||
}
|
||||
|
||||
if tokio::fs::metadata(&portfolio_age_path).await.is_ok() {
|
||||
tokio::fs::remove_file(&portfolio_age_path).await?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn is_portfolio_submitted(candidate_id: i32) -> bool {
|
||||
let path = Path::new(&candidate_id.to_string()).join("PORTFOLIO.age");
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue