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

34 lines
1.2 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-19 14:44:37 +00:00
use crate::{entities::workspace::UserWorkspace, handlers::*, services::ViewController};
2021-07-14 00:07:25 +00:00
use std::sync::Arc;
pub trait WorkspaceUser: Send + Sync {
fn set_cur_workspace_id(&self, id: &str) -> DispatchFuture<Result<(), WorkspaceError>>;
fn get_cur_workspace(&self) -> DispatchFuture<Result<UserWorkspace, WorkspaceError>>;
fn db_connection(&self) -> Result<DBConnection, WorkspaceError>;
}
pub fn create(user: Arc<dyn WorkspaceUser>) -> Module {
let workspace_controller = Arc::new(WorkspaceController::new(user.clone()));
let app_controller = Arc::new(AppController::new(user.clone()));
2021-07-19 14:44:37 +00:00
let view_controller = Arc::new(ViewController::new(user.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-14 00:07:25 +00:00
.event(WorkspaceEvent::CreateWorkspace, create_workspace)
.event(WorkspaceEvent::GetWorkspaceDetail, get_workspace_detail)
.event(WorkspaceEvent::CreateApp, create_app)
2021-07-19 14:44:37 +00:00
.event(WorkspaceEvent::CreateView, create_view)
2021-07-14 00:07:25 +00:00
}