2021-07-14 08:07:25 +08:00
|
|
|
use crate::{
|
2021-07-20 14:03:21 +08:00
|
|
|
entities::{app::RepeatedApp, workspace::*},
|
2021-07-14 08:07:25 +08:00
|
|
|
errors::WorkspaceError,
|
2021-07-19 11:32:33 +08:00
|
|
|
services::WorkspaceController,
|
2021-07-14 08:07:25 +08:00
|
|
|
};
|
2021-07-19 11:32:33 +08:00
|
|
|
use flowy_dispatch::prelude::{response_ok, Data, ModuleData, ResponseResult};
|
|
|
|
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>,
|
|
|
|
controller: ModuleData<Arc<WorkspaceController>>,
|
2021-07-19 22:44:37 +08:00
|
|
|
) -> ResponseResult<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-19 11:32:33 +08:00
|
|
|
response_ok(detail)
|
|
|
|
}
|
|
|
|
|
2021-07-21 22:41:44 +08:00
|
|
|
#[tracing::instrument(name = "get_cur_workspace", skip(controller))]
|
2021-07-20 14:03:21 +08:00
|
|
|
pub async fn get_cur_workspace(
|
2021-07-19 11:32:33 +08:00
|
|
|
controller: ModuleData<Arc<WorkspaceController>>,
|
2021-07-20 14:03:21 +08:00
|
|
|
) -> ResponseResult<Workspace, WorkspaceError> {
|
2021-07-23 14:37:18 +08:00
|
|
|
let workspace = controller.read_cur_workspace().await?;
|
2021-07-20 14:03:21 +08:00
|
|
|
response_ok(workspace)
|
|
|
|
}
|
|
|
|
|
2021-07-21 22:41:44 +08:00
|
|
|
#[tracing::instrument(name = "get_workspace", skip(data, controller))]
|
2021-07-20 14:03:21 +08:00
|
|
|
pub async fn get_workspace(
|
|
|
|
data: Data<QueryWorkspaceRequest>,
|
|
|
|
controller: ModuleData<Arc<WorkspaceController>>,
|
|
|
|
) -> ResponseResult<Workspace, WorkspaceError> {
|
|
|
|
let params: QueryWorkspaceParams = data.into_inner().try_into()?;
|
2021-07-23 14:37:18 +08:00
|
|
|
let mut workspace = controller.read_workspace(¶ms.workspace_id).await?;
|
2021-07-20 14:03:21 +08:00
|
|
|
|
|
|
|
if params.read_apps {
|
2021-07-23 14:37:18 +08:00
|
|
|
let apps = controller.read_apps(¶ms.workspace_id).await?;
|
2021-07-20 14:03:21 +08:00
|
|
|
workspace.apps = RepeatedApp { items: apps };
|
|
|
|
}
|
|
|
|
|
|
|
|
response_ok(workspace)
|
2021-07-14 08:07:25 +08:00
|
|
|
}
|