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.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: include member count in get_workspace API (#6747)
Zack6ad303583bfc
diff --git a/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs b/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rsindex d8fe3e15cd..09e16cd62e 100644--- a/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs+++ b/frontend/rust-lib/flowy-server/src/af_cloud/impls/user/cloud_service_impl.rs@@ -8,7 +8,8 @@ use client_api::entity::billing_dto::{SubscriptionPlanDetail, WorkspaceSubscriptionStatus, WorkspaceUsageAndLimit,};use client_api::entity::workspace_dto::{- CreateWorkspaceParam, PatchWorkspaceParam, WorkspaceMemberChangeset, WorkspaceMemberInvitation,+ CreateWorkspaceParam, PatchWorkspaceParam, QueryWorkspaceParam, WorkspaceMemberChangeset,+ WorkspaceMemberInvitation,};use client_api::entity::{AFRole, AFWorkspace, AFWorkspaceInvitation, AFWorkspaceSettings, AFWorkspaceSettingsChange,@@ -198,7 +199,11 @@ whereasync fn get_all_workspace(&self, _uid: i64) -> Result<Vec<UserWorkspace>, FlowyError> {let try_get_client = self.server.try_get_client();- let workspaces = try_get_client?.get_workspaces().await?;+ let workspaces = try_get_client?+ .get_workspaces_opt(QueryWorkspaceParam {+ include_member_count: Some(true),+ })+ .await?;to_user_workspaces(workspaces)}@@ -658,6 +663,7 @@ fn to_user_workspace(af_workspace: AFWorkspace) -> UserWorkspace {created_at: af_workspace.created_at,workspace_database_id: af_workspace.database_storage_id.to_string(),icon: af_workspace.icon,+ member_count: af_workspace.member_count.unwrap_or(0),}}diff --git a/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs b/frontend/rust-lib/flowy-server/src/local_server/impls/user.rsindex 2c767b0efe..de940c7a02 100644--- a/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs+++ b/frontend/rust-lib/flowy-server/src/local_server/impls/user.rs@@ -214,5 +214,6 @@ fn make_user_workspace() -> UserWorkspace {created_at: Default::default(),workspace_database_id: uuid::Uuid::new_v4().to_string(),icon: "".to_string(),+ member_count: 0,}}diff --git a/frontend/rust-lib/flowy-sqlite/migrations/2024-11-08-102351_workspace_member_count/down.sql b/frontend/rust-lib/flowy-sqlite/migrations/2024-11-08-102351_workspace_member_count/down.sqlnew file mode 100644index 0000000000..88bc9048aa--- /dev/null+++ b/frontend/rust-lib/flowy-sqlite/migrations/2024-11-08-102351_workspace_member_count/down.sql@@ -0,0 +1 @@+ALTER TABLE user_workspace_table DROP COLUMN member_count;diff --git a/frontend/rust-lib/flowy-sqlite/migrations/2024-11-08-102351_workspace_member_count/up.sql b/frontend/rust-lib/flowy-sqlite/migrations/2024-11-08-102351_workspace_member_count/up.sqlnew file mode 100644index 0000000000..8198d4f3f5--- /dev/null+++ b/frontend/rust-lib/flowy-sqlite/migrations/2024-11-08-102351_workspace_member_count/up.sql@@ -0,0 +1 @@+ALTER TABLE user_workspace_table ADD COLUMN member_count BIGINT NOT NULL DEFAULT 1;diff --git a/frontend/rust-lib/flowy-sqlite/src/schema.rs b/frontend/rust-lib/flowy-sqlite/src/schema.rsindex ed2290dd6f..fc885497dd 100644--- a/frontend/rust-lib/flowy-sqlite/src/schema.rs+++ b/frontend/rust-lib/flowy-sqlite/src/schema.rs@@ -101,6 +101,7 @@ diesel::table! {created_at -> BigInt,database_storage_id -> Text,icon -> Text,+ member_count -> BigInt,}}diff --git a/frontend/rust-lib/flowy-user-pub/src/entities.rs b/frontend/rust-lib/flowy-user-pub/src/entities.rsindex 7c0c9e3e8a..ecaa78021e 100644--- a/frontend/rust-lib/flowy-user-pub/src/entities.rs+++ b/frontend/rust-lib/flowy-user-pub/src/entities.rs@@ -143,6 +143,7 @@ pub struct UserWorkspace {pub workspace_database_id: String,#[serde(default)]pub icon: String,+ pub member_count: i64,}impl UserWorkspace {@@ -153,6 +154,7 @@ impl UserWorkspace {created_at: Utc::now(),workspace_database_id: Uuid::new_v4().to_string(),icon: "".to_string(),+ member_count: 1,}}}diff --git a/frontend/rust-lib/flowy-user-pub/src/session.rs b/frontend/rust-lib/flowy-user-pub/src/session.rsindex 8bbacd5af2..94d4c6718a 100644--- a/frontend/rust-lib/flowy-user-pub/src/session.rs+++ b/frontend/rust-lib/flowy-user-pub/src/session.rs@@ -75,6 +75,7 @@ impl<'de> Visitor<'de> for SessionVisitor {// For historical reasons, the database_storage_id is constructed by the user_id.workspace_database_id: STANDARD.encode(format!("{}:user:database", user_id)),icon: "".to_owned(),+ member_count: 0,})}}diff --git a/frontend/rust-lib/flowy-user/src/entities/user_profile.rs b/frontend/rust-lib/flowy-user/src/entities/user_profile.rsindex ec2dd70291..ba2e945044 100644--- a/frontend/rust-lib/flowy-user/src/entities/user_profile.rs+++ b/frontend/rust-lib/flowy-user/src/entities/user_profile.rs@@ -234,6 +234,9 @@ pub struct UserWorkspacePB {#[pb(index = 4)]pub icon: String,++ #[pb(index = 5)]+ pub member_count: i64,}impl From<UserWorkspace> for UserWorkspacePB {@@ -243,6 +246,7 @@ impl From<UserWorkspace> for UserWorkspacePB {name: value.name,created_at_timestamp: value.created_at.timestamp(),icon: value.icon,+ member_count: value.member_count,}}}diff --git a/frontend/rust-lib/flowy-user/src/services/sqlite_sql/workspace_sql.rs b/frontend/rust-lib/flowy-user/src/services/sqlite_sql/workspace_sql.rsindex a9ad21341e..312b8beca1 100644--- a/frontend/rust-lib/flowy-user/src/services/sqlite_sql/workspace_sql.rs+++ b/frontend/rust-lib/flowy-user/src/services/sqlite_sql/workspace_sql.rs@@ -16,6 +16,7 @@ pub struct UserWorkspaceTable {pub created_at: i64,pub database_storage_id: String,pub icon: String,+ pub member_count: i64,}pub fn get_user_workspace_op(workspace_id: &str, mut conn: DBConnection) -> Option<UserWorkspace> {@@ -92,6 +93,7 @@ impl TryFrom<(i64, &UserWorkspace)> for UserWorkspaceTable {created_at: value.1.created_at.timestamp(),database_storage_id: value.1.workspace_database_id.clone(),icon: value.1.icon.clone(),+ member_count: value.1.member_count,})}}@@ -107,6 +109,7 @@ impl From<UserWorkspaceTable> for UserWorkspace {.unwrap_or_default(),workspace_database_id: value.database_storage_id,icon: value.icon,+ member_count: value.member_count,}}}