text-document-common 1.4.0

Shared entities, database, events, and undo/redo infrastructure for text-document
Documentation
// Generated by Qleany v1.4.8 from common_da_use_cases_get_relationship_many.tera

use super::traits::ReadRelUoWFactory;
use crate::types::EntityId;
use anyhow::Result;
use std::collections::HashMap;

pub struct GetRelationshipManyUseCase<RF, F: ReadRelUoWFactory<RF>> {
    uow_factory: F,
    _phantom: std::marker::PhantomData<RF>,
}

impl<RF, F: ReadRelUoWFactory<RF>> GetRelationshipManyUseCase<RF, F> {
    pub fn new(uow_factory: F) -> Self {
        GetRelationshipManyUseCase {
            uow_factory,
            _phantom: std::marker::PhantomData,
        }
    }

    pub fn execute(
        &self,
        ids: &[EntityId],
        field: &RF,
    ) -> Result<HashMap<EntityId, Vec<EntityId>>> {
        let uow = self.uow_factory.create();
        uow.begin_transaction()?;
        let result = uow.get_relationship_many(ids, field)?;
        uow.end_transaction()?;
        Ok(result)
    }
}