mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-14 20:11:24 +00:00
refactor: refactor routes and function names
This commit is contained in:
parent
62e341c26e
commit
abfcf9f3eb
3 changed files with 49 additions and 20 deletions
|
|
@ -41,13 +41,24 @@ async fn start() -> Result<(), rocket::Error> {
|
|||
routes![
|
||||
routes::candidate::login,
|
||||
routes::candidate::whoami,
|
||||
routes::candidate::fill_details,
|
||||
routes::candidate::get_details,
|
||||
routes::candidate::upload_cover_letter,
|
||||
],
|
||||
)
|
||||
.mount(
|
||||
"/candidate/add",
|
||||
routes![
|
||||
routes::candidate::add_details,
|
||||
routes::candidate::upload_portfolio_letter,
|
||||
routes::candidate::upload_portfolio_zip,
|
||||
routes::candidate::upload_cover_letter,
|
||||
],
|
||||
)
|
||||
.mount(
|
||||
"/candidate/portfolio",
|
||||
routes![
|
||||
routes::candidate::submit_portfolio,
|
||||
routes::candidate::is_submitted,
|
||||
routes::candidate::is_portfolio_prepared,
|
||||
routes::candidate::is_portfolio_submitted,
|
||||
],
|
||||
)
|
||||
.mount(
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ pub async fn whoami(session: CandidateAuth) -> Result<String, Custom<String>> {
|
|||
}
|
||||
|
||||
#[post("/details", data = "<details>")]
|
||||
pub async fn fill_details(
|
||||
pub async fn add_details(
|
||||
conn: Connection<'_, Db>,
|
||||
details: Json<ApplicationDetails>,
|
||||
session: CandidateAuth,
|
||||
|
|
@ -105,14 +105,14 @@ pub async fn get_details(
|
|||
|
||||
details.map(|d| Json(d))
|
||||
}
|
||||
#[post("/coverletter", data = "<letter>")]
|
||||
#[post("/cover_letter", data = "<letter>")]
|
||||
pub async fn upload_cover_letter(
|
||||
session: CandidateAuth,
|
||||
letter: Letter,
|
||||
) -> Result<String, Custom<String>> {
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
|
||||
let candidate = CandidateService::add_cover_letter(candidate.application, letter.into()).await;
|
||||
let candidate = CandidateService::add_cover_letter_to_cache(candidate.application, letter.into()).await;
|
||||
|
||||
if candidate.is_err() {
|
||||
// TODO cleanup
|
||||
|
|
@ -126,7 +126,7 @@ pub async fn upload_cover_letter(
|
|||
Ok("Letter added".to_string())
|
||||
}
|
||||
|
||||
#[post("/portfolioletter", data = "<letter>")]
|
||||
#[post("/portfolio_letter", data = "<letter>")]
|
||||
pub async fn upload_portfolio_letter(
|
||||
session: CandidateAuth,
|
||||
letter: Letter,
|
||||
|
|
@ -134,7 +134,7 @@ pub async fn upload_portfolio_letter(
|
|||
let candidate: entity::candidate::Model = session.into();
|
||||
|
||||
let candidate =
|
||||
CandidateService::add_portfolio_letter(candidate.application, letter.into()).await;
|
||||
CandidateService::add_portfolio_letter_to_cache(candidate.application, letter.into()).await;
|
||||
|
||||
if candidate.is_err() {
|
||||
// TODO cleanup
|
||||
|
|
@ -148,7 +148,7 @@ pub async fn upload_portfolio_letter(
|
|||
Ok("Letter added".to_string())
|
||||
}
|
||||
|
||||
#[post("/portfolio", data = "<portfolio>")]
|
||||
#[post("/portfolio_zip", data = "<portfolio>")]
|
||||
pub async fn upload_portfolio_zip(
|
||||
session: CandidateAuth,
|
||||
portfolio: Portfolio,
|
||||
|
|
@ -156,7 +156,7 @@ pub async fn upload_portfolio_zip(
|
|||
let candidate: entity::candidate::Model = session.into();
|
||||
|
||||
let candidate =
|
||||
CandidateService::add_portfolio_zip(candidate.application, portfolio.into()).await;
|
||||
CandidateService::add_portfolio_zip_to_cache(candidate.application, portfolio.into()).await;
|
||||
|
||||
if candidate.is_err() {
|
||||
// TODO cleanup
|
||||
|
|
@ -167,7 +167,7 @@ pub async fn upload_portfolio_zip(
|
|||
));
|
||||
}
|
||||
|
||||
Ok("Letter added".to_string())
|
||||
Ok("Portfolio added".to_string())
|
||||
}
|
||||
|
||||
#[post("/submit")]
|
||||
|
|
@ -179,7 +179,7 @@ pub async fn submit_portfolio(
|
|||
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
|
||||
let submit = CandidateService::submit_portfolio(candidate.application, &db).await;
|
||||
let submit = CandidateService::add_portfolio(candidate.application, &db).await;
|
||||
|
||||
if submit.is_err() {
|
||||
// TODO cleanup
|
||||
|
|
@ -193,9 +193,27 @@ pub async fn submit_portfolio(
|
|||
|
||||
Ok("Portfolio submitted".to_string())
|
||||
}
|
||||
#[get("/is_prepared")]
|
||||
pub async fn is_portfolio_prepared(
|
||||
session: CandidateAuth,
|
||||
) -> Result<String, Custom<String>> {
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
|
||||
let is_ok = CandidateService::is_portfolio_prepared(candidate.application).await;
|
||||
|
||||
if !is_ok {
|
||||
// TODO: Correct error
|
||||
return Err(Custom(
|
||||
Status::from_code(404).unwrap_or_default(),
|
||||
"Portfolio not prepared".to_string(),
|
||||
));
|
||||
}
|
||||
|
||||
Ok("Portfolio ok".to_string())
|
||||
}
|
||||
|
||||
#[get("/is_submitted")]
|
||||
pub async fn is_submitted(
|
||||
pub async fn is_portfolio_submitted(
|
||||
session: CandidateAuth,
|
||||
) -> Result<String, Custom<String>> {
|
||||
let candidate: entity::candidate::Model = session.into();
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ impl CandidateService {
|
|||
Ok(model)
|
||||
}
|
||||
|
||||
pub fn is_set_up(candidate: &candidate::Model) -> bool {
|
||||
pub fn are_candidate_details_complete(candidate: &candidate::Model) -> bool {
|
||||
candidate.name.is_some()
|
||||
&& candidate.surname.is_some()
|
||||
&& candidate.birthplace.is_some()
|
||||
|
|
@ -103,22 +103,22 @@ impl CandidateService {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn add_cover_letter(candidate_id: i32, letter: Vec<u8>) -> Result<(), ServiceError> {
|
||||
pub async fn add_cover_letter_to_cache(candidate_id: i32, letter: Vec<u8>) -> Result<(), ServiceError> {
|
||||
Self::write_portfolio_file(candidate_id, letter, "MOTIVACNI_DOPIS.pdf").await
|
||||
}
|
||||
|
||||
pub async fn add_portfolio_letter(
|
||||
pub async fn add_portfolio_letter_to_cache(
|
||||
candidate_id: i32,
|
||||
letter: Vec<u8>,
|
||||
) -> Result<(), ServiceError> {
|
||||
Self::write_portfolio_file(candidate_id, letter, "PORTFOLIO.pdf").await
|
||||
}
|
||||
|
||||
pub async fn add_portfolio_zip(candidate_id: i32, zip: Vec<u8>) -> Result<(), ServiceError> {
|
||||
pub async fn add_portfolio_zip_to_cache(candidate_id: i32, zip: Vec<u8>) -> Result<(), ServiceError> {
|
||||
Self::write_portfolio_file(candidate_id, zip, "PORTFOLIO.zip").await
|
||||
}
|
||||
|
||||
pub async fn is_portfolio_complete(candidate_id: i32) -> bool {
|
||||
pub async fn is_portfolio_prepared(candidate_id: i32) -> bool {
|
||||
let cache_path = Path::new(&candidate_id.to_string()).join("cache");
|
||||
|
||||
tokio::fs::metadata(cache_path.join("MOTIVACNI_DOPIS.pdf"))
|
||||
|
|
@ -132,11 +132,11 @@ impl CandidateService {
|
|||
.is_ok()
|
||||
}
|
||||
|
||||
pub async fn submit_portfolio(candidate_id: i32, db: &DbConn) -> Result<(), ServiceError> {
|
||||
pub async fn add_portfolio(candidate_id: i32, db: &DbConn) -> Result<(), ServiceError> {
|
||||
let path = Path::new(&candidate_id.to_string()).to_path_buf();
|
||||
let cache_path = path.join("cache");
|
||||
|
||||
if Self::is_portfolio_complete(candidate_id).await == false {
|
||||
if Self::is_portfolio_prepared(candidate_id).await == false {
|
||||
return Err(ServiceError::IncompletePortfolio);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue