Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

chore: separate json serde from pb struct

appflowy2b499ee62b87
diff --git a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs
index cbbcf48bfb..0677110cda 100644
--- a/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs
+++ b/frontend/rust-lib/flowy-folder/src/services/persistence/version_1/view_sql.rs
@@ -98,6 +98,7 @@ impl ViewTable {
create_time: view.create_time,
thumbnail: view.thumbnail,
view_type: data_type,
+ ext_data: view.ext_data,
version: 0,
is_trash: false,
}
diff --git a/shared-lib/flowy-folder-data-model/src/entities/app.rs b/shared-lib/flowy-folder-data-model/src/entities/app.rs
index 2c87c882ab..1639082f00 100644
--- a/shared-lib/flowy-folder-data-model/src/entities/app.rs
+++ b/shared-lib/flowy-folder-data-model/src/entities/app.rs
@@ -1,3 +1,4 @@
+use crate::entities::view::ViewSerde;
use crate::{
entities::view::RepeatedView,
errors::ErrorCode,
@@ -15,7 +16,7 @@ use std::convert::TryInto;
pub fn gen_app_id() -> String {
nanoid!(10)
}
-#[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone, Serialize, Deserialize)]
+#[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone)]
pub struct App {
#[pb(index = 1)]
pub id: String,
@@ -42,8 +43,41 @@ pub struct App {
pub create_time: i64,
}
-#[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone, Serialize, Deserialize)]
-#[serde(transparent)]
+#[derive(Serialize, Deserialize)]
+pub struct AppSerde {
+ pub id: String,
+
+ pub workspace_id: String,
+
+ pub name: String,
+
+ pub desc: String,
+
+ pub belongings: Vec<ViewSerde>,
+
+ pub version: i64,
+
+ pub modified_time: i64,
+
+ pub create_time: i64,
+}
+
+impl std::convert::From<AppSerde> for App {
+ fn from(app_serde: AppSerde) -> Self {
+ App {
+ id: app_serde.id,
+ workspace_id: app_serde.workspace_id,
+ name: app_serde.name,
+ desc: app_serde.desc,
+ belongings: app_serde.belongings.into(),
+ version: app_serde.version,
+ modified_time: app_serde.modified_time,
+ create_time: app_serde.create_time,
+ }
+ }
+}
+
+#[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)]
pub struct RepeatedApp {
#[pb(index = 1)]
pub items: Vec<App>,
@@ -51,6 +85,13 @@ pub struct RepeatedApp {
impl_def_and_def_mut!(RepeatedApp, App);
+impl std::convert::From<Vec<AppSerde>> for RepeatedApp {
+ fn from(values: Vec<AppSerde>) -> Self {
+ let items = values.into_iter().map(|value| value.into()).collect::<Vec<App>>();
+ RepeatedApp { items }
+ }
+}
+
#[derive(ProtoBuf, Default)]
pub struct CreateAppPayload {
#[pb(index = 1)]
diff --git a/shared-lib/flowy-folder-data-model/src/entities/trash.rs b/shared-lib/flowy-folder-data-model/src/entities/trash.rs
index 73d8a7e242..4f61a21344 100644
--- a/shared-lib/flowy-folder-data-model/src/entities/trash.rs
+++ b/shared-lib/flowy-folder-data-model/src/entities/trash.rs
@@ -3,7 +3,7 @@ use flowy_derive::{ProtoBuf, ProtoBuf_Enum};
use serde::{Deserialize, Serialize};
use std::fmt::Formatter;
-#[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone, Serialize, Deserialize)]
+#[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone)]
pub struct Trash {
#[pb(index = 1)]
pub id: String,
@@ -21,6 +21,31 @@ pub struct Trash {
pub ty: TrashType,
}
+#[derive(Serialize, Deserialize)]
+pub struct TrashSerde {
+ pub id: String,
+
+ pub name: String,
+
+ pub modified_time: i64,
+
+ pub create_time: i64,
+
+ pub ty: TrashType,
+}
+
+impl std::convert::From<TrashSerde> for Trash {
+ fn from(trash_serde: TrashSerde) -> Self {
+ Trash {
+ id: trash_serde.id,
+ name: trash_serde.name,
+ modified_time: trash_serde.modified_time,
+ create_time: trash_serde.create_time,
+ ty: trash_serde.ty,
+ }
+ }
+}
+
#[derive(PartialEq, Debug, Default, ProtoBuf, Clone)]
pub struct RepeatedTrash {
#[pb(index = 1)]
diff --git a/shared-lib/flowy-folder-data-model/src/entities/view.rs b/shared-lib/flowy-folder-data-model/src/entities/view.rs
index 400649dac1..3e1405137a 100644
--- a/shared-lib/flowy-folder-data-model/src/entities/view.rs
+++ b/shared-lib/flowy-folder-data-model/src/entities/view.rs
@@ -17,7 +17,7 @@ pub fn gen_view_id() -> String {
nanoid!(10)
}
-#[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone, Serialize, Deserialize)]
+#[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone)]
pub struct View {
#[pb(index = 1)]
pub id: String,
@@ -32,7 +32,6 @@ pub struct View {
pub desc: String,
#[pb(index = 5)]
- #[serde(default)]
pub data_type: ViewDataType,
#[pb(index = 6)]
@@ -48,14 +47,42 @@ pub struct View {
pub create_time: i64,
#[pb(index = 10)]
- #[serde(default)]
pub ext_data: String,
#[pb(index = 11)]
- #[serde(default)]
pub thumbnail: String,
#[pb(index = 12)]
+ pub plugin_type: i32,
+}
+
+#[derive(Serialize, Deserialize)]
+pub struct ViewSerde {
+ pub id: String,
+
+ pub belong_to_id: String,
+
+ pub name: String,
+
+ pub desc: String,
+
+ #[serde(default)]
+ pub data_type: ViewDataType,
+
+ pub version: i64,
+
+ pub belongings: Vec<ViewSerde>,
+
+ pub modified_time: i64,
+
+ pub create_time: i64,
+
+ #[serde(default)]
+ pub ext_data: String,
+
+ #[serde(default)]
+ pub thumbnail: String,
+
#[serde(default = "default_plugin_type")]
pub plugin_type: i32,
}
@@ -64,8 +91,27 @@ fn default_plugin_type() -> i32 {
0
}
-#[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone, Serialize, Deserialize)]
-#[serde(transparent)]
+impl std::convert::From<ViewSerde> for View {
+ fn from(view_serde: ViewSerde) -> Self {
+ View {
+ id: view_serde.id,
+ belong_to_id: view_serde.belong_to_id,
+ name: view_serde.name,
+ desc: view_serde.desc,
+ data_type: view_serde.data_type,
+ version: view_serde.version,
+ belongings: view_serde.belongings.into(),
+ modified_time: view_serde.modified_time,
+ create_time: view_serde.create_time,
+ ext_data: view_serde.ext_data,
+ thumbnail: view_serde.thumbnail,
+ plugin_type: view_serde.plugin_type,
+ }
+ }
+}
+
+#[derive(Eq, PartialEq, Debug, Default, ProtoBuf, Clone)]
+// #[serde(transparent)]
pub struct RepeatedView {
#[pb(index = 1)]
pub items: Vec<View>,
@@ -73,6 +119,13 @@ pub struct RepeatedView {
impl_def_and_def_mut!(RepeatedView, View);
+impl std::convert::From<Vec<ViewSerde>> for RepeatedView {
+ fn from(values: Vec<ViewSerde>) -> Self {
+ let items = values.into_iter().map(|value| value.into()).collect::<Vec<View>>();
+ RepeatedView { items }
+ }
+}
+
impl std::convert::From<View> for Trash {
fn from(view: View) -> Self {
Trash {
diff --git a/shared-lib/flowy-folder-data-model/src/entities/workspace.rs b/shared-lib/flowy-folder-data-model/src/entities/workspace.rs
index 0b479f4477..b4f63502f2 100644
--- a/shared-lib/flowy-folder-data-model/src/entities/workspace.rs
+++ b/shared-lib/flowy-folder-data-model/src/entities/workspace.rs
@@ -1,3 +1,4 @@
+use crate::entities::app::AppSerde;
use crate::{
entities::{app::RepeatedApp, view::View},
errors::*,
@@ -12,7 +13,7 @@ use std::convert::TryInto;
pub fn gen_workspace_id() -> String {
nanoid!(10)
}
-#[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone, Serialize, Deserialize)]
+#[derive(Eq, PartialEq, ProtoBuf, Default, Debug, Clone)]
pub struct Workspace {
#[pb(index = 1)]
pub id: String,
@@ -33,6 +34,34 @@ pub struct Workspace {
pub create_time: i64,
}
+#[derive(Serialize, Deserialize)]
+pub struct WorkspaceSerde {
+ pub id: String,
+
+ pub name: String,
+
+ pub desc: String,
+
+ pub apps: Vec<AppSerde>,
+
+ pub modified_time: i64,
+
+ pub create_time: i64,
+}
+
+impl std::convert::From<WorkspaceSerde> for Workspace {
+ fn from(workspace_serde: WorkspaceSerde) -> Self {
+ Workspace {
+ id: workspace_serde.id,
+ name: workspace_serde.name,
+ desc: workspace_serde.desc,
+ apps: workspace_serde.apps.into(),
+ modified_time: workspace_serde.modified_time,
+ create_time: workspace_serde.create_time,
+ }
+ }
+}
+
#[derive(PartialEq, Debug, Default, ProtoBuf)]
pub struct RepeatedWorkspace {
#[pb(index = 1)]