mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-24 17:11:49 +00:00
refactor: optimize imports
This commit is contained in:
parent
85c6a47232
commit
0595f3c044
6 changed files with 13 additions and 45 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
use ::entity::application;
|
use ::entity::application;
|
||||||
use log::{info, warn};
|
use log::{info, warn};
|
||||||
use sea_orm::{DbConn, DbErr, Set, ActiveModelTrait, EntityTrait, IntoActiveModel, QueryFilter, ColumnTrait};
|
use sea_orm::{DbConn, DbErr, Set, ActiveModelTrait, IntoActiveModel};
|
||||||
|
|
||||||
use crate::Mutation;
|
use crate::Mutation;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,15 +22,6 @@ impl Mutation {
|
||||||
Ok(candidate)
|
Ok(candidate)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn find_related_application(
|
|
||||||
db: &DbConn,
|
|
||||||
candidate: candidate::Model,
|
|
||||||
) -> Result<Option<application::Model>, DbErr> {
|
|
||||||
candidate.find_related(application::Entity)
|
|
||||||
.one(db)
|
|
||||||
.await
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn delete_candidate(
|
pub async fn delete_candidate(
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
candidate: candidate::Model,
|
candidate: candidate::Model,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
use crate::Query;
|
use crate::Query;
|
||||||
|
|
||||||
use ::entity::prelude::AdminSession;
|
use ::entity::prelude::AdminSession;
|
||||||
use ::entity::{candidate, admin, admin_session, application};
|
use ::entity::{admin, admin_session, application};
|
||||||
use ::entity::{session, session::Entity as Session};
|
use ::entity::{session, session::Entity as Session};
|
||||||
use sea_orm::prelude::Uuid;
|
use sea_orm::prelude::Uuid;
|
||||||
use sea_orm::*;
|
use sea_orm::*;
|
||||||
|
|
@ -38,12 +38,12 @@ impl Query {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use entity::{session, admin, candidate, admin_session, application};
|
use entity::{session, admin, admin_session};
|
||||||
use sea_orm::{prelude::Uuid, ActiveModelTrait, Set};
|
use sea_orm::{prelude::Uuid, ActiveModelTrait, Set};
|
||||||
|
|
||||||
use crate::services::candidate_service::tests::put_user_data;
|
use crate::services::candidate_service::tests::put_user_data;
|
||||||
use crate::utils::db::get_memory_sqlite_connection;
|
use crate::utils::db::get_memory_sqlite_connection;
|
||||||
use crate::{Query, Mutation};
|
use crate::{Query};
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_find_session_by_uuid() {
|
async fn test_find_session_by_uuid() {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use sea_orm::{DbConn, prelude::Uuid, IntoActiveModel};
|
||||||
|
|
||||||
use crate::{error::ServiceError, Query, utils::db::get_recipients, models::candidate_details::{EncryptedApplicationDetails}, models::{candidate::ApplicationDetails, candidate_details::EncryptedString, auth::AuthenticableTrait, application::ApplicationResponse}, Mutation, crypto::{hash_password, self}};
|
use crate::{error::ServiceError, Query, utils::db::get_recipients, models::candidate_details::{EncryptedApplicationDetails}, models::{candidate::ApplicationDetails, candidate_details::EncryptedString, auth::AuthenticableTrait, application::ApplicationResponse}, Mutation, crypto::{hash_password, self}};
|
||||||
|
|
||||||
use super::{parent_service::ParentService, candidate_service::CandidateService, session_service::SessionService, portfolio_service::PortfolioService};
|
use super::{parent_service::ParentService, candidate_service::CandidateService, session_service::SessionService};
|
||||||
|
|
||||||
const FIELD_OF_STUDY_PREFIXES: [&str; 3] = ["101", "102", "103"];
|
const FIELD_OF_STUDY_PREFIXES: [&str; 3] = ["101", "102", "103"];
|
||||||
|
|
||||||
|
|
@ -140,24 +140,6 @@ impl ApplicationService {
|
||||||
FIELD_OF_STUDY_PREFIXES.contains(&field_of_study_prefix)
|
FIELD_OF_STUDY_PREFIXES.contains(&field_of_study_prefix)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn create_candidate_with_parent( // uchazeč s maminkou 👩🍼
|
|
||||||
db: &DbConn,
|
|
||||||
application: application::Model,
|
|
||||||
plain_text_password: &String,
|
|
||||||
personal_id_number: String,
|
|
||||||
) -> Result<(application::Model, candidate::Model, parent::Model), ServiceError> {
|
|
||||||
let candidate = CandidateService::create(db, personal_id_number).await?;
|
|
||||||
let parent = ParentService::create(db, candidate.id).await?;
|
|
||||||
let application = Mutation::update_candidate_fk(db, application, candidate.id).await?;
|
|
||||||
Ok(
|
|
||||||
(
|
|
||||||
application,
|
|
||||||
candidate,
|
|
||||||
parent
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn find_related_candidate(
|
pub async fn find_related_candidate(
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
application: &application::Model,
|
application: &application::Model,
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,13 @@
|
||||||
use async_trait::async_trait;
|
use entity::candidate;
|
||||||
use chrono::Duration;
|
use sea_orm::DbConn;
|
||||||
use entity::{candidate, session, application};
|
|
||||||
use sea_orm::{prelude::Uuid, DbConn, IntoActiveModel};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
models::{candidate_details::{EncryptedApplicationDetails, EncryptedString, EncryptedCandidateDetails}, candidate::CandidateDetails},
|
models::{candidate_details::EncryptedCandidateDetails, candidate::CandidateDetails},
|
||||||
crypto::{self, hash_password},
|
|
||||||
error::ServiceError,
|
error::ServiceError,
|
||||||
Mutation, Query, models::{candidate::{BaseCandidateResponse, CreateCandidateResponse}, auth::AuthenticableTrait}, utils::db::get_recipients,
|
Mutation, Query, models::candidate::BaseCandidateResponse,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::{session_service::SessionService, portfolio_service::PortfolioService};
|
use super::{portfolio_service::PortfolioService};
|
||||||
|
|
||||||
pub struct CandidateService;
|
pub struct CandidateService;
|
||||||
|
|
||||||
|
|
@ -93,7 +90,7 @@ pub mod tests {
|
||||||
|
|
||||||
use crate::models::candidate_details::tests::assert_all_application_details;
|
use crate::models::candidate_details::tests::assert_all_application_details;
|
||||||
use crate::utils::db::get_memory_sqlite_connection;
|
use crate::utils::db::get_memory_sqlite_connection;
|
||||||
use crate::{crypto, services::candidate_service::CandidateService, Mutation};
|
use crate::{crypto};
|
||||||
|
|
||||||
use crate::models::candidate_details::EncryptedApplicationDetails;
|
use crate::models::candidate_details::EncryptedApplicationDetails;
|
||||||
use entity::{application, candidate, parent, admin};
|
use entity::{application, candidate, parent, admin};
|
||||||
|
|
@ -172,7 +169,7 @@ pub mod tests {
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_put_user_data() {
|
async fn test_put_user_data() {
|
||||||
let db = get_memory_sqlite_connection().await;
|
let db = get_memory_sqlite_connection().await;
|
||||||
let (application, candidate, parents) = put_user_data(&db).await;
|
let (_, candidate, parents) = put_user_data(&db).await;
|
||||||
assert!(candidate.name.is_some());
|
assert!(candidate.name.is_some());
|
||||||
assert!(parents[0].name.is_some());
|
assert!(parents[0].name.is_some());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,9 +54,7 @@ mod tests {
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use crate::{utils::db::get_memory_sqlite_connection, models::{candidate::{ParentDetails, ApplicationDetails, CandidateDetails}, candidate_details::EncryptedApplicationDetails}, services::{candidate_service::CandidateService, application_service::ApplicationService}, crypto};
|
use crate::{utils::db::get_memory_sqlite_connection, models::{candidate::{ParentDetails, ApplicationDetails, CandidateDetails}}, services::{candidate_service::CandidateService}};
|
||||||
|
|
||||||
use super::ParentService;
|
|
||||||
|
|
||||||
pub static APPLICATION_DETAILS_TWO_PARENTS: Lazy<Mutex<ApplicationDetails>> = Lazy::new(||
|
pub static APPLICATION_DETAILS_TWO_PARENTS: Lazy<Mutex<ApplicationDetails>> = Lazy::new(||
|
||||||
Mutex::new(ApplicationDetails {
|
Mutex::new(ApplicationDetails {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue