mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-06 19:40:49 +00:00
feat: submit endpoint
This commit is contained in:
parent
5bac182f83
commit
f475af0eec
2 changed files with 34 additions and 3 deletions
|
|
@ -46,6 +46,7 @@ async fn start() -> Result<(), rocket::Error> {
|
||||||
routes::candidate::upload_cover_letter,
|
routes::candidate::upload_cover_letter,
|
||||||
routes::candidate::upload_portfolio_letter,
|
routes::candidate::upload_portfolio_letter,
|
||||||
routes::candidate::upload_portfolio_zip,
|
routes::candidate::upload_portfolio_zip,
|
||||||
|
routes::candidate::submit_portfolio,
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
.mount(
|
.mount(
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use std::net::SocketAddr;
|
||||||
|
|
||||||
use portfolio_core::candidate_details::ApplicationDetails;
|
use portfolio_core::candidate_details::ApplicationDetails;
|
||||||
use portfolio_core::services::application_service::ApplicationService;
|
use portfolio_core::services::application_service::ApplicationService;
|
||||||
use portfolio_core::services::candidate_service::{CandidateService};
|
use portfolio_core::services::candidate_service::CandidateService;
|
||||||
use requests::LoginRequest;
|
use requests::LoginRequest;
|
||||||
use rocket::http::{Cookie, CookieJar, Status};
|
use rocket::http::{Cookie, CookieJar, Status};
|
||||||
use rocket::response::status::Custom;
|
use rocket::response::status::Custom;
|
||||||
|
|
@ -68,7 +68,8 @@ pub async fn fill_details(
|
||||||
let form = details.into_inner();
|
let form = details.into_inner();
|
||||||
let candidate: entity::candidate::Model = session.into(); // TODO: don't return candidate from session
|
let candidate: entity::candidate::Model = session.into(); // TODO: don't return candidate from session
|
||||||
|
|
||||||
let candidate_parent = ApplicationService::add_all_details(db, candidate.application, form).await;
|
let candidate_parent =
|
||||||
|
ApplicationService::add_all_details(db, candidate.application, form).await;
|
||||||
|
|
||||||
if candidate_parent.is_err() {
|
if candidate_parent.is_err() {
|
||||||
// TODO cleanup
|
// TODO cleanup
|
||||||
|
|
@ -95,7 +96,12 @@ pub async fn get_details(
|
||||||
// let handle = tokio::spawn(async move {
|
// let handle = tokio::spawn(async move {
|
||||||
let details = ApplicationService::decrypt_all_details(db, candidate.application, password)
|
let details = ApplicationService::decrypt_all_details(db, candidate.application, password)
|
||||||
.await
|
.await
|
||||||
.map_err(|e| Custom(Status::from_code(e.code()).unwrap_or_default(), e.to_string()));
|
.map_err(|e| {
|
||||||
|
Custom(
|
||||||
|
Status::from_code(e.code()).unwrap_or_default(),
|
||||||
|
e.to_string(),
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
details.map(|d| Json(d))
|
details.map(|d| Json(d))
|
||||||
}
|
}
|
||||||
|
|
@ -163,3 +169,27 @@ pub async fn upload_portfolio_zip(
|
||||||
|
|
||||||
Ok("Letter added".to_string())
|
Ok("Letter added".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[post("/submit")]
|
||||||
|
pub async fn submit_portfolio(
|
||||||
|
conn: Connection<'_, Db>,
|
||||||
|
session: CandidateAuth,
|
||||||
|
) -> Result<String, Custom<String>> {
|
||||||
|
let db = conn.into_inner();
|
||||||
|
|
||||||
|
let candidate: entity::candidate::Model = session.into();
|
||||||
|
|
||||||
|
let submit = CandidateService::submit_portfolio(candidate.application, &db).await;
|
||||||
|
|
||||||
|
if submit.is_err() {
|
||||||
|
// TODO cleanup
|
||||||
|
let e = submit.err().unwrap();
|
||||||
|
eprintln!("{}", e);
|
||||||
|
return Err(Custom(
|
||||||
|
Status::from_code(e.code()).unwrap_or_default(),
|
||||||
|
e.to_string(),
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok("Portfolio submitted".to_string())
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue