use crate::{ entities::{ app::{ App, AppIdentifier, CreateAppParams, CreateAppRequest, QueryAppRequest, UpdateAppParams, UpdateAppRequest, }, trash::Trash, }, errors::WorkspaceError, services::{AppController, TrashCan, ViewController}, }; use lib_dispatch::prelude::{data_result, Data, DataResult, Unit}; use std::{convert::TryInto, sync::Arc}; pub(crate) async fn create_app_handler( data: Data, controller: Unit>, ) -> DataResult { let params: CreateAppParams = data.into_inner().try_into()?; let detail = controller.create_app_from_params(params).await?; data_result(detail) } pub(crate) async fn delete_app_handler( data: Data, controller: Unit>, trash_can: Unit>, ) -> Result<(), WorkspaceError> { let params: AppIdentifier = data.into_inner().try_into()?; let trash = controller .read_app_tables(vec![params.app_id])? .into_iter() .map(|view_table| view_table.into()) .collect::>(); let _ = trash_can.add(trash).await?; Ok(()) } #[tracing::instrument(skip(data, controller))] pub(crate) async fn update_app_handler( data: Data, controller: Unit>, ) -> Result<(), WorkspaceError> { let params: UpdateAppParams = data.into_inner().try_into()?; let _ = controller.update_app(params).await?; Ok(()) } #[tracing::instrument(skip(data, app_controller, view_controller))] pub(crate) async fn read_app_handler( data: Data, app_controller: Unit>, view_controller: Unit>, ) -> DataResult { let params: AppIdentifier = data.into_inner().try_into()?; let mut app = app_controller.read_app(params.clone()).await?; app.belongings = view_controller.read_views_belong_to(¶ms.app_id).await?; data_result(app) }