mirror of
https://github.com/danbulant/Portfolio
synced 2026-07-05 02:50:47 +00:00
feat: candidate delete
This commit is contained in:
parent
1ea7f36972
commit
72a1dbc38e
3 changed files with 26 additions and 5 deletions
|
|
@ -192,11 +192,16 @@ pub async fn delete_candidate(
|
||||||
.ok_or(to_custom_error(ServiceError::CandidateNotFound))?;
|
.ok_or(to_custom_error(ServiceError::CandidateNotFound))?;
|
||||||
let candidate = ApplicationService::find_related_candidate(db, &application).await.map_err(to_custom_error)?;
|
let candidate = ApplicationService::find_related_candidate(db, &application).await.map_err(to_custom_error)?;
|
||||||
|
|
||||||
// TODO
|
ApplicationService::delete(db, application).await.map_err(to_custom_error)?;
|
||||||
|
|
||||||
|
let remaining_applications = Query::find_applications_by_candidate_id(db, candidate.id).await
|
||||||
|
.map_err(|e| to_custom_error(ServiceError::DbError(e)))?;
|
||||||
|
|
||||||
|
if remaining_applications.is_empty() {
|
||||||
|
CandidateService::delete_candidate(db, candidate).await.map_err(to_custom_error)?;
|
||||||
|
}
|
||||||
|
|
||||||
CandidateService::delete_candidate(db, candidate)
|
Ok(())
|
||||||
.await
|
|
||||||
.map_err(to_custom_error)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[post("/candidate/<id>/reset_password")]
|
#[post("/candidate/<id>/reset_password")]
|
||||||
|
|
|
||||||
|
|
@ -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, IntoActiveModel};
|
use sea_orm::{DbConn, DbErr, Set, ActiveModelTrait, IntoActiveModel, DeleteResult, ModelTrait};
|
||||||
|
|
||||||
use crate::Mutation;
|
use crate::Mutation;
|
||||||
|
|
||||||
|
|
@ -32,6 +32,17 @@ impl Mutation {
|
||||||
Ok(insert)
|
Ok(insert)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn delete_application(
|
||||||
|
db: &DbConn,
|
||||||
|
application: application::Model,
|
||||||
|
) -> Result<DeleteResult, DbErr> {
|
||||||
|
let application_id = application.id;
|
||||||
|
let delete = application.delete(db).await?;
|
||||||
|
|
||||||
|
warn!("APPLICATION {} DELETED", application_id);
|
||||||
|
Ok(delete)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn update_candidate_fk(
|
pub async fn update_candidate_fk(
|
||||||
db: &DbConn,
|
db: &DbConn,
|
||||||
application: application::Model,
|
application: application::Model,
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,11 @@ impl ApplicationService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn delete(db: &DbConn, application: application::Model) -> Result<(), ServiceError> {
|
||||||
|
Mutation::delete_application(db, application).await?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn is_application_id_valid(application_id: i32) -> bool {
|
fn is_application_id_valid(application_id: i32) -> bool {
|
||||||
let s = &application_id.to_string();
|
let s = &application_id.to_string();
|
||||||
if s.len() <= 3 {
|
if s.len() <= 3 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue