AppFlowy/frontend/rust-lib/flowy-folder/src/event_map.rs

191 lines
6.3 KiB
Rust
Raw Normal View History

2021-12-06 07:49:21 +00:00
use crate::{
2022-01-10 15:45:59 +00:00
entities::{
app::{App, AppId, CreateAppParams, UpdateAppParams},
trash::{RepeatedTrash, RepeatedTrashId},
view::{CreateViewParams, RepeatedViewId, UpdateViewParams, View, ViewId},
workspace::{CreateWorkspaceParams, RepeatedWorkspace, UpdateWorkspaceParams, Workspace, WorkspaceId},
},
2021-12-14 10:04:51 +00:00
errors::FlowyError,
manager::FolderManager,
2022-01-20 15:51:11 +00:00
services::{app::event_handler::*, trash::event_handler::*, view::event_handler::*, workspace::event_handler::*},
2021-12-06 07:49:21 +00:00
};
2022-03-19 08:23:34 +00:00
use flowy_database::{ConnectionPool, DBConnection};
2022-01-30 02:33:21 +00:00
use flowy_derive::{Flowy_Event, ProtoBuf_Enum};
2022-01-04 14:54:13 +00:00
use lib_dispatch::prelude::*;
2022-01-10 15:45:59 +00:00
use lib_infra::future::FutureResult;
use std::sync::Arc;
2022-03-19 08:23:34 +00:00
use strum_macros::Display;
2021-07-14 00:07:25 +00:00
2021-07-20 06:03:21 +00:00
pub trait WorkspaceDeps: WorkspaceUser + WorkspaceDatabase {}
pub trait WorkspaceUser: Send + Sync {
2021-12-14 10:04:51 +00:00
fn user_id(&self) -> Result<String, FlowyError>;
fn token(&self) -> Result<String, FlowyError>;
2021-07-20 06:03:21 +00:00
}
pub trait WorkspaceDatabase: Send + Sync {
2021-12-14 10:04:51 +00:00
fn db_pool(&self) -> Result<Arc<ConnectionPool>, FlowyError>;
2021-12-14 10:04:51 +00:00
fn db_connection(&self) -> Result<DBConnection, FlowyError> {
let pool = self.db_pool()?;
2021-12-14 10:04:51 +00:00
let conn = pool.get().map_err(|e| FlowyError::internal().context(e))?;
Ok(conn)
}
}
2022-01-14 12:52:03 +00:00
pub fn create(folder: Arc<FolderManager>) -> Module {
let mut module = Module::new()
2021-07-14 00:07:25 +00:00
.name("Flowy-Workspace")
2022-01-14 12:52:03 +00:00
.data(folder.workspace_controller.clone())
.data(folder.app_controller.clone())
.data(folder.view_controller.clone())
.data(folder.trash_controller.clone())
.data(folder.clone());
module = module
.event(FolderEvent::CreateWorkspace, create_workspace_handler)
.event(FolderEvent::ReadCurWorkspace, read_cur_workspace_handler)
.event(FolderEvent::ReadWorkspaces, read_workspaces_handler)
.event(FolderEvent::OpenWorkspace, open_workspace_handler)
.event(FolderEvent::ReadWorkspaceApps, read_workspace_apps_handler);
module = module
.event(FolderEvent::CreateApp, create_app_handler)
.event(FolderEvent::ReadApp, read_app_handler)
.event(FolderEvent::UpdateApp, update_app_handler)
.event(FolderEvent::DeleteApp, delete_app_handler);
module = module
.event(FolderEvent::CreateView, create_view_handler)
.event(FolderEvent::ReadView, read_view_handler)
.event(FolderEvent::UpdateView, update_view_handler)
.event(FolderEvent::DeleteView, delete_view_handler)
.event(FolderEvent::DuplicateView, duplicate_view_handler)
2022-03-06 13:22:42 +00:00
.event(FolderEvent::SetLatestView, set_latest_view_handler)
2022-04-26 13:20:02 +00:00
.event(FolderEvent::CloseView, close_view_handler)
.event(FolderEvent::MoveItem, move_item_handler);
2021-10-13 15:11:45 +00:00
module = module
.event(FolderEvent::ReadTrash, read_trash_handler)
.event(FolderEvent::PutbackTrash, putback_trash_handler)
.event(FolderEvent::DeleteTrash, delete_trash_handler)
.event(FolderEvent::RestoreAllTrash, restore_all_trash_handler)
.event(FolderEvent::DeleteAllTrash, delete_all_trash_handler);
2021-10-12 14:31:38 +00:00
module
2021-07-14 00:07:25 +00:00
}
2022-01-10 15:45:59 +00:00
2022-01-30 02:33:21 +00:00
#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
#[event_err = "FlowyError"]
pub enum FolderEvent {
2022-02-24 13:49:18 +00:00
#[event(input = "CreateWorkspacePayload", output = "Workspace")]
2022-01-30 02:33:21 +00:00
CreateWorkspace = 0,
#[event(output = "CurrentWorkspaceSetting")]
ReadCurWorkspace = 1,
2022-02-24 13:49:18 +00:00
#[event(input = "WorkspaceId", output = "RepeatedWorkspace")]
2022-01-30 02:33:21 +00:00
ReadWorkspaces = 2,
2022-02-24 13:49:18 +00:00
#[event(input = "WorkspaceId")]
2022-01-30 02:33:21 +00:00
DeleteWorkspace = 3,
2022-02-24 13:49:18 +00:00
#[event(input = "WorkspaceId", output = "Workspace")]
2022-01-30 02:33:21 +00:00
OpenWorkspace = 4,
2022-02-24 13:49:18 +00:00
#[event(input = "WorkspaceId", output = "RepeatedApp")]
2022-01-30 02:33:21 +00:00
ReadWorkspaceApps = 5,
2022-02-24 13:49:18 +00:00
#[event(input = "CreateAppPayload", output = "App")]
2022-01-30 02:33:21 +00:00
CreateApp = 101,
2022-02-24 13:49:18 +00:00
#[event(input = "AppId")]
2022-01-30 02:33:21 +00:00
DeleteApp = 102,
2022-02-24 13:49:18 +00:00
#[event(input = "AppId", output = "App")]
2022-01-30 02:33:21 +00:00
ReadApp = 103,
2022-02-24 13:49:18 +00:00
#[event(input = "UpdateAppPayload")]
2022-01-30 02:33:21 +00:00
UpdateApp = 104,
2022-02-24 13:49:18 +00:00
#[event(input = "CreateViewPayload", output = "View")]
2022-01-30 02:33:21 +00:00
CreateView = 201,
2022-02-24 12:36:24 +00:00
#[event(input = "ViewId", output = "View")]
2022-01-30 02:33:21 +00:00
ReadView = 202,
2022-02-24 13:49:18 +00:00
#[event(input = "UpdateViewPayload", output = "View")]
2022-01-30 02:33:21 +00:00
UpdateView = 203,
2022-02-24 12:36:24 +00:00
#[event(input = "RepeatedViewId")]
2022-01-30 02:33:21 +00:00
DeleteView = 204,
2022-02-24 12:36:24 +00:00
#[event(input = "ViewId")]
2022-01-30 02:33:21 +00:00
DuplicateView = 205,
#[event()]
CopyLink = 206,
2022-03-06 13:22:42 +00:00
#[event(input = "ViewId")]
SetLatestView = 207,
2022-01-30 02:33:21 +00:00
2022-02-24 12:36:24 +00:00
#[event(input = "ViewId")]
2022-01-30 02:33:21 +00:00
CloseView = 208,
2022-04-26 13:20:02 +00:00
#[event(input = "MoveFolderItemPayload")]
MoveItem = 209,
2022-01-30 02:33:21 +00:00
#[event(output = "RepeatedTrash")]
ReadTrash = 300,
#[event(input = "TrashId")]
PutbackTrash = 301,
#[event(input = "RepeatedTrashId")]
DeleteTrash = 302,
#[event()]
RestoreAllTrash = 303,
#[event()]
DeleteAllTrash = 304,
}
2022-01-17 03:55:36 +00:00
pub trait FolderCouldServiceV1: Send + Sync {
2022-01-10 15:45:59 +00:00
fn init(&self);
// Workspace
fn create_workspace(&self, token: &str, params: CreateWorkspaceParams) -> FutureResult<Workspace, FlowyError>;
fn read_workspace(&self, token: &str, params: WorkspaceId) -> FutureResult<RepeatedWorkspace, FlowyError>;
fn update_workspace(&self, token: &str, params: UpdateWorkspaceParams) -> FutureResult<(), FlowyError>;
fn delete_workspace(&self, token: &str, params: WorkspaceId) -> FutureResult<(), FlowyError>;
// View
fn create_view(&self, token: &str, params: CreateViewParams) -> FutureResult<View, FlowyError>;
fn read_view(&self, token: &str, params: ViewId) -> FutureResult<Option<View>, FlowyError>;
fn delete_view(&self, token: &str, params: RepeatedViewId) -> FutureResult<(), FlowyError>;
fn update_view(&self, token: &str, params: UpdateViewParams) -> FutureResult<(), FlowyError>;
// App
fn create_app(&self, token: &str, params: CreateAppParams) -> FutureResult<App, FlowyError>;
fn read_app(&self, token: &str, params: AppId) -> FutureResult<Option<App>, FlowyError>;
fn update_app(&self, token: &str, params: UpdateAppParams) -> FutureResult<(), FlowyError>;
fn delete_app(&self, token: &str, params: AppId) -> FutureResult<(), FlowyError>;
// Trash
fn create_trash(&self, token: &str, params: RepeatedTrashId) -> FutureResult<(), FlowyError>;
fn delete_trash(&self, token: &str, params: RepeatedTrashId) -> FutureResult<(), FlowyError>;
fn read_trash(&self, token: &str) -> FutureResult<RepeatedTrash, FlowyError>;
}