From 139222ddcbfd7c9d6eb4f16014d4636d50ff1e8b Mon Sep 17 00:00:00 2001 From: appflowy Date: Mon, 19 Jul 2021 17:37:58 +0800 Subject: [PATCH] rename all sql table struct with Table signature --- rust-lib/flowy-sdk/src/flowy_server.rs | 10 +++++----- .../flowy-user/src/entities/user_detail.rs | 6 +++--- .../src/services/user_session/user_server.rs | 6 +++--- .../src/services/user_session/user_session.rs | 12 ++++++------ rust-lib/flowy-user/src/sql_tables/user.rs | 10 +++++----- .../src/services/app_controller.rs | 4 ++-- .../src/services/workspace_controller.rs | 8 ++++---- .../flowy-workspace/src/sql_tables/app/app.rs | 16 ++++++++-------- .../src/sql_tables/workspace/workspace.rs | 18 +++++++++--------- 9 files changed, 45 insertions(+), 45 deletions(-) diff --git a/rust-lib/flowy-sdk/src/flowy_server.rs b/rust-lib/flowy-sdk/src/flowy_server.rs index 1db12a4f19..bcf6202d79 100644 --- a/rust-lib/flowy-sdk/src/flowy_server.rs +++ b/rust-lib/flowy-sdk/src/flowy_server.rs @@ -2,7 +2,7 @@ use flowy_user::{ entities::{SignInParams, SignUpParams, UserDetail}, errors::{ErrorBuilder, UserError, UserErrorCode}, prelude::UserServer, - sql_tables::User, + sql_tables::UserTable, }; pub type ArcFlowyServer = std::sync::Arc; @@ -14,9 +14,9 @@ pub struct FlowyServerMocker {} impl FlowyServer for FlowyServerMocker {} impl UserServer for FlowyServerMocker { - fn sign_up(&self, params: SignUpParams) -> Result { + fn sign_up(&self, params: SignUpParams) -> Result { let user_id = params.email.clone(); - Ok(User::new( + Ok(UserTable::new( user_id, params.name, params.email, @@ -24,9 +24,9 @@ impl UserServer for FlowyServerMocker { )) } - fn sign_in(&self, params: SignInParams) -> Result { + fn sign_in(&self, params: SignInParams) -> Result { let user_id = params.email.clone(); - Ok(User::new( + Ok(UserTable::new( user_id, "".to_owned(), params.email, diff --git a/rust-lib/flowy-user/src/entities/user_detail.rs b/rust-lib/flowy-user/src/entities/user_detail.rs index e59a421a7a..eaf1e4e99a 100644 --- a/rust-lib/flowy-user/src/entities/user_detail.rs +++ b/rust-lib/flowy-user/src/entities/user_detail.rs @@ -29,9 +29,9 @@ pub struct UserDetail { pub workspace: String, } -use crate::sql_tables::User; -impl std::convert::From for UserDetail { - fn from(user: User) -> Self { +use crate::sql_tables::UserTable; +impl std::convert::From for UserDetail { + fn from(user: UserTable) -> Self { UserDetail { id: user.id, email: user.email, diff --git a/rust-lib/flowy-user/src/services/user_session/user_server.rs b/rust-lib/flowy-user/src/services/user_session/user_server.rs index e54bd48217..c5c7f3aac9 100644 --- a/rust-lib/flowy-user/src/services/user_session/user_server.rs +++ b/rust-lib/flowy-user/src/services/user_session/user_server.rs @@ -1,12 +1,12 @@ use crate::{ entities::{SignInParams, SignUpParams, UserDetail}, errors::UserError, - sql_tables::User, + sql_tables::UserTable, }; pub trait UserServer { - fn sign_up(&self, params: SignUpParams) -> Result; - fn sign_in(&self, params: SignInParams) -> Result; + fn sign_up(&self, params: SignUpParams) -> Result; + fn sign_in(&self, params: SignInParams) -> Result; fn get_user_info(&self, user_id: &str) -> Result; fn sign_out(&self, user_id: &str) -> Result<(), UserError>; } diff --git a/rust-lib/flowy-user/src/services/user_session/user_session.rs b/rust-lib/flowy-user/src/services/user_session/user_session.rs index 64aa629fb0..e4a8dc663a 100644 --- a/rust-lib/flowy-user/src/services/user_session/user_session.rs +++ b/rust-lib/flowy-user/src/services/user_session/user_session.rs @@ -14,7 +14,7 @@ use crate::{ errors::{ErrorBuilder, UserError, UserErrorCode}, event::UserEvent::*, services::user_session::{database::UserDB, user_server::UserServer}, - sql_tables::{User, UserChangeset}, + sql_tables::{UserTable, UserTableChangeset}, }; use flowy_dispatch::prelude::{EventDispatch, ModuleRequest, ToBytes}; @@ -56,14 +56,14 @@ impl UserSession { self.database.get_connection(&user_id) } - pub fn sign_in(&self, params: SignInParams) -> Result { + pub fn sign_in(&self, params: SignInParams) -> Result { let user = self.server.sign_in(params)?; let _ = self.set_user_id(Some(user.id.clone()))?; self.save_user(user) } - pub fn sign_up(&self, params: SignUpParams) -> Result { + pub fn sign_up(&self, params: SignUpParams) -> Result { let user = self.server.sign_up(params)?; let _ = self.set_user_id(Some(user.id.clone()))?; self.save_user(user) @@ -84,7 +84,7 @@ impl UserSession { Ok(()) } - fn save_user(&self, user: User) -> Result { + fn save_user(&self, user: UserTable) -> Result { let conn = self.get_db_connection()?; let _ = diesel::insert_into(user_table::table) .values(user.clone()) @@ -94,7 +94,7 @@ impl UserSession { } pub fn update_user(&self, params: UpdateUserParams) -> Result { - let changeset = UserChangeset::new(params); + let changeset = UserTableChangeset::new(params); let conn = self.get_db_connection()?; diesel_update_table!(user_table, changeset, conn); @@ -106,7 +106,7 @@ impl UserSession { let user_id = self.get_user_id()?; let user = dsl::user_table .filter(user_table::id.eq(&user_id)) - .first::(&*(self.get_db_connection()?))?; + .first::(&*(self.get_db_connection()?))?; match self.server.get_user_info(&user_id) { Ok(_user_detail) => { diff --git a/rust-lib/flowy-user/src/sql_tables/user.rs b/rust-lib/flowy-user/src/sql_tables/user.rs index 826837e09d..7b2d7e9b62 100644 --- a/rust-lib/flowy-user/src/sql_tables/user.rs +++ b/rust-lib/flowy-user/src/sql_tables/user.rs @@ -3,7 +3,7 @@ use flowy_database::schema::user_table; #[derive(Clone, Default, Queryable, Identifiable, Insertable)] #[table_name = "user_table"] -pub struct User { +pub struct UserTable { pub(crate) id: String, pub(crate) name: String, pub(crate) password: String, @@ -11,7 +11,7 @@ pub struct User { pub(crate) workspace: String, } -impl User { +impl UserTable { pub fn new(id: String, name: String, email: String, password: String) -> Self { Self { id, @@ -30,7 +30,7 @@ impl User { #[derive(AsChangeset, Identifiable, Default, Debug)] #[table_name = "user_table"] -pub struct UserChangeset { +pub struct UserTableChangeset { pub id: String, pub workspace: Option, pub name: Option, @@ -38,9 +38,9 @@ pub struct UserChangeset { pub password: Option, } -impl UserChangeset { +impl UserTableChangeset { pub fn new(params: UpdateUserParams) -> Self { - UserChangeset { + UserTableChangeset { id: params.id, workspace: params.workspace, name: params.name, diff --git a/rust-lib/flowy-workspace/src/services/app_controller.rs b/rust-lib/flowy-workspace/src/services/app_controller.rs index cfa5327574..0c7636abcf 100644 --- a/rust-lib/flowy-workspace/src/services/app_controller.rs +++ b/rust-lib/flowy-workspace/src/services/app_controller.rs @@ -15,7 +15,7 @@ impl AppController { pub fn new(user: Arc) -> Self { Self { user } } pub fn save_app(&self, params: CreateAppParams) -> Result { - let app = App::new(params); + let app = AppTable::new(params); let conn = self.user.db_connection()?; let detail: AppDetail = app.clone().into(); @@ -26,7 +26,7 @@ impl AppController { } pub fn update_app(&self, params: UpdateAppParams) -> Result<(), WorkspaceError> { - let changeset = AppChangeset::new(params); + let changeset = AppTableChangeset::new(params); let conn = self.user.db_connection()?; diesel_update_table!(app_table, changeset, conn); Ok(()) diff --git a/rust-lib/flowy-workspace/src/services/workspace_controller.rs b/rust-lib/flowy-workspace/src/services/workspace_controller.rs index 5fdf48e2b1..8b5fadfdd4 100644 --- a/rust-lib/flowy-workspace/src/services/workspace_controller.rs +++ b/rust-lib/flowy-workspace/src/services/workspace_controller.rs @@ -16,7 +16,7 @@ impl WorkspaceController { &self, params: CreateWorkspaceParams, ) -> Result { - let workspace = Workspace::new(params); + let workspace = WorkspaceTable::new(params); let detail: WorkspaceDetail = workspace.clone().into(); let _ = diesel::insert_into(workspace_table::table) @@ -31,14 +31,14 @@ impl WorkspaceController { pub fn get_workspace( &self, workspace_id: &str, - ) -> DispatchFuture> { + ) -> DispatchFuture> { let user = self.user.clone(); let workspace_id = workspace_id.to_owned(); DispatchFuture { fut: Box::pin(async move { let workspace = dsl::workspace_table .filter(workspace_table::id.eq(&workspace_id)) - .first::(&*(user.db_connection()?))?; + .first::(&*(user.db_connection()?))?; // TODO: fetch workspace from remote server Ok(workspace) @@ -47,7 +47,7 @@ impl WorkspaceController { } pub fn update_workspace(&self, params: UpdateWorkspaceParams) -> Result<(), WorkspaceError> { - let changeset = WorkspaceChangeset::new(params); + let changeset = WorkspaceTableChangeset::new(params); let conn = self.user.db_connection()?; diesel_update_table!(workspace_table, changeset, conn); diff --git a/rust-lib/flowy-workspace/src/sql_tables/app/app.rs b/rust-lib/flowy-workspace/src/sql_tables/app/app.rs index 1354fad323..89b4b08f80 100644 --- a/rust-lib/flowy-workspace/src/sql_tables/app/app.rs +++ b/rust-lib/flowy-workspace/src/sql_tables/app/app.rs @@ -1,7 +1,7 @@ use crate::{ entities::app::{AppDetail, ColorStyle, CreateAppParams, UpdateAppParams}, impl_sql_binary_expression, - sql_tables::workspace::Workspace, + sql_tables::workspace::WorkspaceTable, }; use diesel::sql_types::Binary; use flowy_database::schema::app_table; @@ -20,10 +20,10 @@ use std::convert::TryInto; Insertable, Associations, )] -#[belongs_to(Workspace, foreign_key = "workspace_id")] +#[belongs_to(WorkspaceTable, foreign_key = "workspace_id")] #[table_name = "app_table"] #[serde(tag = "type")] -pub(crate) struct App { +pub(crate) struct AppTable { pub id: String, pub workspace_id: String, // equal to #[belongs_to(Workspace, foreign_key = "workspace_id")]. pub name: String, @@ -35,7 +35,7 @@ pub(crate) struct App { pub version: i64, } -impl App { +impl AppTable { pub fn new(params: CreateAppParams) -> Self { let app_id = uuid(); let time = timestamp(); @@ -87,16 +87,16 @@ impl_sql_binary_expression!(ColorStyleCol); #[derive(AsChangeset, Identifiable, Default, Debug)] #[table_name = "app_table"] -pub struct AppChangeset { +pub struct AppTableChangeset { pub id: String, pub workspace_id: Option, pub name: Option, pub desc: Option, } -impl AppChangeset { +impl AppTableChangeset { pub fn new(params: UpdateAppParams) -> Self { - AppChangeset { + AppTableChangeset { id: params.app_id, workspace_id: params.workspace_id, name: params.name, @@ -105,7 +105,7 @@ impl AppChangeset { } } -impl std::convert::Into for App { +impl std::convert::Into for AppTable { fn into(self) -> AppDetail { AppDetail { id: self.id, diff --git a/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace.rs b/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace.rs index 5ec20f2c20..2786b90938 100644 --- a/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace.rs +++ b/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace.rs @@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize}; #[derive(PartialEq, Clone, Serialize, Deserialize, Debug, Queryable, Identifiable, Insertable)] #[table_name = "workspace_table"] #[serde(tag = "type")] -pub struct Workspace { +pub struct WorkspaceTable { pub id: String, pub name: String, pub desc: String, @@ -16,20 +16,20 @@ pub struct Workspace { pub version: i64, } -impl Workspace { +impl WorkspaceTable { #[allow(dead_code)] pub fn new(params: CreateWorkspaceParams) -> Self { - let mut workspace = Workspace::default(); + let mut workspace = WorkspaceTable::default(); workspace.name = params.name; workspace.desc = params.desc; workspace } } -impl std::default::Default for Workspace { +impl std::default::Default for WorkspaceTable { fn default() -> Self { let time = timestamp(); - Workspace { + WorkspaceTable { id: uuid(), name: String::default(), desc: String::default(), @@ -43,15 +43,15 @@ impl std::default::Default for Workspace { #[derive(AsChangeset, Identifiable, Clone, Default, Debug)] #[table_name = "workspace_table"] -pub struct WorkspaceChangeset { +pub struct WorkspaceTableChangeset { pub id: String, pub name: Option, pub desc: Option, } -impl WorkspaceChangeset { +impl WorkspaceTableChangeset { pub fn new(params: UpdateWorkspaceParams) -> Self { - WorkspaceChangeset { + WorkspaceTableChangeset { id: params.id, name: params.name, desc: params.desc, @@ -59,7 +59,7 @@ impl WorkspaceChangeset { } } -impl std::convert::Into for Workspace { +impl std::convert::Into for WorkspaceTable { fn into(self) -> WorkspaceDetail { WorkspaceDetail { id: self.id,