mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-18 14:01:04 +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_portfolio_letter,
|
||||
routes::candidate::upload_portfolio_zip,
|
||||
routes::candidate::submit_portfolio,
|
||||
],
|
||||
)
|
||||
.mount(
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use std::net::SocketAddr;
|
|||
|
||||
use portfolio_core::candidate_details::ApplicationDetails;
|
||||
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 rocket::http::{Cookie, CookieJar, Status};
|
||||
use rocket::response::status::Custom;
|
||||
|
|
@ -68,7 +68,8 @@ pub async fn fill_details(
|
|||
let form = details.into_inner();
|
||||
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() {
|
||||
// TODO cleanup
|
||||
|
|
@ -95,7 +96,12 @@ pub async fn get_details(
|
|||
// let handle = tokio::spawn(async move {
|
||||
let details = ApplicationService::decrypt_all_details(db, candidate.application, password)
|
||||
.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))
|
||||
}
|
||||
|
|
@ -163,3 +169,27 @@ pub async fn upload_portfolio_zip(
|
|||
|
||||
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