adding user authentication
This commit is contained in:
+517
-1
@@ -1,6 +1,10 @@
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use std::sync::RwLock;
|
||||
use sqlx::PgPool;
|
||||
|
||||
use crate::domain::services::auth_service::AuthService;
|
||||
use crate::application::services::auth_application_service::AuthApplicationService;
|
||||
|
||||
use crate::domain::services::path_service::PathService;
|
||||
use crate::infrastructure::repositories::folder_fs_repository::FolderFsRepository;
|
||||
@@ -224,7 +228,7 @@ impl AppServiceFactory {
|
||||
pub struct CoreServices {
|
||||
pub path_service: Arc<PathService>,
|
||||
pub cache_manager: Arc<StorageCacheManager>,
|
||||
pub id_mapping_service: Arc<IdMappingService>,
|
||||
pub id_mapping_service: Arc<dyn crate::application::ports::outbound::IdMappingPort>,
|
||||
pub config: AppConfig,
|
||||
}
|
||||
|
||||
@@ -251,4 +255,516 @@ pub struct ApplicationServices {
|
||||
pub file_management_service: Arc<dyn FileManagementUseCase>,
|
||||
pub file_use_case_factory: Arc<dyn FileUseCaseFactory>,
|
||||
pub i18n_service: Arc<I18nApplicationService>,
|
||||
}
|
||||
|
||||
/// Contenedor para servicios de autenticación
|
||||
#[allow(dead_code)]
|
||||
pub struct AuthServices {
|
||||
pub auth_service: Arc<AuthService>,
|
||||
pub auth_application_service: Arc<AuthApplicationService>,
|
||||
}
|
||||
|
||||
/// Estado global de la aplicación para dependency injection
|
||||
pub struct AppState {
|
||||
pub core: CoreServices,
|
||||
pub repositories: RepositoryServices,
|
||||
pub applications: ApplicationServices,
|
||||
pub db_pool: Option<Arc<PgPool>>,
|
||||
pub auth_service: Option<AuthServices>,
|
||||
}
|
||||
|
||||
impl Default for AppState {
|
||||
fn default() -> Self {
|
||||
// This is just a minimal stub version for auth middleware
|
||||
// We'll need to create proper instance in main.rs
|
||||
|
||||
let config = crate::common::config::AppConfig::default();
|
||||
let path_service = Arc::new(
|
||||
crate::domain::services::path_service::PathService::new(
|
||||
std::path::PathBuf::from("./storage")
|
||||
)
|
||||
);
|
||||
|
||||
// Create stub service implementations
|
||||
struct DummyIdMappingService;
|
||||
#[async_trait::async_trait]
|
||||
impl crate::application::ports::outbound::IdMappingPort for DummyIdMappingService {
|
||||
async fn get_or_create_id(&self, _path: &crate::domain::services::path_service::StoragePath) -> Result<String, crate::common::errors::DomainError> {
|
||||
Ok("dummy-id".to_string())
|
||||
}
|
||||
|
||||
async fn get_path_by_id(&self, _id: &str) -> Result<crate::domain::services::path_service::StoragePath, crate::common::errors::DomainError> {
|
||||
Ok(crate::domain::services::path_service::StoragePath::from_string("/"))
|
||||
}
|
||||
|
||||
async fn update_path(&self, _id: &str, _new_path: &crate::domain::services::path_service::StoragePath) -> Result<(), crate::common::errors::DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn remove_id(&self, _id: &str) -> Result<(), crate::common::errors::DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn save_changes(&self) -> Result<(), crate::common::errors::DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct DummyStorageMediator;
|
||||
#[async_trait::async_trait]
|
||||
impl crate::application::services::storage_mediator::StorageMediator for DummyStorageMediator {
|
||||
async fn get_folder_path(&self, _folder_id: &str) -> Result<std::path::PathBuf, crate::application::services::storage_mediator::StorageMediatorError> {
|
||||
Ok(std::path::PathBuf::from("/tmp"))
|
||||
}
|
||||
|
||||
async fn get_folder_storage_path(&self, _folder_id: &str) -> Result<crate::domain::services::path_service::StoragePath, crate::application::services::storage_mediator::StorageMediatorError> {
|
||||
Ok(crate::domain::services::path_service::StoragePath::root())
|
||||
}
|
||||
|
||||
async fn get_folder(&self, _folder_id: &str) -> Result<crate::domain::entities::folder::Folder, crate::application::services::storage_mediator::StorageMediatorError> {
|
||||
Err(crate::application::services::storage_mediator::StorageMediatorError::NotFound("Stub not implemented".to_string()))
|
||||
}
|
||||
|
||||
async fn file_exists_at_path(&self, _path: &std::path::Path) -> Result<bool, crate::application::services::storage_mediator::StorageMediatorError> {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
async fn file_exists_at_storage_path(&self, _storage_path: &crate::domain::services::path_service::StoragePath) -> Result<bool, crate::application::services::storage_mediator::StorageMediatorError> {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
async fn folder_exists_at_path(&self, _path: &std::path::Path) -> Result<bool, crate::application::services::storage_mediator::StorageMediatorError> {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
async fn folder_exists_at_storage_path(&self, _storage_path: &crate::domain::services::path_service::StoragePath) -> Result<bool, crate::application::services::storage_mediator::StorageMediatorError> {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
fn resolve_path(&self, _relative_path: &std::path::Path) -> std::path::PathBuf {
|
||||
std::path::PathBuf::from("/tmp")
|
||||
}
|
||||
|
||||
fn resolve_storage_path(&self, _storage_path: &crate::domain::services::path_service::StoragePath) -> std::path::PathBuf {
|
||||
std::path::PathBuf::from("/tmp")
|
||||
}
|
||||
|
||||
async fn ensure_directory(&self, _path: &std::path::Path) -> Result<(), crate::application::services::storage_mediator::StorageMediatorError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn ensure_storage_directory(&self, _storage_path: &crate::domain::services::path_service::StoragePath) -> Result<(), crate::application::services::storage_mediator::StorageMediatorError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct DummyFileReadPort;
|
||||
#[async_trait::async_trait]
|
||||
impl crate::application::ports::storage_ports::FileReadPort for DummyFileReadPort {
|
||||
async fn get_file(&self, _id: &str) -> Result<crate::domain::entities::file::File, crate::common::errors::DomainError> {
|
||||
Ok(crate::domain::entities::file::File::default())
|
||||
}
|
||||
|
||||
async fn list_files(&self, _folder_id: Option<&str>) -> Result<Vec<crate::domain::entities::file::File>, crate::common::errors::DomainError> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
async fn get_file_content(&self, _id: &str) -> Result<Vec<u8>, crate::common::errors::DomainError> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
async fn get_file_stream(&self, _id: &str) -> Result<Box<dyn futures::Stream<Item = Result<bytes::Bytes, std::io::Error>> + Send>, crate::common::errors::DomainError> {
|
||||
let empty_stream = futures::stream::empty::<Result<bytes::Bytes, std::io::Error>>();
|
||||
Ok(Box::new(empty_stream))
|
||||
}
|
||||
}
|
||||
|
||||
struct DummyFileWritePort;
|
||||
#[async_trait::async_trait]
|
||||
impl crate::application::ports::storage_ports::FileWritePort for DummyFileWritePort {
|
||||
async fn save_file(
|
||||
&self,
|
||||
_name: String,
|
||||
_folder_id: Option<String>,
|
||||
_content_type: String,
|
||||
_content: Vec<u8>,
|
||||
) -> Result<crate::domain::entities::file::File, crate::common::errors::DomainError> {
|
||||
Ok(crate::domain::entities::file::File::default())
|
||||
}
|
||||
|
||||
async fn move_file(&self, _file_id: &str, _target_folder_id: Option<String>) -> Result<crate::domain::entities::file::File, crate::common::errors::DomainError> {
|
||||
Ok(crate::domain::entities::file::File::default())
|
||||
}
|
||||
|
||||
async fn delete_file(&self, _id: &str) -> Result<(), crate::common::errors::DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct DummyFileStoragePort;
|
||||
#[async_trait::async_trait]
|
||||
impl crate::application::ports::outbound::FileStoragePort for DummyFileStoragePort {
|
||||
async fn save_file(
|
||||
&self,
|
||||
_name: String,
|
||||
_folder_id: Option<String>,
|
||||
_content_type: String,
|
||||
_content: Vec<u8>,
|
||||
) -> Result<crate::domain::entities::file::File, crate::common::errors::DomainError> {
|
||||
Ok(crate::domain::entities::file::File::default())
|
||||
}
|
||||
|
||||
async fn get_file(&self, _id: &str) -> Result<crate::domain::entities::file::File, crate::common::errors::DomainError> {
|
||||
Ok(crate::domain::entities::file::File::default())
|
||||
}
|
||||
|
||||
async fn list_files(&self, _folder_id: Option<&str>) -> Result<Vec<crate::domain::entities::file::File>, crate::common::errors::DomainError> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
async fn delete_file(&self, _id: &str) -> Result<(), crate::common::errors::DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_file_content(&self, _id: &str) -> Result<Vec<u8>, crate::common::errors::DomainError> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
async fn get_file_stream(&self, _id: &str) -> Result<Box<dyn futures::Stream<Item = Result<bytes::Bytes, std::io::Error>> + Send>, crate::common::errors::DomainError> {
|
||||
let empty_stream = futures::stream::empty::<Result<bytes::Bytes, std::io::Error>>();
|
||||
Ok(Box::new(empty_stream))
|
||||
}
|
||||
|
||||
async fn move_file(&self, _file_id: &str, _target_folder_id: Option<String>) -> Result<crate::domain::entities::file::File, crate::common::errors::DomainError> {
|
||||
Ok(crate::domain::entities::file::File::default())
|
||||
}
|
||||
|
||||
async fn get_file_path(&self, _id: &str) -> Result<crate::domain::services::path_service::StoragePath, crate::common::errors::DomainError> {
|
||||
Ok(crate::domain::services::path_service::StoragePath::from_string("/"))
|
||||
}
|
||||
}
|
||||
|
||||
struct DummyFolderStoragePort;
|
||||
#[async_trait::async_trait]
|
||||
impl crate::application::ports::outbound::FolderStoragePort for DummyFolderStoragePort {
|
||||
async fn create_folder(&self, _name: String, _parent_id: Option<String>) -> Result<crate::domain::entities::folder::Folder, crate::common::errors::DomainError> {
|
||||
Ok(crate::domain::entities::folder::Folder::default())
|
||||
}
|
||||
|
||||
async fn get_folder(&self, _id: &str) -> Result<crate::domain::entities::folder::Folder, crate::common::errors::DomainError> {
|
||||
Ok(crate::domain::entities::folder::Folder::default())
|
||||
}
|
||||
|
||||
async fn get_folder_by_path(&self, _storage_path: &crate::domain::services::path_service::StoragePath) -> Result<crate::domain::entities::folder::Folder, crate::common::errors::DomainError> {
|
||||
Ok(crate::domain::entities::folder::Folder::default())
|
||||
}
|
||||
|
||||
async fn list_folders(&self, _parent_id: Option<&str>) -> Result<Vec<crate::domain::entities::folder::Folder>, crate::common::errors::DomainError> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
async fn list_folders_paginated(
|
||||
&self,
|
||||
_parent_id: Option<&str>,
|
||||
_offset: usize,
|
||||
_limit: usize,
|
||||
_include_total: bool
|
||||
) -> Result<(Vec<crate::domain::entities::folder::Folder>, Option<usize>), crate::common::errors::DomainError> {
|
||||
Ok((Vec::new(), Some(0)))
|
||||
}
|
||||
|
||||
async fn rename_folder(&self, _id: &str, _new_name: String) -> Result<crate::domain::entities::folder::Folder, crate::common::errors::DomainError> {
|
||||
Ok(crate::domain::entities::folder::Folder::default())
|
||||
}
|
||||
|
||||
async fn move_folder(&self, _id: &str, _new_parent_id: Option<&str>) -> Result<crate::domain::entities::folder::Folder, crate::common::errors::DomainError> {
|
||||
Ok(crate::domain::entities::folder::Folder::default())
|
||||
}
|
||||
|
||||
async fn delete_folder(&self, _id: &str) -> Result<(), crate::common::errors::DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn folder_exists(&self, _storage_path: &crate::domain::services::path_service::StoragePath) -> Result<bool, crate::common::errors::DomainError> {
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
async fn get_folder_path(&self, _id: &str) -> Result<crate::domain::services::path_service::StoragePath, crate::common::errors::DomainError> {
|
||||
Ok(crate::domain::services::path_service::StoragePath::from_string("/"))
|
||||
}
|
||||
}
|
||||
|
||||
struct DummyFilePathResolutionPort;
|
||||
#[async_trait::async_trait]
|
||||
impl crate::application::ports::storage_ports::FilePathResolutionPort for DummyFilePathResolutionPort {
|
||||
async fn get_file_path(&self, _id: &str) -> Result<crate::domain::services::path_service::StoragePath, crate::common::errors::DomainError> {
|
||||
Ok(crate::domain::services::path_service::StoragePath::from_string("/"))
|
||||
}
|
||||
|
||||
fn resolve_path(&self, _storage_path: &crate::domain::services::path_service::StoragePath) -> std::path::PathBuf {
|
||||
std::path::PathBuf::from("/")
|
||||
}
|
||||
}
|
||||
|
||||
struct DummyI18nService;
|
||||
#[async_trait::async_trait]
|
||||
impl crate::domain::services::i18n_service::I18nService for DummyI18nService {
|
||||
async fn translate(&self, _key: &str, _locale: crate::domain::services::i18n_service::Locale) -> crate::domain::services::i18n_service::I18nResult<String> {
|
||||
Ok(String::new())
|
||||
}
|
||||
|
||||
async fn load_translations(&self, _locale: crate::domain::services::i18n_service::Locale) -> crate::domain::services::i18n_service::I18nResult<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn available_locales(&self) -> Vec<crate::domain::services::i18n_service::Locale> {
|
||||
vec![crate::domain::services::i18n_service::Locale::default()]
|
||||
}
|
||||
|
||||
async fn is_supported(&self, _locale: crate::domain::services::i18n_service::Locale) -> bool {
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
struct DummyFolderUseCase;
|
||||
#[async_trait::async_trait]
|
||||
impl crate::application::ports::inbound::FolderUseCase for DummyFolderUseCase {
|
||||
async fn create_folder(&self, _dto: crate::application::dtos::folder_dto::CreateFolderDto) -> Result<crate::application::dtos::folder_dto::FolderDto, crate::common::errors::DomainError> {
|
||||
Ok(crate::application::dtos::folder_dto::FolderDto::default())
|
||||
}
|
||||
|
||||
async fn get_folder(&self, _id: &str) -> Result<crate::application::dtos::folder_dto::FolderDto, crate::common::errors::DomainError> {
|
||||
Ok(crate::application::dtos::folder_dto::FolderDto::default())
|
||||
}
|
||||
|
||||
async fn get_folder_by_path(&self, _path: &str) -> Result<crate::application::dtos::folder_dto::FolderDto, crate::common::errors::DomainError> {
|
||||
Ok(crate::application::dtos::folder_dto::FolderDto::default())
|
||||
}
|
||||
|
||||
async fn list_folders(&self, _parent_id: Option<&str>) -> Result<Vec<crate::application::dtos::folder_dto::FolderDto>, crate::common::errors::DomainError> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
async fn list_folders_paginated(
|
||||
&self,
|
||||
_parent_id: Option<&str>,
|
||||
_pagination: &crate::application::dtos::pagination::PaginationRequestDto
|
||||
) -> Result<crate::application::dtos::pagination::PaginatedResponseDto<crate::application::dtos::folder_dto::FolderDto>, crate::common::errors::DomainError> {
|
||||
Ok(crate::application::dtos::pagination::PaginatedResponseDto::new(
|
||||
Vec::new(),
|
||||
0,
|
||||
10,
|
||||
0
|
||||
))
|
||||
}
|
||||
|
||||
async fn rename_folder(&self, _id: &str, _dto: crate::application::dtos::folder_dto::RenameFolderDto) -> Result<crate::application::dtos::folder_dto::FolderDto, crate::common::errors::DomainError> {
|
||||
Ok(crate::application::dtos::folder_dto::FolderDto::default())
|
||||
}
|
||||
|
||||
async fn move_folder(&self, _id: &str, _dto: crate::application::dtos::folder_dto::MoveFolderDto) -> Result<crate::application::dtos::folder_dto::FolderDto, crate::common::errors::DomainError> {
|
||||
Ok(crate::application::dtos::folder_dto::FolderDto::default())
|
||||
}
|
||||
|
||||
async fn delete_folder(&self, _id: &str) -> Result<(), crate::common::errors::DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct DummyFileUseCase;
|
||||
#[async_trait::async_trait]
|
||||
impl crate::application::ports::inbound::FileUseCase for DummyFileUseCase {
|
||||
async fn upload_file(
|
||||
&self,
|
||||
_name: String,
|
||||
_folder_id: Option<String>,
|
||||
_content_type: String,
|
||||
_content: Vec<u8>,
|
||||
) -> Result<crate::application::dtos::file_dto::FileDto, crate::common::errors::DomainError> {
|
||||
Ok(crate::application::dtos::file_dto::FileDto::default())
|
||||
}
|
||||
|
||||
async fn get_file(&self, _id: &str) -> Result<crate::application::dtos::file_dto::FileDto, crate::common::errors::DomainError> {
|
||||
Ok(crate::application::dtos::file_dto::FileDto::default())
|
||||
}
|
||||
|
||||
async fn list_files(&self, _folder_id: Option<&str>) -> Result<Vec<crate::application::dtos::file_dto::FileDto>, crate::common::errors::DomainError> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
async fn delete_file(&self, _id: &str) -> Result<(), crate::common::errors::DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_file_content(&self, _id: &str) -> Result<Vec<u8>, crate::common::errors::DomainError> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
async fn get_file_stream(&self, _id: &str) -> Result<Box<dyn futures::Stream<Item = Result<bytes::Bytes, std::io::Error>> + Send>, crate::common::errors::DomainError> {
|
||||
// Create an empty stream
|
||||
let empty_stream = futures::stream::empty::<Result<bytes::Bytes, std::io::Error>>();
|
||||
Ok(Box::new(empty_stream))
|
||||
}
|
||||
|
||||
async fn move_file(&self, _file_id: &str, _folder_id: Option<String>) -> Result<crate::application::dtos::file_dto::FileDto, crate::common::errors::DomainError> {
|
||||
Ok(crate::application::dtos::file_dto::FileDto::default())
|
||||
}
|
||||
}
|
||||
|
||||
struct DummyFileUploadUseCase;
|
||||
#[async_trait::async_trait]
|
||||
impl crate::application::ports::file_ports::FileUploadUseCase for DummyFileUploadUseCase {
|
||||
async fn upload_file(
|
||||
&self,
|
||||
_name: String,
|
||||
_folder_id: Option<String>,
|
||||
_content_type: String,
|
||||
_content: Vec<u8>,
|
||||
) -> Result<crate::application::dtos::file_dto::FileDto, crate::common::errors::DomainError> {
|
||||
Ok(crate::application::dtos::file_dto::FileDto::default())
|
||||
}
|
||||
}
|
||||
|
||||
struct DummyFileRetrievalUseCase;
|
||||
#[async_trait::async_trait]
|
||||
impl crate::application::ports::file_ports::FileRetrievalUseCase for DummyFileRetrievalUseCase {
|
||||
async fn get_file(&self, _id: &str) -> Result<crate::application::dtos::file_dto::FileDto, crate::common::errors::DomainError> {
|
||||
Ok(crate::application::dtos::file_dto::FileDto::default())
|
||||
}
|
||||
|
||||
async fn list_files(&self, _folder_id: Option<&str>) -> Result<Vec<crate::application::dtos::file_dto::FileDto>, crate::common::errors::DomainError> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
async fn get_file_content(&self, _id: &str) -> Result<Vec<u8>, crate::common::errors::DomainError> {
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
async fn get_file_stream(&self, _id: &str) -> Result<Box<dyn futures::Stream<Item = Result<bytes::Bytes, std::io::Error>> + Send>, crate::common::errors::DomainError> {
|
||||
// Create an empty stream
|
||||
let empty_stream = futures::stream::empty::<Result<bytes::Bytes, std::io::Error>>();
|
||||
Ok(Box::new(empty_stream))
|
||||
}
|
||||
}
|
||||
|
||||
struct DummyFileManagementUseCase;
|
||||
#[async_trait::async_trait]
|
||||
impl crate::application::ports::file_ports::FileManagementUseCase for DummyFileManagementUseCase {
|
||||
async fn move_file(&self, _file_id: &str, _folder_id: Option<String>) -> Result<crate::application::dtos::file_dto::FileDto, crate::common::errors::DomainError> {
|
||||
Ok(crate::application::dtos::file_dto::FileDto::default())
|
||||
}
|
||||
|
||||
async fn delete_file(&self, _id: &str) -> Result<(), crate::common::errors::DomainError> {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
struct DummyFileUseCaseFactory;
|
||||
impl crate::application::ports::file_ports::FileUseCaseFactory for DummyFileUseCaseFactory {
|
||||
fn create_file_upload_use_case(&self) -> std::sync::Arc<dyn crate::application::ports::file_ports::FileUploadUseCase> {
|
||||
std::sync::Arc::new(DummyFileUploadUseCase)
|
||||
}
|
||||
|
||||
fn create_file_retrieval_use_case(&self) -> std::sync::Arc<dyn crate::application::ports::file_ports::FileRetrievalUseCase> {
|
||||
std::sync::Arc::new(DummyFileRetrievalUseCase)
|
||||
}
|
||||
|
||||
fn create_file_management_use_case(&self) -> std::sync::Arc<dyn crate::application::ports::file_ports::FileManagementUseCase> {
|
||||
std::sync::Arc::new(DummyFileManagementUseCase)
|
||||
}
|
||||
}
|
||||
|
||||
struct DummyI18nApplicationService {};
|
||||
|
||||
// Need to implement the actual service to match the type signature in DI container
|
||||
impl DummyI18nApplicationService {
|
||||
fn dummy() -> crate::application::services::i18n_application_service::I18nApplicationService {
|
||||
// We need to create an actual I18nApplicationService
|
||||
crate::application::services::i18n_application_service::I18nApplicationService::new(
|
||||
Arc::new(DummyI18nService) as Arc<dyn crate::domain::services::i18n_service::I18nService>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Create service instances
|
||||
let id_mapping_service = Arc::new(DummyIdMappingService) as Arc<dyn crate::application::ports::outbound::IdMappingPort>;
|
||||
let storage_mediator = Arc::new(DummyStorageMediator) as Arc<dyn crate::application::services::storage_mediator::StorageMediator>;
|
||||
let i18n_repository = Arc::new(DummyI18nService) as Arc<dyn crate::domain::services::i18n_service::I18nService>;
|
||||
let folder_service = Arc::new(DummyFolderUseCase) as Arc<dyn crate::application::ports::inbound::FolderUseCase>;
|
||||
let file_service = Arc::new(DummyFileUseCase) as Arc<dyn crate::application::ports::inbound::FileUseCase>;
|
||||
let file_upload_service = Arc::new(DummyFileUploadUseCase) as Arc<dyn crate::application::ports::file_ports::FileUploadUseCase>;
|
||||
let file_retrieval_service = Arc::new(DummyFileRetrievalUseCase) as Arc<dyn crate::application::ports::file_ports::FileRetrievalUseCase>;
|
||||
let file_management_service = Arc::new(DummyFileManagementUseCase) as Arc<dyn crate::application::ports::file_ports::FileManagementUseCase>;
|
||||
let file_use_case_factory = Arc::new(DummyFileUseCaseFactory) as Arc<dyn crate::application::ports::file_ports::FileUseCaseFactory>;
|
||||
|
||||
// This creates the core services needed for basic functionality
|
||||
let core_services = CoreServices {
|
||||
path_service: path_service.clone(),
|
||||
cache_manager: Arc::new(crate::infrastructure::services::cache_manager::StorageCacheManager::default()),
|
||||
id_mapping_service: id_mapping_service.clone(),
|
||||
config: config.clone(),
|
||||
};
|
||||
|
||||
// Create empty repository implementations
|
||||
let repository_services = RepositoryServices {
|
||||
folder_repository: Arc::new(DummyFolderStoragePort) as Arc<dyn crate::application::ports::outbound::FolderStoragePort>,
|
||||
file_repository: Arc::new(DummyFileStoragePort) as Arc<dyn crate::application::ports::outbound::FileStoragePort>,
|
||||
file_read_repository: Arc::new(DummyFileReadPort) as Arc<dyn crate::application::ports::storage_ports::FileReadPort>,
|
||||
file_write_repository: Arc::new(DummyFileWritePort) as Arc<dyn crate::application::ports::storage_ports::FileWritePort>,
|
||||
i18n_repository,
|
||||
storage_mediator: storage_mediator.clone(),
|
||||
metadata_manager: Arc::new(crate::infrastructure::repositories::FileMetadataManager::default()),
|
||||
path_resolver: Arc::new(crate::infrastructure::repositories::file_path_resolver::FilePathResolver::new(
|
||||
path_service.clone(),
|
||||
storage_mediator.clone(),
|
||||
id_mapping_service.clone()
|
||||
)),
|
||||
};
|
||||
|
||||
// Create application services
|
||||
let application_services = ApplicationServices {
|
||||
folder_service,
|
||||
file_service,
|
||||
file_upload_service,
|
||||
file_retrieval_service,
|
||||
file_management_service,
|
||||
file_use_case_factory,
|
||||
i18n_service: Arc::new(DummyI18nApplicationService::dummy()),
|
||||
};
|
||||
|
||||
// Return a minimal app state
|
||||
Self {
|
||||
core: core_services,
|
||||
repositories: repository_services,
|
||||
applications: application_services,
|
||||
db_pool: None,
|
||||
auth_service: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new(
|
||||
core: CoreServices,
|
||||
repositories: RepositoryServices,
|
||||
applications: ApplicationServices,
|
||||
) -> Self {
|
||||
Self {
|
||||
core,
|
||||
repositories,
|
||||
applications,
|
||||
db_pool: None,
|
||||
auth_service: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_database(mut self, db_pool: Arc<PgPool>) -> Self {
|
||||
self.db_pool = Some(db_pool);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_auth_services(mut self, auth_services: AuthServices) -> Self {
|
||||
self.auth_service = Some(auth_services);
|
||||
self
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user