Files
Oxicloud/src/application/ports/outbound.rs
T

49 lines
2.0 KiB
Rust
Raw Normal View History

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
// Re-export domain repository traits for backward compatibility
pub use crate::domain::repositories::folder_repository::FolderRepository;
use super::storage_ports::{FileReadPort, FileWritePort};
/// Secondary port for storage operations
2025-03-19 00:44:27 +01:00
pub trait StoragePort: Send + Sync + 'static {
/// 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
/// 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
/// 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
/// 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>;
}
/// Unified port for file persistence (backward-compatible).
///
/// 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.
pub trait FileStoragePort: FileReadPort + FileWritePort {}
2025-03-19 00:44:27 +01:00
/// Blanket implementation: any type that implements both ports
/// is automatically a FileStoragePort.
impl<T: FileReadPort + FileWritePort> FileStoragePort for T {}
/// Secondary port for folder persistence (application layer).
///
/// Has the same signature as the domain's `FolderRepository`.
/// Concrete implementations must implement `FolderRepository`,
/// getting `FolderStoragePort` automatically via blanket impl.
pub trait FolderStoragePort: FolderRepository {}
/// Blanket implementation: any type that implements FolderRepository
/// is automatically a FolderStoragePort.
impl<T: FolderRepository> FolderStoragePort for T {}