From b31b557ae03e135244136f611a70542b52078b67 Mon Sep 17 00:00:00 2001 From: EETagent Date: Mon, 5 Dec 2022 20:18:24 +0100 Subject: [PATCH] feat: use seperate functions --- api/src/routes/candidate.rs | 27 +++++++++----------------- core/src/services/portfolio_service.rs | 20 ++++++++++++++++++- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/api/src/routes/candidate.rs b/api/src/routes/candidate.rs index c2b3a6f..dafe0b9 100644 --- a/api/src/routes/candidate.rs +++ b/api/src/routes/candidate.rs @@ -128,12 +128,9 @@ pub async fn upload_cover_letter( pub async fn delete_cover_letter(session: CandidateAuth) -> Result<(), Custom> { let candidate: entity::candidate::Model = session.into(); - PortfolioService::delete_cache_item( - candidate.application, - portfolio_core::services::portfolio_service::FileType::CoverLetterPdf, - ) - .await - .map_err(to_custom_error)?; + PortfolioService::delete_cover_letter_from_cache(candidate.application) + .await + .map_err(to_custom_error)?; Ok(()) } @@ -156,12 +153,9 @@ pub async fn upload_portfolio_letter( pub async fn delete_portfolio_letter(session: CandidateAuth) -> Result<(), Custom> { let candidate: entity::candidate::Model = session.into(); - PortfolioService::delete_cache_item( - candidate.application, - portfolio_core::services::portfolio_service::FileType::PortfolioLetterPdf, - ) - .await - .map_err(to_custom_error)?; + PortfolioService::delete_portfolio_letter_from_cache(candidate.application) + .await + .map_err(to_custom_error)?; Ok(()) } @@ -184,12 +178,9 @@ pub async fn upload_portfolio_zip( pub async fn delete_portfolio_zip(session: CandidateAuth) -> Result<(), Custom> { let candidate: entity::candidate::Model = session.into(); - PortfolioService::delete_cache_item( - candidate.application, - portfolio_core::services::portfolio_service::FileType::PortfolioZip, - ) - .await - .map_err(to_custom_error)?; + PortfolioService::delete_portfolio_zip_from_cache(candidate.application) + .await + .map_err(to_custom_error)?; Ok(()) } diff --git a/core/src/services/portfolio_service.rs b/core/src/services/portfolio_service.rs index e80463a..c122cc9 100644 --- a/core/src/services/portfolio_service.rs +++ b/core/src/services/portfolio_service.rs @@ -210,7 +210,7 @@ impl PortfolioService { /// Returns true if portfolio is ready to be moved to the final directory - pub async fn is_portfolio_prepared(candidate_id: i32) -> bool { + async fn is_portfolio_prepared(candidate_id: i32) -> bool { let cache_path = Self::get_file_store_path().join(&candidate_id.to_string()).join("cache"); let filenames = vec![FileType::CoverLetterPdf, FileType::PortfolioLetterPdf, FileType::PortfolioZip]; @@ -233,6 +233,24 @@ impl PortfolioService { Ok(()) } + pub async fn delete_cover_letter_from_cache( + candidate_id: i32, + ) -> Result<(), ServiceError> { + Self::delete_cache_item(candidate_id, FileType::CoverLetterPdf).await + } + + pub async fn delete_portfolio_letter_from_cache( + candidate_id: i32, + ) -> Result<(), ServiceError> { + Self::delete_cache_item(candidate_id, FileType::PortfolioLetterPdf).await + } + + pub async fn delete_portfolio_zip_from_cache( + candidate_id: i32, + ) -> Result<(), ServiceError> { + Self::delete_cache_item(candidate_id, FileType::PortfolioZip).await + } + /// Removes all files from cache pub async fn delete_cache(candidate_id: i32) -> Result<(), ServiceError> { let cache_path = Self::get_file_store_path().join(&candidate_id.to_string()).join("cache");