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,
|
|
|
|
handlers::create_workspace,
|
|
|
|
services::{AppController, WorkspaceController},
|
|
|
|
};
|
2021-07-16 15:18:12 +00:00
|
|
|
use flowy_database::DBConnection;
|
2021-07-18 15:56:36 +00:00
|
|
|
use futures_core::future::BoxFuture;
|
2021-07-14 00:07:25 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2021-07-14 13:12:52 +00:00
|
|
|
pub trait WorkspaceUser: Send + Sync {
|
2021-07-18 15:56:36 +00:00
|
|
|
fn set_current_workspace(&self, id: &str) -> BoxFuture<()>;
|
2021-07-14 13:12:52 +00:00
|
|
|
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")
|
2021-07-14 13:12:52 +00:00
|
|
|
.data(workspace_controller)
|
|
|
|
.data(app_controller)
|
2021-07-14 00:07:25 +00:00
|
|
|
.event(WorkspaceEvent::CreateWorkspace, create_workspace)
|
|
|
|
}
|