use crate::{ entities::{app::RepeatedApp, workspace::*}, errors::WorkspaceError, services::WorkspaceController, }; use flowy_dispatch::prelude::{data_result, Data, DataResult, Unit}; use std::{convert::TryInto, sync::Arc}; #[tracing::instrument(skip(controller), err)] pub(crate) async fn init_workspace_handler(controller: Unit>) -> Result<(), WorkspaceError> { let _ = controller.init()?; Ok(()) } #[tracing::instrument(skip(data, controller), err)] pub(crate) async fn create_workspace_handler( data: Data, controller: Unit>, ) -> DataResult { let controller = controller.get_ref().clone(); let params: CreateWorkspaceParams = data.into_inner().try_into()?; let detail = controller.create_workspace(params).await?; data_result(detail) } #[tracing::instrument(skip(controller), err)] pub(crate) async fn read_cur_workspace_handler( controller: Unit>, ) -> DataResult { let workspace = controller.read_cur_workspace().await?; data_result(workspace) } #[tracing::instrument(skip(controller), err)] pub(crate) async fn read_workspace_apps_handler( controller: Unit>, ) -> DataResult { let repeated_app = controller.read_workspace_apps().await?; data_result(repeated_app) } #[tracing::instrument(skip(data, controller), err)] pub(crate) async fn read_workspaces_handler( data: Data, controller: Unit>, ) -> DataResult { let params: QueryWorkspaceParams = data.into_inner().try_into()?; let workspaces = controller.read_workspaces(params).await?; data_result(workspaces) } #[tracing::instrument(skip(data, controller), err)] pub(crate) async fn open_workspace_handler( data: Data, controller: Unit>, ) -> DataResult { let params: QueryWorkspaceParams = data.into_inner().try_into()?; let workspaces = controller.open_workspace(params).await?; data_result(workspaces) }