Add dao method to delete tag implications

Signed-off-by: trivernis <trivernis@protonmail.com>
feature/tag-implications
trivernis 2 years ago
parent d0dfa2b638
commit 42396f2174
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -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<TagImplicationDto>,
) -> 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(())
}
}

@ -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);

Loading…
Cancel
Save