Initial commit

This commit is contained in:
root
2025-03-17 21:28:08 +01:00
commit fe19bc8505
58 changed files with 7202 additions and 0 deletions
@@ -0,0 +1,72 @@
use std::path::PathBuf;
use async_trait::async_trait;
use crate::domain::entities::file::File;
/// Error types for file repository operations
#[derive(Debug, thiserror::Error)]
#[allow(dead_code)]
pub enum FileRepositoryError {
#[error("File not found: {0}")]
NotFound(String),
#[error("File already exists: {0}")]
AlreadyExists(String),
#[error("Invalid file path: {0}")]
InvalidPath(String),
#[error("IO Error: {0}")]
IoError(#[from] std::io::Error),
#[error("Other error: {0}")]
Other(String),
}
/// Result type for file repository operations
pub type FileRepositoryResult<T> = Result<T, FileRepositoryError>;
/// Repository interface for file operations (primary port)
#[async_trait]
pub trait FileRepository: Send + Sync + 'static {
/// Gets a folder by its ID - helper method for file repository to work with folders
#[allow(dead_code)]
async fn get_folder_by_id(&self, id: &str) -> FileRepositoryResult<crate::domain::entities::folder::Folder>;
/// Saves a file from bytes
async fn save_file_from_bytes(
&self,
name: String,
folder_id: Option<String>,
content_type: String,
content: Vec<u8>,
) -> FileRepositoryResult<File>;
/// Saves a file with a specific ID
#[allow(dead_code)]
async fn save_file_with_id(
&self,
id: String,
name: String,
folder_id: Option<String>,
content_type: String,
content: Vec<u8>,
) -> FileRepositoryResult<File>;
/// Gets a file by its ID
async fn get_file_by_id(&self, id: &str) -> FileRepositoryResult<File>;
/// Lists files in a folder
async fn list_files(&self, folder_id: Option<&str>) -> FileRepositoryResult<Vec<File>>;
/// Deletes a file
async fn delete_file(&self, id: &str) -> FileRepositoryResult<()>;
/// Deletes a file and its entry from the map
#[allow(dead_code)]
async fn delete_file_entry(&self, id: &str) -> FileRepositoryResult<()>;
/// Gets file content as bytes
async fn get_file_content(&self, id: &str) -> FileRepositoryResult<Vec<u8>>;
/// Checks if a file exists at the given path
async fn file_exists(&self, path: &PathBuf) -> FileRepositoryResult<bool>;
}
@@ -0,0 +1,54 @@
use std::path::PathBuf;
use async_trait::async_trait;
use crate::domain::entities::folder::Folder;
/// Error types for folder repository operations
#[derive(Debug, thiserror::Error)]
#[allow(dead_code)]
pub enum FolderRepositoryError {
#[error("Folder not found: {0}")]
NotFound(String),
#[error("Folder already exists: {0}")]
AlreadyExists(String),
#[error("Invalid folder path: {0}")]
InvalidPath(String),
#[error("IO Error: {0}")]
IoError(#[from] std::io::Error),
#[error("Other error: {0}")]
Other(String),
}
/// Result type for folder repository operations
pub type FolderRepositoryResult<T> = Result<T, FolderRepositoryError>;
/// Repository interface for folder operations (primary port)
#[async_trait]
pub trait FolderRepository: Send + Sync + 'static {
/// Creates a new folder
async fn create_folder(&self, name: String, parent_path: Option<PathBuf>) -> FolderRepositoryResult<Folder>;
/// Gets a folder by its ID
async fn get_folder_by_id(&self, id: &str) -> FolderRepositoryResult<Folder>;
/// Gets a folder by its path
async fn get_folder_by_path(&self, path: &PathBuf) -> FolderRepositoryResult<Folder>;
/// Lists folders in a parent folder
async fn list_folders(&self, parent_id: Option<&str>) -> FolderRepositoryResult<Vec<Folder>>;
/// Renames a folder
async fn rename_folder(&self, id: &str, new_name: String) -> FolderRepositoryResult<Folder>;
/// Moves a folder to a new parent
async fn move_folder(&self, id: &str, new_parent_id: Option<&str>) -> FolderRepositoryResult<Folder>;
/// Deletes a folder
async fn delete_folder(&self, id: &str) -> FolderRepositoryResult<()>;
/// Checks if a folder exists at the given path
async fn folder_exists(&self, path: &PathBuf) -> FolderRepositoryResult<bool>;
}
+3
View File
@@ -0,0 +1,3 @@
pub mod file_repository;
pub mod folder_repository;