//! Memory use-case implementation. //! //! `MemoryServiceImpl` implements [`MemoryService`] from the domain //! layer. It is generic over `R: MemoryRepository`, delegating all //! persistence to that adapter. //! //! # Flow //! //! Each method delegates to the injected `repo` with the configured //! `memory_dir`. Error context is added at this layer to identify which //! memory operation failed. use std::path::PathBuf; use tracing; use zesdex_domain::cms::{Memory, MemoryRepository, ServiceError}; /// Service implementation for memory CRUD operations. /// /// Generic over `R: MemoryRepository` so the persistence layer can be /// swapped without changing business logic. pub struct MemoryServiceImpl { pub repo: R, /// Base directory for memory storage files. pub memory_dir: PathBuf, } impl MemoryServiceImpl { /// Create a new service with the given repository and memory directory. pub fn new(repo: R, memory_dir: impl Into) -> Self { tracing::debug!("creating MemoryServiceImpl"); Self { repo, memory_dir: memory_dir.into(), } } } impl zesdex_domain::cms::MemoryService for MemoryServiceImpl { fn list_memories(&self) -> Result, ServiceError> { tracing::debug!("listing memories from {:?}", self.memory_dir); self.repo .list(&self.memory_dir) .map_err(ServiceError::Repository) } fn save_memory(&self, memory: &Memory) -> Result<(), ServiceError> { tracing::debug!("saving memory '{}'", memory.name); self.repo.save(&self.memory_dir, memory)?; Ok(()) } fn delete_memory(&self, name: &str) -> Result<(), ServiceError> { tracing::debug!("deleting memory '{name}'"); self.repo .delete(&self.memory_dir, name) .map_err(ServiceError::Repository) } }