text_document_common/direct_access/use_cases/
get_relationship_count.rs1use super::traits::ReadRelUoWFactory;
4use crate::types::EntityId;
5use anyhow::Result;
6
7pub struct GetRelationshipCountUseCase<RF, F: ReadRelUoWFactory<RF>> {
8 uow_factory: F,
9 _phantom: std::marker::PhantomData<RF>,
10}
11
12impl<RF, F: ReadRelUoWFactory<RF>> GetRelationshipCountUseCase<RF, F> {
13 pub fn new(uow_factory: F) -> Self {
14 GetRelationshipCountUseCase {
15 uow_factory,
16 _phantom: std::marker::PhantomData,
17 }
18 }
19
20 pub fn execute(&self, id: &EntityId, field: &RF) -> Result<usize> {
21 let uow = self.uow_factory.create();
22 uow.begin_transaction()?;
23 let result = uow.get_relationship_count(id, field)?;
24 uow.end_transaction()?;
25 Ok(result)
26 }
27}