mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-27 05:51:56 +00:00
feat: add is_submitted
This commit is contained in:
parent
f475af0eec
commit
62e341c26e
3 changed files with 26 additions and 0 deletions
|
|
@ -47,6 +47,7 @@ async fn start() -> Result<(), rocket::Error> {
|
||||||
routes::candidate::upload_portfolio_letter,
|
routes::candidate::upload_portfolio_letter,
|
||||||
routes::candidate::upload_portfolio_zip,
|
routes::candidate::upload_portfolio_zip,
|
||||||
routes::candidate::submit_portfolio,
|
routes::candidate::submit_portfolio,
|
||||||
|
routes::candidate::is_submitted,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.mount(
|
.mount(
|
||||||
|
|
|
||||||
|
|
@ -193,3 +193,22 @@ pub async fn submit_portfolio(
|
||||||
|
|
||||||
Ok("Portfolio submitted".to_string())
|
Ok("Portfolio submitted".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/is_submitted")]
|
||||||
|
pub async fn is_submitted(
|
||||||
|
session: CandidateAuth,
|
||||||
|
) -> Result<String, Custom<String>> {
|
||||||
|
let candidate: entity::candidate::Model = session.into();
|
||||||
|
|
||||||
|
let is_ok = CandidateService::is_portfolio_submitted(candidate.application).await;
|
||||||
|
|
||||||
|
if !is_ok {
|
||||||
|
// TODO: Correct error
|
||||||
|
return Err(Custom(
|
||||||
|
Status::from_code(404).unwrap_or_default(),
|
||||||
|
"Portfolio not submitted".to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok("Portfolio ok".to_string())
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -192,6 +192,12 @@ impl CandidateService {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn is_portfolio_submitted(candidate_id: i32) -> bool {
|
||||||
|
let path = Path::new(&candidate_id.to_string()).join("PORTFOLIO.age");
|
||||||
|
|
||||||
|
tokio::fs::metadata(path).await.is_ok()
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn get_portfolio(candidate_id: i32, db: &DbConn) -> Result<Vec<u8>, ServiceError> {
|
pub async fn get_portfolio(candidate_id: i32, db: &DbConn) -> Result<Vec<u8>, ServiceError> {
|
||||||
let candidate = Query::find_candidate_by_id(db, candidate_id)
|
let candidate = Query::find_candidate_by_id(db, candidate_id)
|
||||||
.await?
|
.await?
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue