45 lines
1.4 KiB
Rust
Raw Normal View History

2021-10-12 22:31:38 +08:00
use crate::{
2021-10-16 21:22:59 +08:00
entities::trash::{RepeatedTrash, TrashIdentifier},
2021-10-12 22:31:38 +08:00
errors::WorkspaceError,
2021-10-13 11:10:29 +08:00
services::TrashCan,
2021-10-12 22:31:38 +08:00
};
use flowy_dispatch::prelude::{data_result, Data, DataResult, Unit};
2021-10-16 21:22:59 +08:00
use std::sync::Arc;
2021-10-12 22:31:38 +08:00
2021-10-13 23:11:45 +08:00
#[tracing::instrument(skip(controller), err)]
2021-10-13 11:10:29 +08:00
pub(crate) async fn read_trash_handler(controller: Unit<Arc<TrashCan>>) -> DataResult<RepeatedTrash, WorkspaceError> {
2021-10-16 21:22:59 +08:00
let conn = controller.database.db_connection()?;
let repeated_trash = controller.read_trash(&conn)?;
2021-10-12 22:31:38 +08:00
data_result(repeated_trash)
}
2021-10-13 23:11:45 +08:00
#[tracing::instrument(skip(identifier, controller), err)]
pub(crate) async fn putback_trash_handler(
identifier: Data<TrashIdentifier>,
controller: Unit<Arc<TrashCan>>,
) -> Result<(), WorkspaceError> {
let _ = controller.putback(&identifier.id).await?;
2021-10-13 23:11:45 +08:00
Ok(())
}
#[tracing::instrument(skip(identifier, controller), err)]
pub(crate) async fn delete_trash_handler(
identifier: Data<TrashIdentifier>,
controller: Unit<Arc<TrashCan>>,
) -> Result<(), WorkspaceError> {
let _ = controller.delete(&identifier.id).await?;
Ok(())
}
#[tracing::instrument(skip(controller), err)]
pub(crate) async fn restore_all_handler(controller: Unit<Arc<TrashCan>>) -> Result<(), WorkspaceError> {
let _ = controller.restore_all()?;
Ok(())
}
#[tracing::instrument(skip(controller), err)]
pub(crate) async fn delete_all_handler(controller: Unit<Arc<TrashCan>>) -> Result<(), WorkspaceError> {
let _ = controller.delete_all()?;
2021-10-13 23:11:45 +08:00
Ok(())
}