2021-07-14 08:07:25 +08:00
|
|
|
use crate::{
|
2021-08-29 22:00:42 +08:00
|
|
|
entities::workspace::*,
|
2021-08-28 23:08:12 +08:00
|
|
|
errors::{ErrorBuilder, WorkspaceError, WsErrCode},
|
2021-07-19 11:32:33 +08:00
|
|
|
services::WorkspaceController,
|
2021-07-14 08:07:25 +08:00
|
|
|
};
|
2021-07-31 10:50:56 +08:00
|
|
|
use flowy_dispatch::prelude::{data_result, Data, DataResult, Unit};
|
2021-07-19 11:32:33 +08:00
|
|
|
use std::{convert::TryInto, sync::Arc};
|
2021-07-13 17:19:39 +08:00
|
|
|
|
2021-07-21 22:41:44 +08:00
|
|
|
#[tracing::instrument(name = "create_workspace", skip(data, controller))]
|
2021-07-14 08:07:25 +08:00
|
|
|
pub async fn create_workspace(
|
|
|
|
data: Data<CreateWorkspaceRequest>,
|
2021-07-23 14:54:31 +08:00
|
|
|
controller: Unit<Arc<WorkspaceController>>,
|
2021-07-31 10:50:56 +08:00
|
|
|
) -> DataResult<Workspace, WorkspaceError> {
|
2021-07-18 23:56:36 +08:00
|
|
|
let controller = controller.get_ref().clone();
|
2021-07-14 08:07:25 +08:00
|
|
|
let params: CreateWorkspaceParams = data.into_inner().try_into()?;
|
2021-07-23 14:37:18 +08:00
|
|
|
let detail = controller.create_workspace(params).await?;
|
2021-07-31 10:50:56 +08:00
|
|
|
data_result(detail)
|
2021-07-19 11:32:33 +08:00
|
|
|
}
|
|
|
|
|
2021-07-29 17:27:59 +08:00
|
|
|
#[tracing::instrument(name = "read_cur_workspace", skip(controller))]
|
|
|
|
pub async fn read_cur_workspace(
|
2021-07-23 14:54:31 +08:00
|
|
|
controller: Unit<Arc<WorkspaceController>>,
|
2021-07-31 10:50:56 +08:00
|
|
|
) -> DataResult<Workspace, WorkspaceError> {
|
2021-07-23 14:37:18 +08:00
|
|
|
let workspace = controller.read_cur_workspace().await?;
|
2021-07-31 10:50:56 +08:00
|
|
|
data_result(workspace)
|
2021-07-20 14:03:21 +08:00
|
|
|
}
|
|
|
|
|
2021-07-29 17:27:59 +08:00
|
|
|
#[tracing::instrument(name = "read_workspace", skip(data, controller))]
|
2021-08-30 16:18:58 +08:00
|
|
|
pub async fn read_workspaces(
|
2021-07-20 14:03:21 +08:00
|
|
|
data: Data<QueryWorkspaceRequest>,
|
2021-07-23 14:54:31 +08:00
|
|
|
controller: Unit<Arc<WorkspaceController>>,
|
2021-08-27 23:53:53 +08:00
|
|
|
) -> DataResult<RepeatedWorkspace, WorkspaceError> {
|
2021-07-20 14:03:21 +08:00
|
|
|
let params: QueryWorkspaceParams = data.into_inner().try_into()?;
|
2021-08-27 23:53:53 +08:00
|
|
|
let workspaces = controller.read_workspaces(params.workspace_id).await?;
|
|
|
|
data_result(workspaces)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[tracing::instrument(name = "open_workspace", skip(data, controller))]
|
|
|
|
pub async fn open_workspace(
|
|
|
|
data: Data<QueryWorkspaceRequest>,
|
|
|
|
controller: Unit<Arc<WorkspaceController>>,
|
2021-08-28 23:08:12 +08:00
|
|
|
) -> DataResult<Workspace, WorkspaceError> {
|
2021-08-27 23:53:53 +08:00
|
|
|
let params: QueryWorkspaceParams = data.into_inner().try_into()?;
|
2021-08-28 23:08:12 +08:00
|
|
|
match params.workspace_id {
|
|
|
|
None => Err(ErrorBuilder::new(WsErrCode::WorkspaceIdInvalid).build()),
|
|
|
|
Some(workspace_id) => {
|
|
|
|
let workspaces = controller.open_workspace(&workspace_id).await?;
|
|
|
|
data_result(workspaces)
|
|
|
|
},
|
|
|
|
}
|
2021-07-14 08:07:25 +08:00
|
|
|
}
|