mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-06 16:20:08 +00:00
refactor: methods order
This commit is contained in:
parent
8ef28a65c4
commit
b6e4af6ef7
3 changed files with 88 additions and 3 deletions
|
|
@ -5,14 +5,42 @@ use sea_orm::{prelude::Uuid, DbConn};
|
||||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
candidate_details::EncryptedApplicationDetails,
|
candidate_details::{EncryptedApplicationDetails},
|
||||||
crypto::{self, hash_password},
|
crypto::{self, hash_password},
|
||||||
error::ServiceError,
|
error::ServiceError,
|
||||||
Mutation, Query,
|
Mutation, Query, responses::CandidateResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::session_service::{AdminUser, SessionService};
|
use super::session_service::{AdminUser, SessionService};
|
||||||
|
|
||||||
|
// TODO
|
||||||
|
|
||||||
|
/* pub struct FieldOfStudy {
|
||||||
|
pub short_name: String,
|
||||||
|
pub full_name: String,
|
||||||
|
pub code: i32,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FieldOfStudy {
|
||||||
|
pub fn new(short_name: String, full_name: String, code: i32) -> Self {
|
||||||
|
Self {
|
||||||
|
short_name,
|
||||||
|
full_name,
|
||||||
|
code,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn code_str(&self) -> String {
|
||||||
|
format!("{:04}", self.code)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub enum FieldsOfStudy {
|
||||||
|
KB(FieldOfStudy),
|
||||||
|
IT(FieldOfStudy),
|
||||||
|
G(FieldOfStudy),
|
||||||
|
} */
|
||||||
|
|
||||||
const FIELD_OF_STUDY_PREFIXES: [&str; 3] = ["101", "102", "103"];
|
const FIELD_OF_STUDY_PREFIXES: [&str; 3] = ["101", "102", "103"];
|
||||||
|
|
||||||
pub struct CandidateService;
|
pub struct CandidateService;
|
||||||
|
|
@ -81,6 +109,31 @@ impl CandidateService {
|
||||||
Ok(model)
|
Ok(model)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn list_candidates(
|
||||||
|
private_key: String,
|
||||||
|
db: &DbConn,
|
||||||
|
field_of_study: Option<String>,
|
||||||
|
) -> Result<Vec<CandidateResponse>, ServiceError> {
|
||||||
|
|
||||||
|
let candidates = Query::list_candidates(db, None).await?;
|
||||||
|
let mut result: Vec<CandidateResponse> = vec![];
|
||||||
|
|
||||||
|
for candidate in candidates {
|
||||||
|
result.push(
|
||||||
|
CandidateResponse::from_encrypted(
|
||||||
|
&private_key,
|
||||||
|
candidate.application,
|
||||||
|
candidate.name,
|
||||||
|
candidate.surname,
|
||||||
|
candidate.study,
|
||||||
|
true
|
||||||
|
).await?
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn is_candidate_info(candidate: &candidate::Model) -> bool {
|
pub fn is_candidate_info(candidate: &candidate::Model) -> bool {
|
||||||
candidate.name.is_some()
|
candidate.name.is_some()
|
||||||
&& candidate.surname.is_some()
|
&& candidate.surname.is_some()
|
||||||
|
|
|
||||||
|
|
@ -2,4 +2,5 @@ pub mod session_service;
|
||||||
pub mod candidate_service;
|
pub mod candidate_service;
|
||||||
pub mod admin_service;
|
pub mod admin_service;
|
||||||
pub mod parent_service;
|
pub mod parent_service;
|
||||||
pub mod application_service;
|
pub mod application_service;
|
||||||
|
pub mod portfolio_service;
|
||||||
31
core/src/services/portfolio_service.rs
Normal file
31
core/src/services/portfolio_service.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
||||||
|
use std::path::Path;
|
||||||
|
|
||||||
|
use tokio::io::AsyncWriteExt;
|
||||||
|
|
||||||
|
use crate::error::ServiceError;
|
||||||
|
|
||||||
|
pub struct PortfolioService;
|
||||||
|
|
||||||
|
impl PortfolioService {
|
||||||
|
pub async fn write_portfolio_file(
|
||||||
|
candidate_id: i32,
|
||||||
|
data: Vec<u8>,
|
||||||
|
filename: &str,
|
||||||
|
) -> Result<(), ServiceError> {
|
||||||
|
let cache_path = Path::new(&candidate_id.to_string()).join("cache");
|
||||||
|
|
||||||
|
let mut file = tokio::fs::File::create(cache_path.join(filename)).await?;
|
||||||
|
|
||||||
|
file.write_all(&data).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn is_portfolio_complete(candidate_id: i32) -> bool {
|
||||||
|
let cache_path = Path::new(&candidate_id.to_string()).join("cache");
|
||||||
|
|
||||||
|
tokio::fs::metadata(cache_path.join("MOTIVACNI_DOPIS.pdf")).await.is_ok()
|
||||||
|
&& tokio::fs::metadata(cache_path.join("PORTFOLIO.pdf")).await.is_ok()
|
||||||
|
&& tokio::fs::metadata(cache_path.join("PORTFOLIO.zip")).await.is_ok()
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue