72 lines
2.6 KiB
Rust
Raw Normal View History

2021-09-01 22:50:22 +08:00
mod server_api;
mod server_api_mock;
2021-09-01 22:50:22 +08:00
pub use server_api::*;
// TODO: ignore mock files in production
2021-09-01 22:50:22 +08:00
pub use server_api_mock::*;
use crate::{
entities::{
2021-10-30 17:19:50 +08:00
app::{App, AppIdentifier, CreateAppParams, UpdateAppParams},
trash::{RepeatedTrash, TrashIdentifiers},
view::{CreateViewParams, UpdateViewParams, View, ViewIdentifier, ViewIdentifiers},
workspace::{CreateWorkspaceParams, RepeatedWorkspace, UpdateWorkspaceParams, Workspace, WorkspaceIdentifier},
2021-09-01 22:50:22 +08:00
},
errors::WorkspaceError,
};
2021-09-27 23:23:23 +08:00
use flowy_net::config::ServerConfig;
use lib_infra::future::ResultFuture;
2021-09-01 22:50:22 +08:00
use std::sync::Arc;
pub(crate) type Server = Arc<dyn WorkspaceServerAPI + Send + Sync>;
pub trait WorkspaceServerAPI {
2021-11-08 10:57:33 +08:00
fn init(&self);
2021-09-01 22:50:22 +08:00
// Workspace
fn create_workspace(&self, token: &str, params: CreateWorkspaceParams) -> ResultFuture<Workspace, WorkspaceError>;
2021-09-01 22:50:22 +08:00
2021-09-27 23:23:23 +08:00
fn read_workspace(
&self,
token: &str,
2021-11-08 19:19:02 +08:00
params: WorkspaceIdentifier,
2021-09-27 23:23:23 +08:00
) -> ResultFuture<RepeatedWorkspace, WorkspaceError>;
2021-09-01 22:50:22 +08:00
fn update_workspace(&self, token: &str, params: UpdateWorkspaceParams) -> ResultFuture<(), WorkspaceError>;
fn delete_workspace(&self, token: &str, params: WorkspaceIdentifier) -> ResultFuture<(), WorkspaceError>;
2021-09-01 22:50:22 +08:00
// 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: ViewIdentifier) -> ResultFuture<Option<View>, WorkspaceError>;
2021-09-01 22:50:22 +08:00
fn delete_view(&self, token: &str, params: ViewIdentifiers) -> ResultFuture<(), WorkspaceError>;
2021-09-01 22:50:22 +08:00
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: AppIdentifier) -> 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-10-30 17:19:50 +08:00
fn delete_app(&self, token: &str, params: AppIdentifier) -> ResultFuture<(), WorkspaceError>;
// Trash
fn create_trash(&self, token: &str, params: TrashIdentifiers) -> ResultFuture<(), WorkspaceError>;
fn delete_trash(&self, token: &str, params: TrashIdentifiers) -> ResultFuture<(), WorkspaceError>;
fn read_trash(&self, token: &str) -> ResultFuture<RepeatedTrash, WorkspaceError>;
2021-09-01 22:50:22 +08:00
}
2021-09-27 23:23:23 +08:00
pub(crate) fn construct_workspace_server(config: &ServerConfig) -> Arc<dyn WorkspaceServerAPI + Send + Sync> {
2021-09-04 15:12:53 +08:00
if cfg!(feature = "http_server") {
2021-09-27 23:23:23 +08:00
Arc::new(WorkspaceServer::new(config.clone()))
2021-09-04 15:12:53 +08:00
} else {
Arc::new(WorkspaceServerMock {})
2021-09-01 22:50:22 +08:00
}
}