mirror of
https://github.com/danbulant/Portfolio
synced 2026-05-21 21:38:43 +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>,
|
||||
// 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")]
|
||||
|
|
@ -145,14 +145,14 @@ pub async fn is_cover_letter(session: CandidateAuth) -> Result<String, Custom<St
|
|||
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())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// TODO: JSON
|
||||
|
|
@ -169,14 +169,14 @@ pub async fn is_portfolio_letter(session: CandidateAuth) -> Result<String, Custo
|
|||
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())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// TODO: JSON
|
||||
|
|
@ -193,7 +193,7 @@ pub async fn is_portfolio_zip(session: CandidateAuth) -> Result<String, Custom<S
|
|||
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,21 +211,21 @@ pub async fn submit_portfolio(
|
|||
return Err(to_custom_error(e));
|
||||
}
|
||||
|
||||
Ok("Portfolio submitted".to_string())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[post("/delete")]
|
||||
pub async fn delete_portfolio(
|
||||
conn: Connection<'_, Db>,
|
||||
session: CandidateAuth,
|
||||
) -> Result<String, Custom<String>> {
|
||||
) -> Result<(), Custom<String>> {
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
|
||||
PortfolioService::delete_portfolio(candidate.application)
|
||||
.await
|
||||
.map_err(to_custom_error)?;
|
||||
|
||||
Ok("Portfolio deleted".to_string())
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[deprecated = "Use /submission_progress instead"]
|
||||
|
|
|
|||
Loading…
Reference in a new issue