mirror of
https://github.com/danbulant/Portfolio
synced 2026-06-17 21:41:20 +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))?;
|
||||
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)
|
||||
.await
|
||||
.map_err(to_custom_error)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[post("/candidate/<id>/reset_password")]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use ::entity::application;
|
||||
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;
|
||||
|
||||
|
|
@ -32,6 +32,17 @@ impl Mutation {
|
|||
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(
|
||||
db: &DbConn,
|
||||
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 {
|
||||
let s = &application_id.to_string();
|
||||
if s.len() <= 3 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue