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:
@ -15,7 +15,7 @@ impl AppController {
|
||||
pub fn new(user: Arc<dyn WorkspaceUser>) -> Self { Self { user } }
|
||||
|
||||
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 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(())
|
||||
|
@ -16,7 +16,7 @@ impl WorkspaceController {
|
||||
&self,
|
||||
params: CreateWorkspaceParams,
|
||||
) -> Result<WorkspaceDetail, WorkspaceError> {
|
||||
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<Result<Workspace, WorkspaceError>> {
|
||||
) -> DispatchFuture<Result<WorkspaceTable, WorkspaceError>> {
|
||||
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::<Workspace>(&*(user.db_connection()?))?;
|
||||
.first::<WorkspaceTable>(&*(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);
|
||||
|
||||
|
@ -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<String>,
|
||||
pub name: Option<String>,
|
||||
pub desc: Option<String>,
|
||||
}
|
||||
|
||||
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<AppDetail> for App {
|
||||
impl std::convert::Into<AppDetail> for AppTable {
|
||||
fn into(self) -> AppDetail {
|
||||
AppDetail {
|
||||
id: self.id,
|
||||
|
@ -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<String>,
|
||||
pub desc: Option<String>,
|
||||
}
|
||||
|
||||
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<WorkspaceDetail> for Workspace {
|
||||
impl std::convert::Into<WorkspaceDetail> for WorkspaceTable {
|
||||
fn into(self) -> WorkspaceDetail {
|
||||
WorkspaceDetail {
|
||||
id: self.id,
|
||||
|
Reference in New Issue
Block a user