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