63 lines
2.3 KiB
Rust
Raw Normal View History

2021-09-01 22:50:22 +08:00
mod server_api;
mod server_api_mock;
pub use server_api::*;
// TODO: exclude mock files in production
pub use server_api_mock::*;
use crate::{
entities::{
app::{App, CreateAppParams, DeleteAppParams, QueryAppParams, UpdateAppParams},
view::{CreateViewParams, DeleteViewParams, QueryViewParams, UpdateViewParams, View},
workspace::{
CreateWorkspaceParams,
DeleteWorkspaceParams,
QueryWorkspaceParams,
RepeatedWorkspace,
UpdateWorkspaceParams,
Workspace,
},
2021-09-01 22:50:22 +08:00
},
errors::WorkspaceError,
};
use flowy_infra::future::ResultFuture;
use std::sync::Arc;
pub(crate) type Server = Arc<dyn WorkspaceServerAPI + Send + Sync>;
pub trait WorkspaceServerAPI {
// Workspace
fn create_workspace(&self, token: &str, params: CreateWorkspaceParams) -> ResultFuture<Workspace, WorkspaceError>;
2021-09-01 22:50:22 +08:00
fn read_workspace(&self, token: &str, params: QueryWorkspaceParams) -> ResultFuture<RepeatedWorkspace, WorkspaceError>;
fn update_workspace(&self, token: &str, params: UpdateWorkspaceParams) -> ResultFuture<(), WorkspaceError>;
fn delete_workspace(&self, token: &str, params: DeleteWorkspaceParams) -> ResultFuture<(), WorkspaceError>;
// View
fn create_view(&self, token: &str, params: CreateViewParams) -> ResultFuture<View, WorkspaceError>;
2021-09-01 22:50:22 +08:00
fn read_view(&self, token: &str, params: QueryViewParams) -> ResultFuture<Option<View>, WorkspaceError>;
2021-09-01 22:50:22 +08:00
fn delete_view(&self, token: &str, params: DeleteViewParams) -> ResultFuture<(), WorkspaceError>;
fn update_view(&self, token: &str, params: UpdateViewParams) -> ResultFuture<(), WorkspaceError>;
// App
fn create_app(&self, token: &str, params: CreateAppParams) -> ResultFuture<App, WorkspaceError>;
2021-09-05 13:50:23 +08:00
fn read_app(&self, token: &str, params: QueryAppParams) -> ResultFuture<Option<App>, WorkspaceError>;
2021-09-05 13:50:23 +08:00
2021-09-01 22:50:22 +08:00
fn update_app(&self, token: &str, params: UpdateAppParams) -> ResultFuture<(), WorkspaceError>;
2021-09-05 13:50:23 +08:00
2021-09-01 22:50:22 +08:00
fn delete_app(&self, token: &str, params: DeleteAppParams) -> ResultFuture<(), WorkspaceError>;
}
pub(crate) fn construct_workspace_server() -> Arc<dyn WorkspaceServerAPI + Send + Sync> {
2021-09-04 15:12:53 +08:00
if cfg!(feature = "http_server") {
2021-09-04 09:00:15 +08:00
Arc::new(WorkspaceServer {})
2021-09-04 15:12:53 +08:00
} else {
Arc::new(WorkspaceServerMock {})
2021-09-01 22:50:22 +08:00
}
}