46 lines
1.5 KiB
Rust
Raw Normal View History

2021-10-12 22:31:38 +08:00
use crate::{
2021-12-31 10:32:25 +08:00
entities::trash::{RepeatedTrash, RepeatedTrashId, TrashId},
2021-12-14 18:04:51 +08:00
errors::FlowyError,
2021-12-06 15:49:21 +08:00
services::TrashController,
2021-10-12 22:31:38 +08:00
};
use lib_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-12-06 15:49:21 +08:00
pub(crate) async fn read_trash_handler(
controller: Unit<Arc<TrashController>>,
2021-12-14 18:04:51 +08:00
) -> DataResult<RepeatedTrash, FlowyError> {
2022-01-20 23:51:11 +08:00
let repeated_trash = controller.read_trash().await?;
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(
2021-12-31 10:32:25 +08:00
identifier: Data<TrashId>,
2021-12-06 15:49:21 +08:00
controller: Unit<Arc<TrashController>>,
2021-12-14 18:04:51 +08:00
) -> Result<(), FlowyError> {
let _ = controller.putback(&identifier.id).await?;
2021-10-13 23:11:45 +08:00
Ok(())
}
#[tracing::instrument(skip(identifiers, controller), err)]
2021-10-13 23:11:45 +08:00
pub(crate) async fn delete_trash_handler(
2021-12-31 10:32:25 +08:00
identifiers: Data<RepeatedTrashId>,
2021-12-06 15:49:21 +08:00
controller: Unit<Arc<TrashController>>,
2021-12-14 18:04:51 +08:00
) -> Result<(), FlowyError> {
let _ = controller.delete(identifiers.into_inner()).await?;
Ok(())
}
#[tracing::instrument(skip(controller), err)]
2022-01-22 18:48:43 +08:00
pub(crate) async fn restore_all_trash_handler(controller: Unit<Arc<TrashController>>) -> Result<(), FlowyError> {
let _ = controller.restore_all_trash().await?;
Ok(())
}
#[tracing::instrument(skip(controller), err)]
2022-01-22 18:48:43 +08:00
pub(crate) async fn delete_all_trash_handler(controller: Unit<Arc<TrashController>>) -> Result<(), FlowyError> {
let _ = controller.delete_all_trash().await?;
2021-10-13 23:11:45 +08:00
Ok(())
}