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

29 lines
918 B
Rust
Raw Normal View History

2021-07-14 00:07:25 +00:00
use flowy_dispatch::prelude::*;
use crate::{
errors::WorkspaceError,
event::WorkspaceEvent,
handlers::create_workspace,
services::{AppController, WorkspaceController},
};
2021-07-16 15:18:12 +00:00
use flowy_database::DBConnection;
use futures_core::future::BoxFuture;
2021-07-14 00:07:25 +00:00
use std::sync::Arc;
pub trait WorkspaceUser: Send + Sync {
fn set_current_workspace(&self, id: &str) -> BoxFuture<()>;
fn get_current_workspace(&self) -> Result<String, 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-14 00:07:25 +00:00
Module::new()
.name("Flowy-Workspace")
.data(workspace_controller)
.data(app_controller)
2021-07-14 00:07:25 +00:00
.event(WorkspaceEvent::CreateWorkspace, create_workspace)
}