feat: candidate delete

This commit is contained in:
Sebastian Pravda 2023-01-15 15:05:31 +01:00
parent 1ea7f36972
commit 72a1dbc38e
No known key found for this signature in database
GPG key ID: F3BC84F08EFA3F57
3 changed files with 26 additions and 5 deletions

View file

@ -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")]

View file

@ -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,

View file

@ -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 {