2026-02-14 01:29:34 +01:00
|
|
|
use std::path::PathBuf;
|
2025-03-19 00:44:27 +01:00
|
|
|
|
|
|
|
|
use crate::common::errors::DomainError;
|
2026-02-14 01:29:34 +01:00
|
|
|
use crate::domain::services::path_service::StoragePath;
|
2025-03-19 00:44:27 +01:00
|
|
|
|
2026-02-08 13:40:23 +01:00
|
|
|
// Re-export domain repository traits for backward compatibility
|
|
|
|
|
pub use crate::domain::repositories::folder_repository::FolderRepository;
|
|
|
|
|
|
|
|
|
|
use super::storage_ports::{FileReadPort, FileWritePort};
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Secondary port for storage operations
|
2025-03-19 00:44:27 +01:00
|
|
|
pub trait StoragePort: Send + Sync + 'static {
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Resolves a domain path to a physical path
|
2025-03-19 00:44:27 +01:00
|
|
|
fn resolve_path(&self, storage_path: &StoragePath) -> PathBuf;
|
2026-02-14 01:29:34 +01:00
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Creates directories if they don't exist
|
2025-03-19 00:44:27 +01:00
|
|
|
async fn ensure_directory(&self, storage_path: &StoragePath) -> Result<(), DomainError>;
|
2026-02-14 01:29:34 +01:00
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Checks if a file exists at the given path
|
2025-03-19 00:44:27 +01:00
|
|
|
async fn file_exists(&self, storage_path: &StoragePath) -> Result<bool, DomainError>;
|
2026-02-14 01:29:34 +01:00
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Checks if a directory exists at the given path
|
2025-03-19 00:44:27 +01:00
|
|
|
async fn directory_exists(&self, storage_path: &StoragePath) -> Result<bool, DomainError>;
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Unified port for file persistence (backward-compatible).
|
2026-02-08 13:40:23 +01:00
|
|
|
///
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Now it is a **supertrait** of `FileReadPort + FileWritePort`.
|
|
|
|
|
/// Any type that implements both ports gets `FileStoragePort`
|
|
|
|
|
/// automatically via blanket impl. This allows consumers to be migrated
|
|
|
|
|
/// gradually to granular ports while existing ones continue
|
|
|
|
|
/// working without changes.
|
2026-02-08 13:40:23 +01:00
|
|
|
pub trait FileStoragePort: FileReadPort + FileWritePort {}
|
2025-03-19 00:44:27 +01:00
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Blanket implementation: any type that implements both ports
|
|
|
|
|
/// is automatically a FileStoragePort.
|
2026-02-08 13:40:23 +01:00
|
|
|
impl<T: FileReadPort + FileWritePort> FileStoragePort for T {}
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Secondary port for folder persistence (application layer).
|
2026-02-08 13:40:23 +01:00
|
|
|
///
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Has the same signature as the domain's `FolderRepository`.
|
|
|
|
|
/// Concrete implementations must implement `FolderRepository`,
|
|
|
|
|
/// getting `FolderStoragePort` automatically via blanket impl.
|
2026-02-08 13:40:23 +01:00
|
|
|
pub trait FolderStoragePort: FolderRepository {}
|
|
|
|
|
|
2026-02-12 09:41:25 +01:00
|
|
|
/// Blanket implementation: any type that implements FolderRepository
|
|
|
|
|
/// is automatically a FolderStoragePort.
|
2026-02-08 13:40:23 +01:00
|
|
|
impl<T: FolderRepository> FolderStoragePort for T {}
|