mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
rename all sql table struct with Table signature
This commit is contained in:
parent
7e9a68f9fd
commit
139222ddcb
@ -2,7 +2,7 @@ use flowy_user::{
|
|||||||
entities::{SignInParams, SignUpParams, UserDetail},
|
entities::{SignInParams, SignUpParams, UserDetail},
|
||||||
errors::{ErrorBuilder, UserError, UserErrorCode},
|
errors::{ErrorBuilder, UserError, UserErrorCode},
|
||||||
prelude::UserServer,
|
prelude::UserServer,
|
||||||
sql_tables::User,
|
sql_tables::UserTable,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub type ArcFlowyServer = std::sync::Arc<dyn FlowyServer>;
|
pub type ArcFlowyServer = std::sync::Arc<dyn FlowyServer>;
|
||||||
@ -14,9 +14,9 @@ pub struct FlowyServerMocker {}
|
|||||||
impl FlowyServer for FlowyServerMocker {}
|
impl FlowyServer for FlowyServerMocker {}
|
||||||
|
|
||||||
impl UserServer for FlowyServerMocker {
|
impl UserServer for FlowyServerMocker {
|
||||||
fn sign_up(&self, params: SignUpParams) -> Result<User, UserError> {
|
fn sign_up(&self, params: SignUpParams) -> Result<UserTable, UserError> {
|
||||||
let user_id = params.email.clone();
|
let user_id = params.email.clone();
|
||||||
Ok(User::new(
|
Ok(UserTable::new(
|
||||||
user_id,
|
user_id,
|
||||||
params.name,
|
params.name,
|
||||||
params.email,
|
params.email,
|
||||||
@ -24,9 +24,9 @@ impl UserServer for FlowyServerMocker {
|
|||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn sign_in(&self, params: SignInParams) -> Result<User, UserError> {
|
fn sign_in(&self, params: SignInParams) -> Result<UserTable, UserError> {
|
||||||
let user_id = params.email.clone();
|
let user_id = params.email.clone();
|
||||||
Ok(User::new(
|
Ok(UserTable::new(
|
||||||
user_id,
|
user_id,
|
||||||
"".to_owned(),
|
"".to_owned(),
|
||||||
params.email,
|
params.email,
|
||||||
|
@ -29,9 +29,9 @@ pub struct UserDetail {
|
|||||||
pub workspace: String,
|
pub workspace: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
use crate::sql_tables::User;
|
use crate::sql_tables::UserTable;
|
||||||
impl std::convert::From<User> for UserDetail {
|
impl std::convert::From<UserTable> for UserDetail {
|
||||||
fn from(user: User) -> Self {
|
fn from(user: UserTable) -> Self {
|
||||||
UserDetail {
|
UserDetail {
|
||||||
id: user.id,
|
id: user.id,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
entities::{SignInParams, SignUpParams, UserDetail},
|
entities::{SignInParams, SignUpParams, UserDetail},
|
||||||
errors::UserError,
|
errors::UserError,
|
||||||
sql_tables::User,
|
sql_tables::UserTable,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub trait UserServer {
|
pub trait UserServer {
|
||||||
fn sign_up(&self, params: SignUpParams) -> Result<User, UserError>;
|
fn sign_up(&self, params: SignUpParams) -> Result<UserTable, UserError>;
|
||||||
fn sign_in(&self, params: SignInParams) -> Result<User, UserError>;
|
fn sign_in(&self, params: SignInParams) -> Result<UserTable, UserError>;
|
||||||
fn get_user_info(&self, user_id: &str) -> Result<UserDetail, UserError>;
|
fn get_user_info(&self, user_id: &str) -> Result<UserDetail, UserError>;
|
||||||
fn sign_out(&self, user_id: &str) -> Result<(), UserError>;
|
fn sign_out(&self, user_id: &str) -> Result<(), UserError>;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ use crate::{
|
|||||||
errors::{ErrorBuilder, UserError, UserErrorCode},
|
errors::{ErrorBuilder, UserError, UserErrorCode},
|
||||||
event::UserEvent::*,
|
event::UserEvent::*,
|
||||||
services::user_session::{database::UserDB, user_server::UserServer},
|
services::user_session::{database::UserDB, user_server::UserServer},
|
||||||
sql_tables::{User, UserChangeset},
|
sql_tables::{UserTable, UserTableChangeset},
|
||||||
};
|
};
|
||||||
use flowy_dispatch::prelude::{EventDispatch, ModuleRequest, ToBytes};
|
use flowy_dispatch::prelude::{EventDispatch, ModuleRequest, ToBytes};
|
||||||
|
|
||||||
@ -56,14 +56,14 @@ impl UserSession {
|
|||||||
self.database.get_connection(&user_id)
|
self.database.get_connection(&user_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sign_in(&self, params: SignInParams) -> Result<User, UserError> {
|
pub fn sign_in(&self, params: SignInParams) -> Result<UserTable, UserError> {
|
||||||
let user = self.server.sign_in(params)?;
|
let user = self.server.sign_in(params)?;
|
||||||
let _ = self.set_user_id(Some(user.id.clone()))?;
|
let _ = self.set_user_id(Some(user.id.clone()))?;
|
||||||
|
|
||||||
self.save_user(user)
|
self.save_user(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sign_up(&self, params: SignUpParams) -> Result<User, UserError> {
|
pub fn sign_up(&self, params: SignUpParams) -> Result<UserTable, UserError> {
|
||||||
let user = self.server.sign_up(params)?;
|
let user = self.server.sign_up(params)?;
|
||||||
let _ = self.set_user_id(Some(user.id.clone()))?;
|
let _ = self.set_user_id(Some(user.id.clone()))?;
|
||||||
self.save_user(user)
|
self.save_user(user)
|
||||||
@ -84,7 +84,7 @@ impl UserSession {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn save_user(&self, user: User) -> Result<User, UserError> {
|
fn save_user(&self, user: UserTable) -> Result<UserTable, UserError> {
|
||||||
let conn = self.get_db_connection()?;
|
let conn = self.get_db_connection()?;
|
||||||
let _ = diesel::insert_into(user_table::table)
|
let _ = diesel::insert_into(user_table::table)
|
||||||
.values(user.clone())
|
.values(user.clone())
|
||||||
@ -94,7 +94,7 @@ impl UserSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_user(&self, params: UpdateUserParams) -> Result<UserDetail, UserError> {
|
pub fn update_user(&self, params: UpdateUserParams) -> Result<UserDetail, UserError> {
|
||||||
let changeset = UserChangeset::new(params);
|
let changeset = UserTableChangeset::new(params);
|
||||||
let conn = self.get_db_connection()?;
|
let conn = self.get_db_connection()?;
|
||||||
diesel_update_table!(user_table, changeset, conn);
|
diesel_update_table!(user_table, changeset, conn);
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ impl UserSession {
|
|||||||
let user_id = self.get_user_id()?;
|
let user_id = self.get_user_id()?;
|
||||||
let user = dsl::user_table
|
let user = dsl::user_table
|
||||||
.filter(user_table::id.eq(&user_id))
|
.filter(user_table::id.eq(&user_id))
|
||||||
.first::<User>(&*(self.get_db_connection()?))?;
|
.first::<UserTable>(&*(self.get_db_connection()?))?;
|
||||||
|
|
||||||
match self.server.get_user_info(&user_id) {
|
match self.server.get_user_info(&user_id) {
|
||||||
Ok(_user_detail) => {
|
Ok(_user_detail) => {
|
||||||
|
@ -3,7 +3,7 @@ use flowy_database::schema::user_table;
|
|||||||
|
|
||||||
#[derive(Clone, Default, Queryable, Identifiable, Insertable)]
|
#[derive(Clone, Default, Queryable, Identifiable, Insertable)]
|
||||||
#[table_name = "user_table"]
|
#[table_name = "user_table"]
|
||||||
pub struct User {
|
pub struct UserTable {
|
||||||
pub(crate) id: String,
|
pub(crate) id: String,
|
||||||
pub(crate) name: String,
|
pub(crate) name: String,
|
||||||
pub(crate) password: String,
|
pub(crate) password: String,
|
||||||
@ -11,7 +11,7 @@ pub struct User {
|
|||||||
pub(crate) workspace: String,
|
pub(crate) workspace: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl User {
|
impl UserTable {
|
||||||
pub fn new(id: String, name: String, email: String, password: String) -> Self {
|
pub fn new(id: String, name: String, email: String, password: String) -> Self {
|
||||||
Self {
|
Self {
|
||||||
id,
|
id,
|
||||||
@ -30,7 +30,7 @@ impl User {
|
|||||||
|
|
||||||
#[derive(AsChangeset, Identifiable, Default, Debug)]
|
#[derive(AsChangeset, Identifiable, Default, Debug)]
|
||||||
#[table_name = "user_table"]
|
#[table_name = "user_table"]
|
||||||
pub struct UserChangeset {
|
pub struct UserTableChangeset {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub workspace: Option<String>,
|
pub workspace: Option<String>,
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
@ -38,9 +38,9 @@ pub struct UserChangeset {
|
|||||||
pub password: Option<String>,
|
pub password: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl UserChangeset {
|
impl UserTableChangeset {
|
||||||
pub fn new(params: UpdateUserParams) -> Self {
|
pub fn new(params: UpdateUserParams) -> Self {
|
||||||
UserChangeset {
|
UserTableChangeset {
|
||||||
id: params.id,
|
id: params.id,
|
||||||
workspace: params.workspace,
|
workspace: params.workspace,
|
||||||
name: params.name,
|
name: params.name,
|
||||||
|
@ -15,7 +15,7 @@ impl AppController {
|
|||||||
pub fn new(user: Arc<dyn WorkspaceUser>) -> Self { Self { user } }
|
pub fn new(user: Arc<dyn WorkspaceUser>) -> Self { Self { user } }
|
||||||
|
|
||||||
pub fn save_app(&self, params: CreateAppParams) -> Result<AppDetail, WorkspaceError> {
|
pub fn save_app(&self, params: CreateAppParams) -> Result<AppDetail, WorkspaceError> {
|
||||||
let app = App::new(params);
|
let app = AppTable::new(params);
|
||||||
let conn = self.user.db_connection()?;
|
let conn = self.user.db_connection()?;
|
||||||
|
|
||||||
let detail: AppDetail = app.clone().into();
|
let detail: AppDetail = app.clone().into();
|
||||||
@ -26,7 +26,7 @@ impl AppController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_app(&self, params: UpdateAppParams) -> Result<(), WorkspaceError> {
|
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()?;
|
let conn = self.user.db_connection()?;
|
||||||
diesel_update_table!(app_table, changeset, conn);
|
diesel_update_table!(app_table, changeset, conn);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -16,7 +16,7 @@ impl WorkspaceController {
|
|||||||
&self,
|
&self,
|
||||||
params: CreateWorkspaceParams,
|
params: CreateWorkspaceParams,
|
||||||
) -> Result<WorkspaceDetail, WorkspaceError> {
|
) -> Result<WorkspaceDetail, WorkspaceError> {
|
||||||
let workspace = Workspace::new(params);
|
let workspace = WorkspaceTable::new(params);
|
||||||
let detail: WorkspaceDetail = workspace.clone().into();
|
let detail: WorkspaceDetail = workspace.clone().into();
|
||||||
|
|
||||||
let _ = diesel::insert_into(workspace_table::table)
|
let _ = diesel::insert_into(workspace_table::table)
|
||||||
@ -31,14 +31,14 @@ impl WorkspaceController {
|
|||||||
pub fn get_workspace(
|
pub fn get_workspace(
|
||||||
&self,
|
&self,
|
||||||
workspace_id: &str,
|
workspace_id: &str,
|
||||||
) -> DispatchFuture<Result<Workspace, WorkspaceError>> {
|
) -> DispatchFuture<Result<WorkspaceTable, WorkspaceError>> {
|
||||||
let user = self.user.clone();
|
let user = self.user.clone();
|
||||||
let workspace_id = workspace_id.to_owned();
|
let workspace_id = workspace_id.to_owned();
|
||||||
DispatchFuture {
|
DispatchFuture {
|
||||||
fut: Box::pin(async move {
|
fut: Box::pin(async move {
|
||||||
let workspace = dsl::workspace_table
|
let workspace = dsl::workspace_table
|
||||||
.filter(workspace_table::id.eq(&workspace_id))
|
.filter(workspace_table::id.eq(&workspace_id))
|
||||||
.first::<Workspace>(&*(user.db_connection()?))?;
|
.first::<WorkspaceTable>(&*(user.db_connection()?))?;
|
||||||
|
|
||||||
// TODO: fetch workspace from remote server
|
// TODO: fetch workspace from remote server
|
||||||
Ok(workspace)
|
Ok(workspace)
|
||||||
@ -47,7 +47,7 @@ impl WorkspaceController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_workspace(&self, params: UpdateWorkspaceParams) -> Result<(), WorkspaceError> {
|
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()?;
|
let conn = self.user.db_connection()?;
|
||||||
diesel_update_table!(workspace_table, changeset, conn);
|
diesel_update_table!(workspace_table, changeset, conn);
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
entities::app::{AppDetail, ColorStyle, CreateAppParams, UpdateAppParams},
|
entities::app::{AppDetail, ColorStyle, CreateAppParams, UpdateAppParams},
|
||||||
impl_sql_binary_expression,
|
impl_sql_binary_expression,
|
||||||
sql_tables::workspace::Workspace,
|
sql_tables::workspace::WorkspaceTable,
|
||||||
};
|
};
|
||||||
use diesel::sql_types::Binary;
|
use diesel::sql_types::Binary;
|
||||||
use flowy_database::schema::app_table;
|
use flowy_database::schema::app_table;
|
||||||
@ -20,10 +20,10 @@ use std::convert::TryInto;
|
|||||||
Insertable,
|
Insertable,
|
||||||
Associations,
|
Associations,
|
||||||
)]
|
)]
|
||||||
#[belongs_to(Workspace, foreign_key = "workspace_id")]
|
#[belongs_to(WorkspaceTable, foreign_key = "workspace_id")]
|
||||||
#[table_name = "app_table"]
|
#[table_name = "app_table"]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
pub(crate) struct App {
|
pub(crate) struct AppTable {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub workspace_id: String, // equal to #[belongs_to(Workspace, foreign_key = "workspace_id")].
|
pub workspace_id: String, // equal to #[belongs_to(Workspace, foreign_key = "workspace_id")].
|
||||||
pub name: String,
|
pub name: String,
|
||||||
@ -35,7 +35,7 @@ pub(crate) struct App {
|
|||||||
pub version: i64,
|
pub version: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl App {
|
impl AppTable {
|
||||||
pub fn new(params: CreateAppParams) -> Self {
|
pub fn new(params: CreateAppParams) -> Self {
|
||||||
let app_id = uuid();
|
let app_id = uuid();
|
||||||
let time = timestamp();
|
let time = timestamp();
|
||||||
@ -87,16 +87,16 @@ impl_sql_binary_expression!(ColorStyleCol);
|
|||||||
|
|
||||||
#[derive(AsChangeset, Identifiable, Default, Debug)]
|
#[derive(AsChangeset, Identifiable, Default, Debug)]
|
||||||
#[table_name = "app_table"]
|
#[table_name = "app_table"]
|
||||||
pub struct AppChangeset {
|
pub struct AppTableChangeset {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub workspace_id: Option<String>,
|
pub workspace_id: Option<String>,
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub desc: Option<String>,
|
pub desc: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppChangeset {
|
impl AppTableChangeset {
|
||||||
pub fn new(params: UpdateAppParams) -> Self {
|
pub fn new(params: UpdateAppParams) -> Self {
|
||||||
AppChangeset {
|
AppTableChangeset {
|
||||||
id: params.app_id,
|
id: params.app_id,
|
||||||
workspace_id: params.workspace_id,
|
workspace_id: params.workspace_id,
|
||||||
name: params.name,
|
name: params.name,
|
||||||
@ -105,7 +105,7 @@ impl AppChangeset {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::convert::Into<AppDetail> for App {
|
impl std::convert::Into<AppDetail> for AppTable {
|
||||||
fn into(self) -> AppDetail {
|
fn into(self) -> AppDetail {
|
||||||
AppDetail {
|
AppDetail {
|
||||||
id: self.id,
|
id: self.id,
|
||||||
|
@ -6,7 +6,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
#[derive(PartialEq, Clone, Serialize, Deserialize, Debug, Queryable, Identifiable, Insertable)]
|
#[derive(PartialEq, Clone, Serialize, Deserialize, Debug, Queryable, Identifiable, Insertable)]
|
||||||
#[table_name = "workspace_table"]
|
#[table_name = "workspace_table"]
|
||||||
#[serde(tag = "type")]
|
#[serde(tag = "type")]
|
||||||
pub struct Workspace {
|
pub struct WorkspaceTable {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub desc: String,
|
pub desc: String,
|
||||||
@ -16,20 +16,20 @@ pub struct Workspace {
|
|||||||
pub version: i64,
|
pub version: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Workspace {
|
impl WorkspaceTable {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn new(params: CreateWorkspaceParams) -> Self {
|
pub fn new(params: CreateWorkspaceParams) -> Self {
|
||||||
let mut workspace = Workspace::default();
|
let mut workspace = WorkspaceTable::default();
|
||||||
workspace.name = params.name;
|
workspace.name = params.name;
|
||||||
workspace.desc = params.desc;
|
workspace.desc = params.desc;
|
||||||
workspace
|
workspace
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::default::Default for Workspace {
|
impl std::default::Default for WorkspaceTable {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let time = timestamp();
|
let time = timestamp();
|
||||||
Workspace {
|
WorkspaceTable {
|
||||||
id: uuid(),
|
id: uuid(),
|
||||||
name: String::default(),
|
name: String::default(),
|
||||||
desc: String::default(),
|
desc: String::default(),
|
||||||
@ -43,15 +43,15 @@ impl std::default::Default for Workspace {
|
|||||||
|
|
||||||
#[derive(AsChangeset, Identifiable, Clone, Default, Debug)]
|
#[derive(AsChangeset, Identifiable, Clone, Default, Debug)]
|
||||||
#[table_name = "workspace_table"]
|
#[table_name = "workspace_table"]
|
||||||
pub struct WorkspaceChangeset {
|
pub struct WorkspaceTableChangeset {
|
||||||
pub id: String,
|
pub id: String,
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
pub desc: Option<String>,
|
pub desc: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl WorkspaceChangeset {
|
impl WorkspaceTableChangeset {
|
||||||
pub fn new(params: UpdateWorkspaceParams) -> Self {
|
pub fn new(params: UpdateWorkspaceParams) -> Self {
|
||||||
WorkspaceChangeset {
|
WorkspaceTableChangeset {
|
||||||
id: params.id,
|
id: params.id,
|
||||||
name: params.name,
|
name: params.name,
|
||||||
desc: params.desc,
|
desc: params.desc,
|
||||||
@ -59,7 +59,7 @@ impl WorkspaceChangeset {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::convert::Into<WorkspaceDetail> for Workspace {
|
impl std::convert::Into<WorkspaceDetail> for WorkspaceTable {
|
||||||
fn into(self) -> WorkspaceDetail {
|
fn into(self) -> WorkspaceDetail {
|
||||||
WorkspaceDetail {
|
WorkspaceDetail {
|
||||||
id: self.id,
|
id: self.id,
|
||||||
|
Loading…
Reference in New Issue
Block a user