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,
|
|
|
|
services::{AppController, WorkspaceController},
|
|
|
|
};
|
2021-07-16 15:18:12 +00:00
|
|
|
use flowy_database::DBConnection;
|
2021-07-19 03:32:33 +00:00
|
|
|
|
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 {}
|
|
|
|
|
2021-07-14 13:12:52 +00:00
|
|
|
pub trait WorkspaceUser: Send + Sync {
|
2021-07-19 08:15:20 +00:00
|
|
|
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 {
|
2021-07-14 13:12:52 +00:00
|
|
|
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 13:12:52 +00:00
|
|
|
|
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-19 14:44:37 +00:00
|
|
|
.data(view_controller)
|
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)
|
2021-07-19 13:05:49 +00:00
|
|
|
.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-14 00:07:25 +00:00
|
|
|
}
|