2021-07-14 00:07:25 +00:00
|
|
|
use flowy_dispatch::prelude::*;
|
|
|
|
|
2021-07-14 13:12:52 +00:00
|
|
|
use crate::{
|
|
|
|
errors::WorkspaceError,
|
|
|
|
event::WorkspaceEvent,
|
|
|
|
services::{AppController, WorkspaceController},
|
|
|
|
};
|
2021-07-16 15:18:12 +00:00
|
|
|
use flowy_database::DBConnection;
|
2021-07-19 03:32:33 +00:00
|
|
|
|
2021-09-01 14:50:22 +00:00
|
|
|
use crate::{
|
|
|
|
handlers::*,
|
|
|
|
services::{server::construct_workspace_server, ViewController},
|
|
|
|
};
|
2021-09-11 06:26:30 +00:00
|
|
|
use flowy_document::module::Document;
|
2021-07-14 00:07:25 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2021-07-20 06:03:21 +00:00
|
|
|
pub trait WorkspaceDeps: WorkspaceUser + WorkspaceDatabase {}
|
|
|
|
|
2021-07-14 13:12:52 +00:00
|
|
|
pub trait WorkspaceUser: Send + Sync {
|
2021-07-26 05:51:41 +00:00
|
|
|
fn user_id(&self) -> Result<String, WorkspaceError>;
|
2021-09-01 14:50:22 +00:00
|
|
|
fn token(&self) -> Result<String, WorkspaceError>;
|
2021-07-20 06:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait WorkspaceDatabase: Send + Sync {
|
2021-07-14 13:12:52 +00:00
|
|
|
fn db_connection(&self) -> Result<DBConnection, WorkspaceError>;
|
|
|
|
}
|
|
|
|
|
2021-09-11 06:26:30 +00:00
|
|
|
pub fn create(user: Arc<dyn WorkspaceUser>, database: Arc<dyn WorkspaceDatabase>, document: Arc<Document>) -> Module {
|
2021-09-01 14:50:22 +00:00
|
|
|
let server = construct_workspace_server();
|
2021-09-11 06:26:30 +00:00
|
|
|
let view_controller = Arc::new(ViewController::new(user.clone(), database.clone(), server.clone(), document));
|
2021-07-20 06:03:21 +00:00
|
|
|
|
2021-09-07 13:31:04 +00:00
|
|
|
let app_controller = Arc::new(AppController::new(user.clone(), database.clone(), server.clone()));
|
2021-07-20 06:03:21 +00:00
|
|
|
|
|
|
|
let workspace_controller = Arc::new(WorkspaceController::new(
|
|
|
|
user.clone(),
|
|
|
|
database.clone(),
|
|
|
|
app_controller.clone(),
|
2021-09-01 14:50:22 +00:00
|
|
|
server.clone(),
|
2021-07-20 06:03:21 +00:00
|
|
|
));
|
2021-07-14 13:12:52 +00:00
|
|
|
|
2021-07-29 09:27:59 +00:00
|
|
|
let mut module = Module::new()
|
2021-07-14 00:07:25 +00:00
|
|
|
.name("Flowy-Workspace")
|
2021-07-14 13:12:52 +00:00
|
|
|
.data(workspace_controller)
|
|
|
|
.data(app_controller)
|
2021-07-29 09:27:59 +00:00
|
|
|
.data(view_controller);
|
|
|
|
|
|
|
|
module = module
|
2021-09-05 05:50:23 +00:00
|
|
|
.event(WorkspaceEvent::CreateWorkspace, create_workspace_handler)
|
|
|
|
.event(WorkspaceEvent::ReadCurWorkspace, read_cur_workspace_handler)
|
|
|
|
.event(WorkspaceEvent::ReadWorkspaces, read_workspaces_handler)
|
2021-09-07 09:12:03 +00:00
|
|
|
.event(WorkspaceEvent::OpenWorkspace, open_workspace_handler)
|
|
|
|
.event(WorkspaceEvent::ReadWorkspaceApps, read_workspace_apps_handler);
|
2021-07-29 09:27:59 +00:00
|
|
|
|
|
|
|
module = module
|
2021-09-05 05:50:23 +00:00
|
|
|
.event(WorkspaceEvent::CreateApp, create_app_handler)
|
|
|
|
.event(WorkspaceEvent::ReadApp, read_app_handler)
|
|
|
|
.event(WorkspaceEvent::UpdateApp, update_app_handler)
|
|
|
|
.event(WorkspaceEvent::DeleteApp, delete_app_handler);
|
2021-07-29 09:27:59 +00:00
|
|
|
|
|
|
|
module = module
|
2021-09-05 05:50:23 +00:00
|
|
|
.event(WorkspaceEvent::CreateView, create_view_handler)
|
|
|
|
.event(WorkspaceEvent::ReadView, read_view_handler)
|
|
|
|
.event(WorkspaceEvent::UpdateView, update_view_handler)
|
2021-09-11 06:26:30 +00:00
|
|
|
.event(WorkspaceEvent::DeleteView, delete_view_handler)
|
|
|
|
.event(WorkspaceEvent::OpenView, open_view_handler)
|
|
|
|
.event(WorkspaceEvent::UpdateViewData, update_view_data_handler);
|
2021-07-29 09:27:59 +00:00
|
|
|
|
|
|
|
module
|
2021-07-14 00:07:25 +00:00
|
|
|
}
|