2021-11-09 13:29:31 +08:00
|
|
|
use crate::{errors::WorkspaceError, services::WorkspaceController};
|
|
|
|
|
2021-07-31 10:50:56 +08:00
|
|
|
use flowy_dispatch::prelude::{data_result, Data, DataResult, Unit};
|
2021-11-09 13:29:31 +08:00
|
|
|
use flowy_workspace_infra::entities::{app::RepeatedApp, workspace::*};
|
2021-07-19 11:32:33 +08:00
|
|
|
use std::{convert::TryInto, sync::Arc};
|
2021-07-13 17:19:39 +08:00
|
|
|
|
2021-09-05 13:50:23 +08:00
|
|
|
#[tracing::instrument(skip(data, controller), err)]
|
|
|
|
pub(crate) async fn create_workspace_handler(
|
2021-07-14 08:07:25 +08:00
|
|
|
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-11-08 19:19:02 +08:00
|
|
|
let detail = controller.create_workspace_from_params(params).await?;
|
2021-07-31 10:50:56 +08:00
|
|
|
data_result(detail)
|
2021-07-19 11:32:33 +08:00
|
|
|
}
|
|
|
|
|
2021-09-05 13:50:23 +08:00
|
|
|
#[tracing::instrument(skip(controller), err)]
|
2021-10-01 19:39:08 +08:00
|
|
|
pub(crate) async fn read_cur_workspace_handler(
|
|
|
|
controller: Unit<Arc<WorkspaceController>>,
|
|
|
|
) -> DataResult<Workspace, WorkspaceError> {
|
2021-11-07 14:47:11 +08:00
|
|
|
let workspace = controller.read_current_workspace().await?;
|
2021-07-31 10:50:56 +08:00
|
|
|
data_result(workspace)
|
2021-07-20 14:03:21 +08:00
|
|
|
}
|
|
|
|
|
2021-09-07 17:12:03 +08:00
|
|
|
#[tracing::instrument(skip(controller), err)]
|
2021-10-01 19:39:08 +08:00
|
|
|
pub(crate) async fn read_workspace_apps_handler(
|
|
|
|
controller: Unit<Arc<WorkspaceController>>,
|
|
|
|
) -> DataResult<RepeatedApp, WorkspaceError> {
|
2021-11-07 14:47:11 +08:00
|
|
|
let repeated_app = controller.read_current_workspace_apps().await?;
|
2021-09-07 17:12:03 +08:00
|
|
|
data_result(repeated_app)
|
|
|
|
}
|
|
|
|
|
2021-09-05 13:50:23 +08:00
|
|
|
#[tracing::instrument(skip(data, controller), err)]
|
|
|
|
pub(crate) async fn read_workspaces_handler(
|
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-11-08 19:19:02 +08:00
|
|
|
let params: WorkspaceIdentifier = data.into_inner().try_into()?;
|
2021-09-02 14:47:39 +08:00
|
|
|
let workspaces = controller.read_workspaces(params).await?;
|
2021-08-27 23:53:53 +08:00
|
|
|
data_result(workspaces)
|
|
|
|
}
|
|
|
|
|
2021-09-05 13:50:23 +08:00
|
|
|
#[tracing::instrument(skip(data, controller), err)]
|
|
|
|
pub(crate) async fn open_workspace_handler(
|
2021-08-27 23:53:53 +08:00
|
|
|
data: Data<QueryWorkspaceRequest>,
|
|
|
|
controller: Unit<Arc<WorkspaceController>>,
|
2021-08-28 23:08:12 +08:00
|
|
|
) -> DataResult<Workspace, WorkspaceError> {
|
2021-11-08 19:19:02 +08:00
|
|
|
let params: WorkspaceIdentifier = data.into_inner().try_into()?;
|
2021-09-04 09:00:15 +08:00
|
|
|
let workspaces = controller.open_workspace(params).await?;
|
|
|
|
data_result(workspaces)
|
2021-07-14 08:07:25 +08:00
|
|
|
}
|