[server]: config trash sql table & router

This commit is contained in:
appflowy 2021-10-15 17:09:50 +08:00
parent 8e40ae60e6
commit d67cf76e37
22 changed files with 305 additions and 244 deletions

View File

@ -12,24 +12,19 @@ import 'package:protobuf/protobuf.dart' as $pb;
class QueryViewRequest extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'QueryViewRequest', createEmptyInstance: create)
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'viewId')
..aOB(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'isTrash')
..aOB(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'readBelongings')
..aOB(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'readBelongings')
..hasRequiredFields = false
;
QueryViewRequest._() : super();
factory QueryViewRequest({
$core.String? viewId,
$core.bool? isTrash,
$core.bool? readBelongings,
}) {
final _result = create();
if (viewId != null) {
_result.viewId = viewId;
}
if (isTrash != null) {
_result.isTrash = isTrash;
}
if (readBelongings != null) {
_result.readBelongings = readBelongings;
}
@ -66,45 +61,31 @@ class QueryViewRequest extends $pb.GeneratedMessage {
void clearViewId() => clearField(1);
@$pb.TagNumber(2)
$core.bool get isTrash => $_getBF(1);
$core.bool get readBelongings => $_getBF(1);
@$pb.TagNumber(2)
set isTrash($core.bool v) { $_setBool(1, v); }
set readBelongings($core.bool v) { $_setBool(1, v); }
@$pb.TagNumber(2)
$core.bool hasIsTrash() => $_has(1);
$core.bool hasReadBelongings() => $_has(1);
@$pb.TagNumber(2)
void clearIsTrash() => clearField(2);
@$pb.TagNumber(3)
$core.bool get readBelongings => $_getBF(2);
@$pb.TagNumber(3)
set readBelongings($core.bool v) { $_setBool(2, v); }
@$pb.TagNumber(3)
$core.bool hasReadBelongings() => $_has(2);
@$pb.TagNumber(3)
void clearReadBelongings() => clearField(3);
void clearReadBelongings() => clearField(2);
}
class QueryViewParams extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'QueryViewParams', createEmptyInstance: create)
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'viewId')
..aOB(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'isTrash')
..aOB(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'readBelongings')
..aOB(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'readBelongings')
..hasRequiredFields = false
;
QueryViewParams._() : super();
factory QueryViewParams({
$core.String? viewId,
$core.bool? isTrash,
$core.bool? readBelongings,
}) {
final _result = create();
if (viewId != null) {
_result.viewId = viewId;
}
if (isTrash != null) {
_result.isTrash = isTrash;
}
if (readBelongings != null) {
_result.readBelongings = readBelongings;
}
@ -141,22 +122,13 @@ class QueryViewParams extends $pb.GeneratedMessage {
void clearViewId() => clearField(1);
@$pb.TagNumber(2)
$core.bool get isTrash => $_getBF(1);
$core.bool get readBelongings => $_getBF(1);
@$pb.TagNumber(2)
set isTrash($core.bool v) { $_setBool(1, v); }
set readBelongings($core.bool v) { $_setBool(1, v); }
@$pb.TagNumber(2)
$core.bool hasIsTrash() => $_has(1);
$core.bool hasReadBelongings() => $_has(1);
@$pb.TagNumber(2)
void clearIsTrash() => clearField(2);
@$pb.TagNumber(3)
$core.bool get readBelongings => $_getBF(2);
@$pb.TagNumber(3)
set readBelongings($core.bool v) { $_setBool(2, v); }
@$pb.TagNumber(3)
$core.bool hasReadBelongings() => $_has(2);
@$pb.TagNumber(3)
void clearReadBelongings() => clearField(3);
void clearReadBelongings() => clearField(2);
}
class OpenViewRequest extends $pb.GeneratedMessage {

View File

@ -13,25 +13,23 @@ const QueryViewRequest$json = const {
'1': 'QueryViewRequest',
'2': const [
const {'1': 'view_id', '3': 1, '4': 1, '5': 9, '10': 'viewId'},
const {'1': 'is_trash', '3': 2, '4': 1, '5': 8, '10': 'isTrash'},
const {'1': 'read_belongings', '3': 3, '4': 1, '5': 8, '10': 'readBelongings'},
const {'1': 'read_belongings', '3': 2, '4': 1, '5': 8, '10': 'readBelongings'},
],
};
/// Descriptor for `QueryViewRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List queryViewRequestDescriptor = $convert.base64Decode('ChBRdWVyeVZpZXdSZXF1ZXN0EhcKB3ZpZXdfaWQYASABKAlSBnZpZXdJZBIZCghpc190cmFzaBgCIAEoCFIHaXNUcmFzaBInCg9yZWFkX2JlbG9uZ2luZ3MYAyABKAhSDnJlYWRCZWxvbmdpbmdz');
final $typed_data.Uint8List queryViewRequestDescriptor = $convert.base64Decode('ChBRdWVyeVZpZXdSZXF1ZXN0EhcKB3ZpZXdfaWQYASABKAlSBnZpZXdJZBInCg9yZWFkX2JlbG9uZ2luZ3MYAiABKAhSDnJlYWRCZWxvbmdpbmdz');
@$core.Deprecated('Use queryViewParamsDescriptor instead')
const QueryViewParams$json = const {
'1': 'QueryViewParams',
'2': const [
const {'1': 'view_id', '3': 1, '4': 1, '5': 9, '10': 'viewId'},
const {'1': 'is_trash', '3': 2, '4': 1, '5': 8, '10': 'isTrash'},
const {'1': 'read_belongings', '3': 3, '4': 1, '5': 8, '10': 'readBelongings'},
const {'1': 'read_belongings', '3': 2, '4': 1, '5': 8, '10': 'readBelongings'},
],
};
/// Descriptor for `QueryViewParams`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List queryViewParamsDescriptor = $convert.base64Decode('Cg9RdWVyeVZpZXdQYXJhbXMSFwoHdmlld19pZBgBIAEoCVIGdmlld0lkEhkKCGlzX3RyYXNoGAIgASgIUgdpc1RyYXNoEicKD3JlYWRfYmVsb25naW5ncxgDIAEoCFIOcmVhZEJlbG9uZ2luZ3M=');
final $typed_data.Uint8List queryViewParamsDescriptor = $convert.base64Decode('Cg9RdWVyeVZpZXdQYXJhbXMSFwoHdmlld19pZBgBIAEoCVIGdmlld0lkEicKD3JlYWRfYmVsb25naW5ncxgCIAEoCFIOcmVhZEJlbG9uZ2luZ3M=');
@$core.Deprecated('Use openViewRequestDescriptor instead')
const OpenViewRequest$json = const {
'1': 'OpenViewRequest',

View File

@ -8,6 +8,5 @@ CREATE TABLE IF NOT EXISTS view_table(
modified_time timestamptz NOT NULL,
create_time timestamptz NOT NULL,
thumbnail TEXT NOT NULL,
view_type INTEGER NOT NULL,
is_trash BOOL NOT NULL DEFAULT false
view_type INTEGER NOT NULL
);

View File

@ -2,5 +2,6 @@
CREATE TABLE IF NOT EXISTS trash_table(
id uuid NOT NULL,
PRIMARY KEY (id),
user_id TEXT NOT NULL,
ty INTEGER NOT NULL DEFAULT 0
);

View File

@ -1,10 +1,11 @@
use chrono::Utc;
use flowy_workspace::protobuf::{App, RepeatedView, View, ViewType};
use flowy_workspace::protobuf::{App, RepeatedView, Trash, TrashType, View, ViewType};
use protobuf::ProtobufEnum;
pub(crate) const WORKSPACE_TABLE: &'static str = "workspace_table";
pub(crate) const APP_TABLE: &'static str = "app_table";
pub(crate) const VIEW_TABLE: &'static str = "view_table";
pub(crate) const TRASH_TABLE: &'static str = "trash_table";
#[derive(Debug, Clone, sqlx::FromRow)]
pub struct WorkspaceTable {
@ -55,8 +56,8 @@ pub struct ViewTable {
pub(crate) create_time: chrono::DateTime<Utc>,
pub(crate) thumbnail: String,
pub(crate) view_type: i32,
pub(crate) is_trash: bool,
}
impl std::convert::Into<View> for ViewTable {
fn into(self) -> View {
let view_type = ViewType::from_i32(self.view_type).unwrap_or(ViewType::Doc);
@ -74,3 +75,24 @@ impl std::convert::Into<View> for ViewTable {
view
}
}
impl std::convert::Into<Trash> for ViewTable {
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::View,
unknown_fields: Default::default(),
cached_size: Default::default(),
}
}
}
#[derive(Debug, Clone, sqlx::FromRow)]
pub struct TrashTable {
pub(crate) id: uuid::Uuid,
pub(crate) user_id: String,
pub(crate) ty: i32,
}

View File

@ -1,23 +1,33 @@
use crate::service::util::parse_from_payload;
use crate::service::{
trash::{create_trash, delete_trash, read_trash},
user::LoggedUser,
util::parse_from_payload,
};
use actix_web::{
web::{Data, Payload},
HttpResponse,
};
use flowy_net::errors::ServerError;
use flowy_workspace::protobuf::{Trash, TrashIdentifiers};
use flowy_workspace::protobuf::{CreateTrashParams, TrashIdentifiers};
use sqlx::PgPool;
pub async fn create_handler(payload: Payload, _pool: Data<PgPool>) -> Result<HttpResponse, ServerError> {
let _params: Trash = parse_from_payload(payload).await?;
unimplemented!()
pub async fn create_handler(
payload: Payload,
pool: Data<PgPool>,
logged_user: LoggedUser,
) -> Result<HttpResponse, ServerError> {
let params: CreateTrashParams = parse_from_payload(payload).await?;
let resp = create_trash(pool.get_ref(), params, logged_user).await?;
Ok(resp.into())
}
pub async fn delete_handler(payload: Payload, _pool: Data<PgPool>) -> Result<HttpResponse, ServerError> {
let _params: TrashIdentifiers = parse_from_payload(payload).await?;
unimplemented!()
pub async fn delete_handler(payload: Payload, pool: Data<PgPool>) -> Result<HttpResponse, ServerError> {
let params: TrashIdentifiers = parse_from_payload(payload).await?;
let resp = delete_trash(pool.get_ref(), params).await?;
Ok(resp.into())
}
pub async fn read_handler(payload: Payload, _pool: Data<PgPool>) -> Result<HttpResponse, ServerError> {
let _params: TrashIdentifiers = parse_from_payload(payload).await?;
unimplemented!()
pub async fn read_handler(pool: Data<PgPool>, logged_user: LoggedUser) -> Result<HttpResponse, ServerError> {
let resp = read_trash(pool.get_ref(), logged_user).await?;
Ok(resp.into())
}

View File

@ -1,14 +1,44 @@
use crate::{
entities::workspace::{TrashTable, TRASH_TABLE},
service::{user::LoggedUser, view::read_view_with_transaction},
sqlx_ext::{map_sqlx_error, DBTransaction, SqlBuilder},
};
use ::protobuf::ProtobufEnum;
use anyhow::Context;
use flowy_net::{errors::ServerError, response::FlowyResponse};
use flowy_workspace::protobuf::Trash;
use sqlx::PgPool;
use flowy_net::{
errors::{invalid_params, ServerError},
response::FlowyResponse,
};
use flowy_workspace::{
entities::trash::parser::{TrashId, TrashIds, TrashTypeParser},
protobuf::{CreateTrashParams, RepeatedTrash, Trash, TrashIdentifiers, TrashType},
};
use sqlx::{postgres::PgArguments, PgPool, Postgres};
pub(crate) async fn create_trash(pool: &PgPool, _params: Trash) -> Result<FlowyResponse, ServerError> {
let transaction = pool
pub(crate) async fn create_trash(
pool: &PgPool,
params: CreateTrashParams,
user: LoggedUser,
) -> Result<FlowyResponse, ServerError> {
let mut transaction = pool
.begin()
.await
.context("Failed to acquire a Postgres connection to create trash")?;
let trash_id = TrashId::parse(params.id).map_err(invalid_params)?;
let ty = TrashTypeParser::parse(params.ty.value()).map_err(invalid_params)?;
let (sql, args) = SqlBuilder::create(TRASH_TABLE)
.add_arg("id", trash_id.as_ref())
.add_arg("user_id", &user.user_id)
.add_arg("ty", ty)
.build()?;
let _ = sqlx::query_with(&sql, args)
.execute(&mut transaction)
.await
.map_err(map_sqlx_error)?;
transaction
.commit()
.await
@ -16,3 +46,66 @@ pub(crate) async fn create_trash(pool: &PgPool, _params: Trash) -> Result<FlowyR
Ok(FlowyResponse::success())
}
pub(crate) async fn delete_trash(pool: &PgPool, params: TrashIdentifiers) -> Result<FlowyResponse, ServerError> {
let mut transaction = pool
.begin()
.await
.context("Failed to acquire a Postgres connection to delete trash")?;
let trash_ids = TrashIds::parse(params.ids.into_vec()).map_err(invalid_params)?;
for trash_id in trash_ids.0 {
let (sql, args) = SqlBuilder::delete(TRASH_TABLE).and_where_eq("id", &trash_id).build()?;
let _ = sqlx::query_with(&sql, args)
.execute(&mut transaction)
.await
.map_err(map_sqlx_error)?;
}
transaction
.commit()
.await
.context("Failed to commit SQL transaction to delete view.")?;
Ok(FlowyResponse::success())
}
pub(crate) async fn read_trash(pool: &PgPool, user: LoggedUser) -> Result<FlowyResponse, ServerError> {
let mut transaction = pool
.begin()
.await
.context("Failed to acquire a Postgres connection to read trash")?;
let (sql, args) = SqlBuilder::select(TRASH_TABLE)
.add_field("*")
.and_where_eq("user_id", &user.user_id)
.build()?;
let tables = sqlx::query_as_with::<Postgres, TrashTable, PgArguments>(&sql, args)
.fetch_all(&mut transaction)
.await
.map_err(map_sqlx_error)?;
let mut trash: Vec<Trash> = vec![];
for table in tables {
match TrashType::from_i32(table.ty) {
None => log::error!("Parser trash type with value: {} failed", table.ty),
Some(ty) => match ty {
TrashType::Unknown => {},
TrashType::View => {
trash.push(read_view_with_transaction(table.id, &mut transaction).await?.into());
},
},
}
}
let mut repeated_trash = RepeatedTrash::default();
repeated_trash.set_items(trash.into());
transaction
.commit()
.await
.context("Failed to commit SQL transaction to read view.")?;
FlowyResponse::success().pb(repeated_trash)
}

View File

@ -30,7 +30,6 @@ impl NewViewSqlBuilder {
create_time: time,
thumbnail: "".to_string(),
view_type: ViewType::Doc.value(),
is_trash: false,
};
Self { table }

View File

@ -25,6 +25,7 @@ use crate::{
};
use actix_web::web::Data;
use std::sync::Arc;
use uuid::Uuid;
pub(crate) async fn create_view(pool: &PgPool, params: CreateViewParams) -> Result<FlowyResponse, ServerError> {
let mut transaction = pool
@ -69,6 +70,22 @@ pub(crate) async fn create_view_with_transaction(
Ok(view)
}
pub(crate) async fn read_view_with_transaction(
view_id: Uuid,
transaction: &mut DBTransaction<'_>,
) -> Result<ViewTable, ServerError> {
let (sql, args) = SqlBuilder::select(VIEW_TABLE)
.add_field("*")
.and_where_eq("id", view_id)
.build()?;
let table = sqlx::query_as_with::<Postgres, ViewTable, PgArguments>(&sql, args)
.fetch_one(transaction as &mut DBTransaction<'_>)
.await
.map_err(map_sqlx_error)?;
Ok(table)
}
pub(crate) async fn read_view(
pool: &PgPool,
params: QueryViewParams,
@ -79,17 +96,7 @@ pub(crate) async fn read_view(
.begin()
.await
.context("Failed to acquire a Postgres connection to read view")?;
let (sql, args) = SqlBuilder::select(VIEW_TABLE)
.add_field("*")
.and_where_eq("id", view_id)
.build()?;
let table = sqlx::query_as_with::<Postgres, ViewTable, PgArguments>(&sql, args)
.fetch_one(&mut transaction)
.await
.map_err(map_sqlx_error)?;
let table = read_view_with_transaction(view_id, &mut transaction).await?;
let mut views = RepeatedView::default();
if params.read_belongings {
views.set_items(
@ -142,7 +149,6 @@ pub(crate) async fn update_view(pool: &PgPool, params: UpdateViewParams) -> Resu
.add_some_arg("description", desc)
.add_some_arg("thumbnail", thumbnail)
.add_some_arg("modified_time", Some(Utc::now()))
.add_arg_if(params.has_is_trash(), "is_trash", params.get_is_trash())
.and_where_eq("id", view_id)
.build()?;
@ -193,7 +199,6 @@ pub(crate) async fn read_views_belong_to_id<'c>(
let (sql, args) = SqlBuilder::select(VIEW_TABLE)
.add_field("*")
.and_where_eq("belong_to_id", id)
.and_where_eq("is_trash", false)
.build()?;
let tables = sqlx::query_as_with::<Postgres, ViewTable, PgArguments>(&sql, args)

View File

@ -152,19 +152,19 @@ async fn view_update() {
assert_eq!(&view.name, new_name);
}
#[actix_rt::test]
async fn view_delete() {
let test = ViewTest::new().await;
// delete
let delete_params = DeleteViewParams {
view_ids: vec![test.view.id.clone()],
};
test.server.delete_view(delete_params).await;
// read
let read_params = QueryViewParams::new(&test.view.id).trash();
assert_eq!(test.server.read_view(read_params).await.is_none(), true);
}
// #[actix_rt::test]
// async fn view_delete() {
// let test = ViewTest::new().await;
// // delete
// let delete_params = DeleteViewParams {
// view_ids: vec![test.view.id.clone()],
// };
// test.server.delete_view(delete_params).await;
//
// // read
// let read_params = QueryViewParams::new(&test.view.id).trash();
// assert_eq!(test.server.read_view(read_params).await.is_none(), true);
// }
#[actix_rt::test]
async fn workspace_list_read() {

View File

@ -27,11 +27,6 @@ impl QueryAppRequest {
self.read_belongings = true;
self
}
pub fn trash(mut self) -> Self {
self.is_trash = true;
self
}
}
#[derive(ProtoBuf, Default, Clone, Debug)]

View File

@ -1,3 +1,4 @@
pub mod parser;
mod trash_create;
mod trash_delete;

View File

@ -0,0 +1,5 @@
mod trash_id;
mod trash_ty;
pub use trash_id::*;
pub use trash_ty::*;

View File

@ -0,0 +1,30 @@
#[derive(Debug)]
pub struct TrashId(pub String);
impl TrashId {
pub fn parse(s: String) -> Result<TrashId, String> {
if s.trim().is_empty() {
return Err(format!("Trash id can not be empty or whitespace"));
}
Ok(Self(s))
}
}
impl AsRef<str> for TrashId {
fn as_ref(&self) -> &str { &self.0 }
}
#[derive(Debug)]
pub struct TrashIds(pub Vec<String>);
impl TrashIds {
pub fn parse(ids: Vec<String>) -> Result<TrashIds, String> {
let mut trash_ids = vec![];
for id in ids {
let id = TrashId::parse(id)?;
trash_ids.push(id.0);
}
Ok(Self(trash_ids))
}
}

View File

@ -0,0 +1,16 @@
use crate::entities::trash::TrashType;
use std::convert::TryFrom;
#[derive(Debug)]
pub struct TrashTypeParser(pub i32);
impl TrashTypeParser {
pub fn parse(value: i32) -> Result<i32, String> {
let _ = TrashType::try_from(value)?;
Ok(value)
}
}
impl AsRef<i32> for TrashTypeParser {
fn as_ref(&self) -> &i32 { &self.0 }
}

View File

@ -7,6 +7,18 @@ pub enum TrashType {
View = 1,
}
impl std::convert::TryFrom<i32> for TrashType {
type Error = String;
fn try_from(value: i32) -> Result<Self, Self::Error> {
match value {
0 => Ok(TrashType::Unknown),
1 => Ok(TrashType::View),
_ => Err(format!("Invalid trash type: {}", value)),
}
}
}
impl std::default::Default for TrashType {
fn default() -> Self { TrashType::Unknown }
}

View File

@ -9,9 +9,6 @@ pub struct QueryViewRequest {
pub view_id: String,
#[pb(index = 2)]
pub is_trash: bool,
#[pb(index = 3)]
pub read_belongings: bool,
}
@ -19,15 +16,9 @@ impl QueryViewRequest {
pub fn new(view_id: &str) -> Self {
Self {
view_id: view_id.to_owned(),
is_trash: false,
read_belongings: false,
}
}
pub fn trash(mut self) -> Self {
self.is_trash = true;
self
}
}
#[derive(Default, ProtoBuf, Clone, Debug)]
@ -36,9 +27,6 @@ pub struct QueryViewParams {
pub view_id: String,
#[pb(index = 2)]
pub is_trash: bool,
#[pb(index = 3)]
pub read_belongings: bool,
}
@ -50,11 +38,6 @@ impl QueryViewParams {
}
}
pub fn trash(mut self) -> Self {
self.is_trash = true;
self
}
pub fn read_belongings(mut self) -> Self {
self.read_belongings = true;
self
@ -74,7 +57,6 @@ impl TryInto<QueryViewParams> for QueryViewRequest {
Ok(QueryViewParams {
view_id,
is_trash: self.is_trash,
read_belongings: self.read_belongings,
})
}

View File

@ -27,7 +27,6 @@
pub struct QueryViewRequest {
// message fields
pub view_id: ::std::string::String,
pub is_trash: bool,
pub read_belongings: bool,
// special fields
pub unknown_fields: ::protobuf::UnknownFields,
@ -71,22 +70,7 @@ impl QueryViewRequest {
::std::mem::replace(&mut self.view_id, ::std::string::String::new())
}
// bool is_trash = 2;
pub fn get_is_trash(&self) -> bool {
self.is_trash
}
pub fn clear_is_trash(&mut self) {
self.is_trash = false;
}
// Param is passed by value, moved
pub fn set_is_trash(&mut self, v: bool) {
self.is_trash = v;
}
// bool read_belongings = 3;
// bool read_belongings = 2;
pub fn get_read_belongings(&self) -> bool {
@ -115,13 +99,6 @@ impl ::protobuf::Message for QueryViewRequest {
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.view_id)?;
},
2 => {
if wire_type != ::protobuf::wire_format::WireTypeVarint {
return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));
}
let tmp = is.read_bool()?;
self.is_trash = tmp;
},
3 => {
if wire_type != ::protobuf::wire_format::WireTypeVarint {
return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));
}
@ -143,9 +120,6 @@ impl ::protobuf::Message for QueryViewRequest {
if !self.view_id.is_empty() {
my_size += ::protobuf::rt::string_size(1, &self.view_id);
}
if self.is_trash != false {
my_size += 2;
}
if self.read_belongings != false {
my_size += 2;
}
@ -158,11 +132,8 @@ impl ::protobuf::Message for QueryViewRequest {
if !self.view_id.is_empty() {
os.write_string(1, &self.view_id)?;
}
if self.is_trash != false {
os.write_bool(2, self.is_trash)?;
}
if self.read_belongings != false {
os.write_bool(3, self.read_belongings)?;
os.write_bool(2, self.read_belongings)?;
}
os.write_unknown_fields(self.get_unknown_fields())?;
::std::result::Result::Ok(())
@ -207,11 +178,6 @@ impl ::protobuf::Message for QueryViewRequest {
|m: &QueryViewRequest| { &m.view_id },
|m: &mut QueryViewRequest| { &mut m.view_id },
));
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>(
"is_trash",
|m: &QueryViewRequest| { &m.is_trash },
|m: &mut QueryViewRequest| { &mut m.is_trash },
));
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>(
"read_belongings",
|m: &QueryViewRequest| { &m.read_belongings },
@ -234,7 +200,6 @@ impl ::protobuf::Message for QueryViewRequest {
impl ::protobuf::Clear for QueryViewRequest {
fn clear(&mut self) {
self.view_id.clear();
self.is_trash = false;
self.read_belongings = false;
self.unknown_fields.clear();
}
@ -256,7 +221,6 @@ impl ::protobuf::reflect::ProtobufValue for QueryViewRequest {
pub struct QueryViewParams {
// message fields
pub view_id: ::std::string::String,
pub is_trash: bool,
pub read_belongings: bool,
// special fields
pub unknown_fields: ::protobuf::UnknownFields,
@ -300,22 +264,7 @@ impl QueryViewParams {
::std::mem::replace(&mut self.view_id, ::std::string::String::new())
}
// bool is_trash = 2;
pub fn get_is_trash(&self) -> bool {
self.is_trash
}
pub fn clear_is_trash(&mut self) {
self.is_trash = false;
}
// Param is passed by value, moved
pub fn set_is_trash(&mut self, v: bool) {
self.is_trash = v;
}
// bool read_belongings = 3;
// bool read_belongings = 2;
pub fn get_read_belongings(&self) -> bool {
@ -344,13 +293,6 @@ impl ::protobuf::Message for QueryViewParams {
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.view_id)?;
},
2 => {
if wire_type != ::protobuf::wire_format::WireTypeVarint {
return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));
}
let tmp = is.read_bool()?;
self.is_trash = tmp;
},
3 => {
if wire_type != ::protobuf::wire_format::WireTypeVarint {
return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));
}
@ -372,9 +314,6 @@ impl ::protobuf::Message for QueryViewParams {
if !self.view_id.is_empty() {
my_size += ::protobuf::rt::string_size(1, &self.view_id);
}
if self.is_trash != false {
my_size += 2;
}
if self.read_belongings != false {
my_size += 2;
}
@ -387,11 +326,8 @@ impl ::protobuf::Message for QueryViewParams {
if !self.view_id.is_empty() {
os.write_string(1, &self.view_id)?;
}
if self.is_trash != false {
os.write_bool(2, self.is_trash)?;
}
if self.read_belongings != false {
os.write_bool(3, self.read_belongings)?;
os.write_bool(2, self.read_belongings)?;
}
os.write_unknown_fields(self.get_unknown_fields())?;
::std::result::Result::Ok(())
@ -436,11 +372,6 @@ impl ::protobuf::Message for QueryViewParams {
|m: &QueryViewParams| { &m.view_id },
|m: &mut QueryViewParams| { &mut m.view_id },
));
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>(
"is_trash",
|m: &QueryViewParams| { &m.is_trash },
|m: &mut QueryViewParams| { &mut m.is_trash },
));
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>(
"read_belongings",
|m: &QueryViewParams| { &m.read_belongings },
@ -463,7 +394,6 @@ impl ::protobuf::Message for QueryViewParams {
impl ::protobuf::Clear for QueryViewParams {
fn clear(&mut self) {
self.view_id.clear();
self.is_trash = false;
self.read_belongings = false;
self.unknown_fields.clear();
}
@ -641,37 +571,30 @@ impl ::protobuf::reflect::ProtobufValue for OpenViewRequest {
}
static file_descriptor_proto_data: &'static [u8] = b"\
\n\x10view_query.proto\"o\n\x10QueryViewRequest\x12\x17\n\x07view_id\x18\
\x01\x20\x01(\tR\x06viewId\x12\x19\n\x08is_trash\x18\x02\x20\x01(\x08R\
\x07isTrash\x12'\n\x0fread_belongings\x18\x03\x20\x01(\x08R\x0ereadBelon\
gings\"n\n\x0fQueryViewParams\x12\x17\n\x07view_id\x18\x01\x20\x01(\tR\
\x06viewId\x12\x19\n\x08is_trash\x18\x02\x20\x01(\x08R\x07isTrash\x12'\n\
\x0fread_belongings\x18\x03\x20\x01(\x08R\x0ereadBelongings\"*\n\x0fOpen\
ViewRequest\x12\x17\n\x07view_id\x18\x01\x20\x01(\tR\x06viewIdJ\xdb\x03\
\n\x06\x12\x04\0\0\x0e\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\
\0\x12\x04\x02\0\x06\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x18\n\x0b\n\
\x04\x04\0\x02\0\x12\x03\x03\x04\x17\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\
\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\x12\n\x0c\n\x05\
\x04\0\x02\0\x03\x12\x03\x03\x15\x16\n\x0b\n\x04\x04\0\x02\x01\x12\x03\
\x04\x04\x16\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\x08\n\x0c\n\
\x05\x04\0\x02\x01\x01\x12\x03\x04\t\x11\n\x0c\n\x05\x04\0\x02\x01\x03\
\x12\x03\x04\x14\x15\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x04\x1d\n\x0c\
\n\x05\x04\0\x02\x02\x05\x12\x03\x05\x04\x08\n\x0c\n\x05\x04\0\x02\x02\
\x01\x12\x03\x05\t\x18\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x1b\x1c\
\n\n\n\x02\x04\x01\x12\x04\x07\0\x0b\x01\n\n\n\x03\x04\x01\x01\x12\x03\
\x07\x08\x17\n\x0b\n\x04\x04\x01\x02\0\x12\x03\x08\x04\x17\n\x0c\n\x05\
\x04\x01\x02\0\x05\x12\x03\x08\x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\
\x03\x08\x0b\x12\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\x08\x15\x16\n\x0b\
\n\x04\x04\x01\x02\x01\x12\x03\t\x04\x16\n\x0c\n\x05\x04\x01\x02\x01\x05\
\x12\x03\t\x04\x08\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\t\t\x11\n\x0c\
\n\x05\x04\x01\x02\x01\x03\x12\x03\t\x14\x15\n\x0b\n\x04\x04\x01\x02\x02\
\x12\x03\n\x04\x1d\n\x0c\n\x05\x04\x01\x02\x02\x05\x12\x03\n\x04\x08\n\
\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\n\t\x18\n\x0c\n\x05\x04\x01\x02\
\x02\x03\x12\x03\n\x1b\x1c\n\n\n\x02\x04\x02\x12\x04\x0c\0\x0e\x01\n\n\n\
\x03\x04\x02\x01\x12\x03\x0c\x08\x17\n\x0b\n\x04\x04\x02\x02\0\x12\x03\r\
\x04\x17\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03\r\x04\n\n\x0c\n\x05\x04\
\x02\x02\0\x01\x12\x03\r\x0b\x12\n\x0c\n\x05\x04\x02\x02\0\x03\x12\x03\r\
\x15\x16b\x06proto3\
\n\x10view_query.proto\"T\n\x10QueryViewRequest\x12\x17\n\x07view_id\x18\
\x01\x20\x01(\tR\x06viewId\x12'\n\x0fread_belongings\x18\x02\x20\x01(\
\x08R\x0ereadBelongings\"S\n\x0fQueryViewParams\x12\x17\n\x07view_id\x18\
\x01\x20\x01(\tR\x06viewId\x12'\n\x0fread_belongings\x18\x02\x20\x01(\
\x08R\x0ereadBelongings\"*\n\x0fOpenViewRequest\x12\x17\n\x07view_id\x18\
\x01\x20\x01(\tR\x06viewIdJ\xed\x02\n\x06\x12\x04\0\0\x0c\x01\n\x08\n\
\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\
\x04\0\x01\x12\x03\x02\x08\x18\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\
\x17\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\
\0\x01\x12\x03\x03\x0b\x12\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x15\
\x16\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x1d\n\x0c\n\x05\x04\0\x02\
\x01\x05\x12\x03\x04\x04\x08\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\t\
\x18\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x1b\x1c\n\n\n\x02\x04\x01\
\x12\x04\x06\0\t\x01\n\n\n\x03\x04\x01\x01\x12\x03\x06\x08\x17\n\x0b\n\
\x04\x04\x01\x02\0\x12\x03\x07\x04\x17\n\x0c\n\x05\x04\x01\x02\0\x05\x12\
\x03\x07\x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\x07\x0b\x12\n\x0c\n\
\x05\x04\x01\x02\0\x03\x12\x03\x07\x15\x16\n\x0b\n\x04\x04\x01\x02\x01\
\x12\x03\x08\x04\x1d\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\x08\x04\x08\
\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\x08\t\x18\n\x0c\n\x05\x04\x01\
\x02\x01\x03\x12\x03\x08\x1b\x1c\n\n\n\x02\x04\x02\x12\x04\n\0\x0c\x01\n\
\n\n\x03\x04\x02\x01\x12\x03\n\x08\x17\n\x0b\n\x04\x04\x02\x02\0\x12\x03\
\x0b\x04\x17\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03\x0b\x04\n\n\x0c\n\x05\
\x04\x02\x02\0\x01\x12\x03\x0b\x0b\x12\n\x0c\n\x05\x04\x02\x02\0\x03\x12\
\x03\x0b\x15\x16b\x06proto3\
";
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

View File

@ -2,13 +2,11 @@ syntax = "proto3";
message QueryViewRequest {
string view_id = 1;
bool is_trash = 2;
bool read_belongings = 3;
bool read_belongings = 2;
}
message QueryViewParams {
string view_id = 1;
bool is_trash = 2;
bool read_belongings = 3;
bool read_belongings = 2;
}
message OpenViewRequest {
string view_id = 1;

View File

@ -60,7 +60,7 @@ impl TrashCan {
);
let _ = self
.notify
.send(TrashEvent::Putback(trash_table.ty.into(), vec![trash_table.id], tx))?;
.send(TrashEvent::Putback(trash_table.ty.into(), vec![trash_table.id], tx));
let _ = rx.recv().await.unwrap()?;
let conn = self.database.db_connection()?;

View File

@ -47,14 +47,14 @@ async fn app_create_with_view() {
assert_eq!(view_from_db.belongings[1], view_b);
}
#[tokio::test]
async fn app_set_trash_flag() {
let test = AppTest::new().await;
test.move_app_to_trash().await;
let query = QueryAppRequest::new(&test.app.id).trash();
let _ = read_app(&test.sdk, query);
}
// #[tokio::test]
// async fn app_set_trash_flag() {
// let test = AppTest::new().await;
// test.move_app_to_trash().await;
//
// let query = QueryAppRequest::new(&test.app.id).trash();
// let _ = read_app(&test.sdk, query);
// }
#[tokio::test]
#[should_panic]

View File

@ -1,18 +1,18 @@
use flowy_test::{workspace::*, FlowyTest};
use flowy_workspace::entities::view::*;
#[tokio::test]
async fn view_move_to_trash() {
let test = FlowyTest::setup();
let _ = test.init_user().await;
let test = ViewTest::new(&test).await;
test.move_view_to_trash().await;
let query = QueryViewRequest::new(&test.view.id).trash();
let view = read_view(&test.sdk, query).await;
assert_eq!(view, test.view);
}
// #[tokio::test]
// async fn view_move_to_trash() {
// let test = FlowyTest::setup();
// let _ = test.init_user().await;
//
// let test = ViewTest::new(&test).await;
// test.move_view_to_trash().await;
//
// let query = QueryViewRequest::new(&test.view.id).trash();
// let view = read_view(&test.sdk, query).await;
// assert_eq!(view, test.view);
// }
#[tokio::test]
#[should_panic]