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

55 lines
1.9 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-07-20 06:03:21 +00:00
use crate::{entities::workspace::CurrentWorkspace, handlers::*, services::ViewController};
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>;
fn set_cur_workspace_id(&self, id: &str) -> DispatchFuture<Result<(), WorkspaceError>>;
2021-07-20 06:03:21 +00:00
fn get_cur_workspace(&self) -> DispatchFuture<Result<CurrentWorkspace, WorkspaceError>>;
}
pub trait WorkspaceDatabase: Send + Sync {
fn db_connection(&self) -> Result<DBConnection, WorkspaceError>;
}
2021-07-20 06:03:21 +00:00
pub fn create(user: Arc<dyn WorkspaceUser>, database: Arc<dyn WorkspaceDatabase>) -> Module {
let view_controller = Arc::new(ViewController::new(database.clone()));
let app_controller = Arc::new(AppController::new(
user.clone(),
database.clone(),
view_controller.clone(),
));
let workspace_controller = Arc::new(WorkspaceController::new(
user.clone(),
database.clone(),
app_controller.clone(),
));
2021-07-14 00:07:25 +00:00
Module::new()
.name("Flowy-Workspace")
.data(workspace_controller)
.data(app_controller)
2021-07-19 14:44:37 +00:00
.data(view_controller)
2021-07-26 05:51:41 +00:00
.event(WorkspaceEvent::ReadAllWorkspace, read_all_workspaces)
2021-07-14 00:07:25 +00:00
.event(WorkspaceEvent::CreateWorkspace, create_workspace)
2021-07-20 06:03:21 +00:00
.event(WorkspaceEvent::GetCurWorkspace, get_cur_workspace)
.event(WorkspaceEvent::GetWorkspace, get_workspace)
.event(WorkspaceEvent::CreateApp, create_app)
2021-07-20 07:51:49 +00:00
.event(WorkspaceEvent::GetApp, get_app)
2021-07-19 14:44:37 +00:00
.event(WorkspaceEvent::CreateView, create_view)
2021-07-23 15:56:59 +00:00
.event(WorkspaceEvent::ReadView, read_view)
.event(WorkspaceEvent::UpdateView, update_view)
2021-07-14 00:07:25 +00:00
}