diff --git a/mediarepo-daemon/mediarepo-logic/src/dao/tag/add_implication.rs b/mediarepo-daemon/mediarepo-logic/src/dao/tag/add_implications.rs similarity index 100% rename from mediarepo-daemon/mediarepo-logic/src/dao/tag/add_implication.rs rename to mediarepo-daemon/mediarepo-logic/src/dao/tag/add_implications.rs diff --git a/mediarepo-daemon/mediarepo-logic/src/dao/tag/delete_implications.rs b/mediarepo-daemon/mediarepo-logic/src/dao/tag/delete_implications.rs new file mode 100644 index 0000000..a9f2ee6 --- /dev/null +++ b/mediarepo-daemon/mediarepo-logic/src/dao/tag/delete_implications.rs @@ -0,0 +1,28 @@ +use mediarepo_core::error::RepoResult; +use mediarepo_database::entities::tag_implication; +use sea_orm::{prelude::*, Condition}; + +use crate::dto::TagImplicationDto; + +use super::TagDao; + +impl TagDao { + pub async fn delete_implications( + &self, + implications: Vec, + ) -> RepoResult<()> { + let filter_condition = implications + .into_iter() + .map(|i| { + Condition::all() + .add(tag_implication::Column::TagId.eq(i.tag_id())) + .add(tag_implication::Column::ImpliedTagId.eq(i.implied_tag_id())) + }) + .fold(Condition::any(), |acc, val| acc.add(val)); + tag_implication::Entity::delete_many() + .filter(filter_condition) + .exec(&self.ctx.db) + .await?; + Ok(()) + } +} diff --git a/mediarepo-daemon/mediarepo-logic/src/dao/tag/mod.rs b/mediarepo-daemon/mediarepo-logic/src/dao/tag/mod.rs index 061a1eb..b98cb97 100644 --- a/mediarepo-daemon/mediarepo-logic/src/dao/tag/mod.rs +++ b/mediarepo-daemon/mediarepo-logic/src/dao/tag/mod.rs @@ -14,10 +14,11 @@ use crate::dao_provider; use crate::dto::{NamespaceDto, TagDto}; pub mod add; -pub mod add_implication; +pub mod add_implications; pub mod all_for_cds_map; pub mod by_name; pub mod cdids_with_namespaced_tags; +pub mod delete_implications; pub mod mappings; dao_provider!(TagDao);