mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: separate json serde from pb struct
This commit is contained in:
parent
bf5247066d
commit
2b499ee62b
@ -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,
|
||||
}
|
||||
|
@ -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)]
|
||||
|
@ -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)]
|
||||
|
@ -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 {
|
||||
|
@ -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)]
|
||||
|
Loading…
Reference in New Issue
Block a user