mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
[rust]: delete app
This commit is contained in:
@ -46,6 +46,20 @@ impl std::convert::Into<App> for AppTable {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::Into<Trash> for AppTable {
|
||||
fn into(self) -> Trash {
|
||||
Trash {
|
||||
id: self.id.to_string(),
|
||||
name: self.name,
|
||||
modified_time: self.modified_time.timestamp(),
|
||||
create_time: self.create_time.timestamp(),
|
||||
ty: TrashType::App,
|
||||
unknown_fields: Default::default(),
|
||||
cached_size: Default::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, sqlx::FromRow)]
|
||||
pub struct ViewTable {
|
||||
pub(crate) id: uuid::Uuid,
|
||||
|
@ -4,6 +4,7 @@ use crate::{
|
||||
sqlx_ext::{map_sqlx_error, DBTransaction, SqlBuilder},
|
||||
};
|
||||
|
||||
use crate::service::trash::read_trash_ids;
|
||||
use chrono::Utc;
|
||||
use flowy_net::errors::{invalid_params, ServerError};
|
||||
use flowy_workspace::{
|
||||
@ -44,6 +45,26 @@ pub(crate) async fn read_app(
|
||||
app_id: Uuid,
|
||||
user: &LoggedUser,
|
||||
) -> Result<App, ServerError> {
|
||||
let table = read_app_table(app_id, transaction).await?;
|
||||
|
||||
let read_trash_ids = read_trash_ids(user, transaction).await?;
|
||||
if read_trash_ids.contains(&table.id.to_string()) {
|
||||
return Err(ServerError::record_not_found());
|
||||
}
|
||||
|
||||
let mut views = RepeatedView::default();
|
||||
views.set_items(
|
||||
read_view_belong_to_id(&table.id.to_string(), user, transaction as &mut DBTransaction<'_>)
|
||||
.await?
|
||||
.into(),
|
||||
);
|
||||
|
||||
let mut app: App = table.into();
|
||||
app.set_belongings(views);
|
||||
Ok(app)
|
||||
}
|
||||
|
||||
pub(crate) async fn read_app_table(app_id: Uuid, transaction: &mut DBTransaction<'_>) -> Result<AppTable, ServerError> {
|
||||
let (sql, args) = SqlBuilder::select(APP_TABLE)
|
||||
.add_field("*")
|
||||
.and_where_eq("id", app_id)
|
||||
@ -54,16 +75,7 @@ pub(crate) async fn read_app(
|
||||
.await
|
||||
.map_err(map_sqlx_error)?;
|
||||
|
||||
let mut views = RepeatedView::default();
|
||||
views.set_items(
|
||||
read_view_belong_to_id(user, transaction as &mut DBTransaction<'_>, &table.id.to_string())
|
||||
.await?
|
||||
.into(),
|
||||
);
|
||||
|
||||
let mut app: App = table.into();
|
||||
app.set_belongings(views);
|
||||
Ok(app)
|
||||
Ok(table)
|
||||
}
|
||||
|
||||
pub(crate) async fn update_app(
|
||||
|
@ -1,6 +1,7 @@
|
||||
use crate::{
|
||||
entities::workspace::{TrashTable, TRASH_TABLE},
|
||||
service::{
|
||||
app::app::{delete_app, read_app_table},
|
||||
user::LoggedUser,
|
||||
view::{delete_view, read_view_table},
|
||||
},
|
||||
@ -82,16 +83,6 @@ pub(crate) async fn delete_trash(
|
||||
.await
|
||||
.map_err(map_sqlx_error)?;
|
||||
|
||||
match TrashType::from_i32(trash_table.ty) {
|
||||
None => log::error!("Parser trash type with value: {} failed", trash_table.ty),
|
||||
Some(ty) => match ty {
|
||||
TrashType::Unknown => {},
|
||||
TrashType::View => {
|
||||
let _ = delete_view(transaction as &mut DBTransaction<'_>, vec![trash_table.id]).await;
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
let _ = delete_trash_targets(
|
||||
transaction as &mut DBTransaction<'_>,
|
||||
vec![(trash_table.id.clone(), trash_table.ty)],
|
||||
@ -120,6 +111,9 @@ async fn delete_trash_targets(
|
||||
TrashType::View => {
|
||||
let _ = delete_view(transaction as &mut DBTransaction<'_>, vec![id]).await;
|
||||
},
|
||||
TrashType::App => {
|
||||
let _ = delete_app(transaction as &mut DBTransaction<'_>, id).await;
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -163,6 +157,9 @@ pub(crate) async fn read_trash(
|
||||
TrashType::View => {
|
||||
trash.push(read_view_table(table.id, transaction).await?.into());
|
||||
},
|
||||
TrashType::App => {
|
||||
trash.push(read_app_table(table.id, transaction).await?.into());
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ pub(crate) async fn read_view(
|
||||
|
||||
let mut views = RepeatedView::default();
|
||||
views.set_items(
|
||||
read_view_belong_to_id(&user, transaction, &table.id.to_string())
|
||||
read_view_belong_to_id(&table.id.to_string(), &user, transaction)
|
||||
.await?
|
||||
.into(),
|
||||
);
|
||||
@ -128,9 +128,9 @@ pub(crate) async fn read_view_table(
|
||||
|
||||
// transaction must be commit from caller
|
||||
pub(crate) async fn read_view_belong_to_id<'c>(
|
||||
id: &str,
|
||||
user: &LoggedUser,
|
||||
transaction: &mut DBTransaction<'_>,
|
||||
id: &str,
|
||||
) -> Result<Vec<View>, ServerError> {
|
||||
// TODO: add index for app_table
|
||||
let (sql, args) = SqlBuilder::select(VIEW_TABLE)
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::helper::*;
|
||||
use flowy_workspace::entities::{
|
||||
app::{AppIdentifier, DeleteAppParams, UpdateAppParams},
|
||||
app::{AppIdentifier, UpdateAppParams},
|
||||
trash::{TrashIdentifier, TrashIdentifiers, TrashType},
|
||||
view::{UpdateViewParams, ViewIdentifier},
|
||||
workspace::{CreateWorkspaceParams, DeleteWorkspaceParams, QueryWorkspaceParams, UpdateWorkspaceParams},
|
||||
@ -123,7 +123,7 @@ async fn app_update() {
|
||||
async fn app_delete() {
|
||||
let test = AppTest::new().await;
|
||||
|
||||
let delete_params = DeleteAppParams {
|
||||
let delete_params = AppIdentifier {
|
||||
app_id: test.app.id.clone(),
|
||||
};
|
||||
test.server.delete_app(delete_params).await;
|
||||
|
@ -95,7 +95,7 @@ impl TestUserServer {
|
||||
update_app_request(self.user_token(), params, &url).await.unwrap();
|
||||
}
|
||||
|
||||
pub async fn delete_app(&self, params: DeleteAppParams) {
|
||||
pub async fn delete_app(&self, params: AppIdentifier) {
|
||||
let url = format!("{}/api/app", self.http_addr());
|
||||
delete_app_request(self.user_token(), params, &url).await.unwrap();
|
||||
}
|
||||
|
Reference in New Issue
Block a user