2021-07-14 08:07:25 +08:00
|
|
|
use crate::{
|
2021-07-19 16:15:20 +08:00
|
|
|
entities::workspace::{
|
|
|
|
CreateWorkspaceParams,
|
|
|
|
CreateWorkspaceRequest,
|
|
|
|
UserWorkspace,
|
|
|
|
UserWorkspaceDetail,
|
2021-07-19 22:44:37 +08:00
|
|
|
Workspace,
|
2021-07-19 16:15:20 +08:00
|
|
|
},
|
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-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-19 11:32:33 +08:00
|
|
|
let detail = controller.save_workspace(params).await?;
|
|
|
|
response_ok(detail)
|
|
|
|
}
|
|
|
|
|
2021-07-19 16:15:20 +08:00
|
|
|
pub async fn get_workspace_detail(
|
2021-07-19 11:32:33 +08:00
|
|
|
controller: ModuleData<Arc<WorkspaceController>>,
|
2021-07-19 16:15:20 +08:00
|
|
|
) -> ResponseResult<UserWorkspaceDetail, WorkspaceError> {
|
|
|
|
let user_workspace = controller.get_user_workspace_detail().await?;
|
|
|
|
response_ok(user_workspace)
|
2021-07-14 08:07:25 +08:00
|
|
|
}
|