AppFlowy/rust-lib/flowy-workspace/src/module.rs

70 lines
2.4 KiB
Rust
Raw Normal View History

2021-07-14 00:07:25 +00:00
use flowy_dispatch::prelude::*;
use crate::{
errors::WorkspaceError,
event::WorkspaceEvent,
services::{AppController, WorkspaceController},
};
2021-07-16 15:18:12 +00:00
use flowy_database::DBConnection;
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 {}
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 {
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
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
));
let mut module = Module::new()
2021-07-14 00:07:25 +00:00
.name("Flowy-Workspace")
.data(workspace_controller)
.data(app_controller)
.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);
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);
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);
module
2021-07-14 00:07:25 +00:00
}