Skip to main content

ito_domain/modules/
repository.rs

1//! Module repository port definitions.
2
3use super::{Module, ModuleSummary, SubModule, SubModuleSummary};
4use crate::errors::{DomainError, DomainResult};
5
6/// Port for accessing module data.
7///
8/// Domain and adapters should depend on this interface rather than concrete
9/// storage details.
10pub trait ModuleRepository {
11    /// Check if a module exists.
12    fn exists(&self, id: &str) -> bool;
13
14    /// Get a module by ID or full name.
15    fn get(&self, id_or_name: &str) -> DomainResult<Module>;
16
17    /// List all modules.
18    fn list(&self) -> DomainResult<Vec<ModuleSummary>>;
19
20    /// List all sub-modules belonging to a parent module.
21    ///
22    /// `parent_id` is the parent module identifier (e.g., `"024"`).
23    ///
24    /// The default implementation returns a not-found error so that existing
25    /// implementors do not need to be updated immediately.
26    fn list_sub_modules(&self, parent_id: &str) -> DomainResult<Vec<SubModuleSummary>> {
27        Err(DomainError::not_found("sub-module", parent_id))
28    }
29
30    /// Get a sub-module by its composite identifier (e.g., `"024.01"`).
31    ///
32    /// The default implementation returns a not-found error so that existing
33    /// implementors do not need to be updated immediately.
34    fn get_sub_module(&self, composite_id: &str) -> DomainResult<SubModule> {
35        Err(DomainError::not_found("sub-module", composite_id))
36    }
37}