mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-24 12:35:31 +00:00
feat: optimize responses
This commit is contained in:
parent
211ed722ca
commit
64562aa982
2 changed files with 22 additions and 21 deletions
|
|
@ -21,7 +21,7 @@ pub async fn login(
|
||||||
login_form: Json<AdminLoginRequest>,
|
login_form: Json<AdminLoginRequest>,
|
||||||
// ip_addr: SocketAddr, // TODO uncomment in production
|
// ip_addr: SocketAddr, // TODO uncomment in production
|
||||||
cookies: &CookieJar<'_>,
|
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 ip_addr: SocketAddr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 0);
|
||||||
let db = conn.into_inner();
|
let db = conn.into_inner();
|
||||||
let session_token_key = AdminService::login(
|
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("id", session_token.clone()));
|
||||||
cookies.add_private(Cookie::new("key", private_key.clone()));
|
cookies.add_private(Cookie::new("key", private_key.clone()));
|
||||||
|
|
||||||
// TODO: JSON
|
return Ok(());
|
||||||
let response = format!("{} {}", session_token, private_key);
|
|
||||||
|
|
||||||
return Ok(response);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/logout")]
|
#[post("/logout")]
|
||||||
|
|
@ -64,12 +61,12 @@ pub async fn logout(conn: Connection<'_, Db>, _session: AdminAuth, cookies: &Coo
|
||||||
|
|
||||||
let res = AdminService::logout(db, session_id)
|
let res = AdminService::logout(db, session_id)
|
||||||
.await
|
.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("id"));
|
||||||
cookies.remove_private(Cookie::named("key"));
|
cookies.remove_private(Cookie::named("key"));
|
||||||
|
|
||||||
Ok(res)
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -135,7 +132,9 @@ pub async fn list_candidates(
|
||||||
.await
|
.await
|
||||||
.map_err(to_custom_error)?;
|
.map_err(to_custom_error)?;
|
||||||
|
|
||||||
Ok(Json(candidates))
|
Ok(
|
||||||
|
Json(candidates)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/candidate/<id>")]
|
#[get("/candidate/<id>")]
|
||||||
|
|
@ -155,7 +154,9 @@ pub async fn get_candidate(
|
||||||
.await
|
.await
|
||||||
.map_err(to_custom_error)?;
|
.map_err(to_custom_error)?;
|
||||||
|
|
||||||
Ok(Json(details))
|
Ok(
|
||||||
|
Json(details)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/candidate/<id>/reset_password")]
|
#[post("/candidate/<id>/reset_password")]
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ pub async fn login(
|
||||||
login_form: Json<LoginRequest>,
|
login_form: Json<LoginRequest>,
|
||||||
// ip_addr: SocketAddr, // TODO uncomment in production
|
// ip_addr: SocketAddr, // TODO uncomment in production
|
||||||
cookies: &CookieJar<'_>,
|
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 ip_addr: SocketAddr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 0);
|
||||||
let db = conn.into_inner();
|
let db = conn.into_inner();
|
||||||
let (session_token, private_key) = CandidateService::login(
|
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("id", session_token.clone()));
|
||||||
cookies.add_private(Cookie::new("key", private_key.clone()));
|
cookies.add_private(Cookie::new("key", private_key.clone()));
|
||||||
|
|
||||||
return Ok("".to_string());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/logout")]
|
#[post("/logout")]
|
||||||
|
|
@ -108,14 +108,14 @@ pub async fn get_details(
|
||||||
pub async fn upload_cover_letter(
|
pub async fn upload_cover_letter(
|
||||||
session: CandidateAuth,
|
session: CandidateAuth,
|
||||||
letter: Letter,
|
letter: Letter,
|
||||||
) -> Result<String, Custom<String>> {
|
) -> Result<(), Custom<String>> {
|
||||||
let candidate: entity::candidate::Model = session.into();
|
let candidate: entity::candidate::Model = session.into();
|
||||||
|
|
||||||
PortfolioService::add_cover_letter_to_cache(candidate.application, letter.into())
|
PortfolioService::add_cover_letter_to_cache(candidate.application, letter.into())
|
||||||
.await
|
.await
|
||||||
.map_err(to_custom_error)?;
|
.map_err(to_custom_error)?;
|
||||||
|
|
||||||
Ok("Letter added".to_string())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/submission_progress")]
|
#[get("/submission_progress")]
|
||||||
|
|
@ -145,14 +145,14 @@ pub async fn is_cover_letter(session: CandidateAuth) -> Result<String, Custom<St
|
||||||
pub async fn upload_portfolio_letter(
|
pub async fn upload_portfolio_letter(
|
||||||
session: CandidateAuth,
|
session: CandidateAuth,
|
||||||
letter: Letter,
|
letter: Letter,
|
||||||
) -> Result<String, Custom<String>> {
|
) -> Result<(), Custom<String>> {
|
||||||
let candidate: entity::candidate::Model = session.into();
|
let candidate: entity::candidate::Model = session.into();
|
||||||
|
|
||||||
PortfolioService::add_portfolio_letter_to_cache(candidate.application, letter.into())
|
PortfolioService::add_portfolio_letter_to_cache(candidate.application, letter.into())
|
||||||
.await
|
.await
|
||||||
.map_err(to_custom_error)?;
|
.map_err(to_custom_error)?;
|
||||||
|
|
||||||
Ok("Letter added".to_string())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: JSON
|
// TODO: JSON
|
||||||
|
|
@ -169,14 +169,14 @@ pub async fn is_portfolio_letter(session: CandidateAuth) -> Result<String, Custo
|
||||||
pub async fn upload_portfolio_zip(
|
pub async fn upload_portfolio_zip(
|
||||||
session: CandidateAuth,
|
session: CandidateAuth,
|
||||||
portfolio: Portfolio,
|
portfolio: Portfolio,
|
||||||
) -> Result<String, Custom<String>> {
|
) -> Result<(), Custom<String>> {
|
||||||
let candidate: entity::candidate::Model = session.into();
|
let candidate: entity::candidate::Model = session.into();
|
||||||
|
|
||||||
PortfolioService::add_portfolio_zip_to_cache(candidate.application, portfolio.into())
|
PortfolioService::add_portfolio_zip_to_cache(candidate.application, portfolio.into())
|
||||||
.await
|
.await
|
||||||
.map_err(to_custom_error)?;
|
.map_err(to_custom_error)?;
|
||||||
|
|
||||||
Ok("Portfolio added".to_string())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: JSON
|
// TODO: JSON
|
||||||
|
|
@ -193,7 +193,7 @@ pub async fn is_portfolio_zip(session: CandidateAuth) -> Result<String, Custom<S
|
||||||
pub async fn submit_portfolio(
|
pub async fn submit_portfolio(
|
||||||
conn: Connection<'_, Db>,
|
conn: Connection<'_, Db>,
|
||||||
session: CandidateAuth,
|
session: CandidateAuth,
|
||||||
) -> Result<String, Custom<String>> {
|
) -> Result<(), Custom<String>> {
|
||||||
let db = conn.into_inner();
|
let db = conn.into_inner();
|
||||||
|
|
||||||
let candidate: entity::candidate::Model = session.into();
|
let candidate: entity::candidate::Model = session.into();
|
||||||
|
|
@ -211,21 +211,21 @@ pub async fn submit_portfolio(
|
||||||
return Err(to_custom_error(e));
|
return Err(to_custom_error(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok("Portfolio submitted".to_string())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/delete")]
|
#[post("/delete")]
|
||||||
pub async fn delete_portfolio(
|
pub async fn delete_portfolio(
|
||||||
conn: Connection<'_, Db>,
|
conn: Connection<'_, Db>,
|
||||||
session: CandidateAuth,
|
session: CandidateAuth,
|
||||||
) -> Result<String, Custom<String>> {
|
) -> Result<(), Custom<String>> {
|
||||||
let candidate: entity::candidate::Model = session.into();
|
let candidate: entity::candidate::Model = session.into();
|
||||||
|
|
||||||
PortfolioService::delete_portfolio(candidate.application)
|
PortfolioService::delete_portfolio(candidate.application)
|
||||||
.await
|
.await
|
||||||
.map_err(to_custom_error)?;
|
.map_err(to_custom_error)?;
|
||||||
|
|
||||||
Ok("Portfolio deleted".to_string())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[deprecated = "Use /submission_progress instead"]
|
#[deprecated = "Use /submission_progress instead"]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue