use super::traits::ReadRelUoWFactory;
use crate::types::EntityId;
use anyhow::Result;
pub struct GetRelationshipCountUseCase<RF, F: ReadRelUoWFactory<RF>> {
uow_factory: F,
_phantom: std::marker::PhantomData<RF>,
}
impl<RF, F: ReadRelUoWFactory<RF>> GetRelationshipCountUseCase<RF, F> {
pub fn new(uow_factory: F) -> Self {
GetRelationshipCountUseCase {
uow_factory,
_phantom: std::marker::PhantomData,
}
}
pub fn execute(&self, id: &EntityId, field: &RF) -> Result<usize> {
let uow = self.uow_factory.create();
uow.begin_transaction()?;
let result = uow.get_relationship_count(id, field)?;
uow.end_transaction()?;
Ok(result)
}
}