mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-05 11:00:56 +00:00
feat: download portfolio candidate endpoint
This commit is contained in:
parent
f8938e65f7
commit
11e90c6b33
3 changed files with 19 additions and 4 deletions
|
|
@ -59,6 +59,7 @@ async fn start() -> Result<(), rocket::Error> {
|
||||||
routes::candidate::submit_portfolio,
|
routes::candidate::submit_portfolio,
|
||||||
routes::candidate::is_portfolio_prepared,
|
routes::candidate::is_portfolio_prepared,
|
||||||
routes::candidate::is_portfolio_submitted,
|
routes::candidate::is_portfolio_submitted,
|
||||||
|
routes::candidate::download_portfolio,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.mount(
|
.mount(
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,6 @@ pub async fn login(
|
||||||
cookies: &CookieJar<'_>,
|
cookies: &CookieJar<'_>,
|
||||||
) -> Result<String, Custom<String>> {
|
) -> Result<String, Custom<String>> {
|
||||||
let db = conn.into_inner();
|
let db = conn.into_inner();
|
||||||
println!("{} {}", login_form.admin_id, login_form.password);
|
|
||||||
|
|
||||||
let session_token_key = AdminService::login(
|
let session_token_key = AdminService::login(
|
||||||
db,
|
db,
|
||||||
login_form.admin_id,
|
login_form.admin_id,
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@ pub async fn login(
|
||||||
cookies: &CookieJar<'_>,
|
cookies: &CookieJar<'_>,
|
||||||
) -> Result<String, Custom<String>> {
|
) -> Result<String, Custom<String>> {
|
||||||
let db = conn.into_inner();
|
let db = conn.into_inner();
|
||||||
println!("{} {}", login_form.application_id, login_form.password);
|
|
||||||
|
|
||||||
let session_token_key = CandidateService::login(
|
let session_token_key = CandidateService::login(
|
||||||
db,
|
db,
|
||||||
login_form.application_id,
|
login_form.application_id,
|
||||||
|
|
@ -267,3 +265,21 @@ pub async fn is_portfolio_submitted(session: CandidateAuth) -> Result<String, Cu
|
||||||
|
|
||||||
Ok("Portfolio ok".to_string())
|
Ok("Portfolio ok".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[get("/download")]
|
||||||
|
pub async fn download_portfolio(session: CandidateAuth) -> Result<Vec<u8>, Custom<String>> {
|
||||||
|
let private_key = session.get_private_key();
|
||||||
|
let candidate: entity::candidate::Model = session.into();
|
||||||
|
|
||||||
|
let file = PortfolioService::get_portfolio(candidate.application, private_key).await;
|
||||||
|
|
||||||
|
if file.is_err() {
|
||||||
|
let e = file.err().unwrap();
|
||||||
|
return Err(Custom(
|
||||||
|
Status::from_code(e.code()).unwrap_or_default(),
|
||||||
|
e.to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(file.unwrap())
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue