mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-25 21:11:50 +00:00
Merge pull request #72 from EETagent/portfolio_download
(backend) Delte portfolio endpoint
This commit is contained in:
commit
904f8732d6
3 changed files with 30 additions and 81 deletions
|
|
@ -90,10 +90,9 @@ pub fn rocket() -> Rocket<Build>{
|
|||
"/candidate/portfolio",
|
||||
routes![
|
||||
routes::candidate::submit_portfolio,
|
||||
routes::candidate::is_portfolio_prepared,
|
||||
routes::candidate::is_portfolio_submitted,
|
||||
routes::candidate::submission_progress,
|
||||
routes::candidate::download_portfolio,
|
||||
routes::candidate::delete_portfolio,
|
||||
],
|
||||
)
|
||||
.mount(
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ pub async fn login(
|
|||
login_form: Json<AdminLoginRequest>,
|
||||
// ip_addr: SocketAddr, // TODO uncomment in production
|
||||
cookies: &CookieJar<'_>,
|
||||
) -> Result<String, Custom<String>> {
|
||||
) -> Result<(), Custom<String>> {
|
||||
let ip_addr: SocketAddr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 0);
|
||||
let db = conn.into_inner();
|
||||
let session_token_key = AdminService::login(
|
||||
|
|
@ -47,10 +47,7 @@ pub async fn login(
|
|||
cookies.add_private(Cookie::new("id", session_token.clone()));
|
||||
cookies.add_private(Cookie::new("key", private_key.clone()));
|
||||
|
||||
// TODO: JSON
|
||||
let response = format!("{} {}", session_token, private_key);
|
||||
|
||||
return Ok(response);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
#[post("/logout")]
|
||||
|
|
@ -64,12 +61,12 @@ pub async fn logout(conn: Connection<'_, Db>, _session: AdminAuth, cookies: &Coo
|
|||
|
||||
let res = AdminService::logout(db, session_id)
|
||||
.await
|
||||
.map_err(|e| Custom(Status::from_code(e.code()).unwrap_or(Status::InternalServerError), e.to_string()))?;
|
||||
.map_err(to_custom_error)?;
|
||||
|
||||
cookies.remove_private(Cookie::named("id"));
|
||||
cookies.remove_private(Cookie::named("key"));
|
||||
|
||||
Ok(res)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -135,7 +132,9 @@ pub async fn list_candidates(
|
|||
.await
|
||||
.map_err(to_custom_error)?;
|
||||
|
||||
Ok(Json(candidates))
|
||||
Ok(
|
||||
Json(candidates)
|
||||
)
|
||||
}
|
||||
|
||||
#[get("/candidate/<id>")]
|
||||
|
|
@ -155,7 +154,9 @@ pub async fn get_candidate(
|
|||
.await
|
||||
.map_err(to_custom_error)?;
|
||||
|
||||
Ok(Json(details))
|
||||
Ok(
|
||||
Json(details)
|
||||
)
|
||||
}
|
||||
|
||||
#[post("/candidate/<id>/reset_password")]
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ pub async fn login(
|
|||
login_form: Json<LoginRequest>,
|
||||
// ip_addr: SocketAddr, // TODO uncomment in production
|
||||
cookies: &CookieJar<'_>,
|
||||
) -> Result<String, Custom<String>> {
|
||||
) -> Result<(), Custom<String>> {
|
||||
let ip_addr: SocketAddr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 0);
|
||||
let db = conn.into_inner();
|
||||
let (session_token, private_key) = CandidateService::login(
|
||||
|
|
@ -39,7 +39,7 @@ pub async fn login(
|
|||
cookies.add_private(Cookie::new("id", session_token.clone()));
|
||||
cookies.add_private(Cookie::new("key", private_key.clone()));
|
||||
|
||||
return Ok("".to_string());
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
#[post("/logout")]
|
||||
|
|
@ -108,14 +108,14 @@ pub async fn get_details(
|
|||
pub async fn upload_cover_letter(
|
||||
session: CandidateAuth,
|
||||
letter: Letter,
|
||||
) -> Result<String, Custom<String>> {
|
||||
) -> Result<(), Custom<String>> {
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
|
||||
PortfolioService::add_cover_letter_to_cache(candidate.application, letter.into())
|
||||
.await
|
||||
.map_err(to_custom_error)?;
|
||||
|
||||
Ok("Letter added".to_string())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[get("/submission_progress")]
|
||||
|
|
@ -131,69 +131,40 @@ pub async fn submission_progress(
|
|||
|
||||
progress
|
||||
}
|
||||
// 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 = PortfolioService::is_cover_letter(candidate.application).await;
|
||||
|
||||
Ok(exists.to_string())
|
||||
}
|
||||
|
||||
#[post("/portfolio_letter", data = "<letter>")]
|
||||
pub async fn upload_portfolio_letter(
|
||||
session: CandidateAuth,
|
||||
letter: Letter,
|
||||
) -> Result<String, Custom<String>> {
|
||||
) -> Result<(), Custom<String>> {
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
|
||||
PortfolioService::add_portfolio_letter_to_cache(candidate.application, letter.into())
|
||||
.await
|
||||
.map_err(to_custom_error)?;
|
||||
|
||||
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 = PortfolioService::is_portfolio_letter(candidate.application).await;
|
||||
|
||||
Ok(exists.to_string())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[post("/portfolio_zip", data = "<portfolio>")]
|
||||
pub async fn upload_portfolio_zip(
|
||||
session: CandidateAuth,
|
||||
portfolio: Portfolio,
|
||||
) -> Result<String, Custom<String>> {
|
||||
) -> Result<(), Custom<String>> {
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
|
||||
PortfolioService::add_portfolio_zip_to_cache(candidate.application, portfolio.into())
|
||||
.await
|
||||
.map_err(to_custom_error)?;
|
||||
|
||||
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 = PortfolioService::is_portfolio_zip(candidate.application).await;
|
||||
|
||||
Ok(exists.to_string())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[post("/submit")]
|
||||
pub async fn submit_portfolio(
|
||||
conn: Connection<'_, Db>,
|
||||
session: CandidateAuth,
|
||||
) -> Result<String, Custom<String>> {
|
||||
) -> Result<(), Custom<String>> {
|
||||
let db = conn.into_inner();
|
||||
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
|
|
@ -211,43 +182,21 @@ pub async fn submit_portfolio(
|
|||
return Err(to_custom_error(e));
|
||||
}
|
||||
|
||||
Ok("Portfolio submitted".to_string())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[deprecated = "Use /submission_progress instead"]
|
||||
#[get("/is_prepared")]
|
||||
pub async fn is_portfolio_prepared(session: CandidateAuth) -> Result<String, Custom<String>> {
|
||||
#[post("/delete")]
|
||||
pub async fn delete_portfolio(
|
||||
conn: Connection<'_, Db>,
|
||||
session: CandidateAuth,
|
||||
) -> Result<(), Custom<String>> {
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
|
||||
let is_ok = PortfolioService::is_portfolio_prepared(candidate.application).await;
|
||||
PortfolioService::delete_portfolio(candidate.application)
|
||||
.await
|
||||
.map_err(to_custom_error)?;
|
||||
|
||||
if !is_ok {
|
||||
// TODO: Correct error
|
||||
return Err(Custom(
|
||||
Status::from_code(404).unwrap_or_default(),
|
||||
"Portfolio not prepared".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
Ok("Portfolio ok".to_string())
|
||||
}
|
||||
|
||||
#[deprecated = "Use /submission_progress instead"]
|
||||
#[get("/is_submitted")]
|
||||
pub async fn is_portfolio_submitted(session: CandidateAuth) -> Result<String, Custom<String>> {
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
|
||||
let is_ok = PortfolioService::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())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[get("/download")]
|
||||
|
|
|
|||
Loading…
Reference in a new issue