mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 11:06:25 +08:00
feat: ipc get_workspace
This commit is contained in:
@@ -12,6 +12,7 @@ pub fn invoke_handler() -> impl Fn(tauri::Invoke) + Send + Sync + 'static {
|
||||
create_workspace,
|
||||
update_workspace,
|
||||
get_workspaces,
|
||||
get_workspace,
|
||||
get_doc,
|
||||
put_blob,
|
||||
get_blob
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use ipc_types::workspace::{
|
||||
CreateWorkspace, CreateWorkspaceResult, GetWorkspacesResult, UpdateWorkspace,
|
||||
CreateWorkspace, CreateWorkspaceResult, GetWorkspace, GetWorkspaceResult, GetWorkspaces,
|
||||
GetWorkspacesResult, UpdateWorkspace,
|
||||
};
|
||||
use jwst::{DocStorage, Workspace as OctoBaseWorkspace};
|
||||
use lib0::any::Any;
|
||||
@@ -10,7 +11,7 @@ use crate::state::AppState;
|
||||
/// create yDoc for a workspace
|
||||
pub async fn get_workspaces<'s>(
|
||||
state: tauri::State<'s, AppState>,
|
||||
parameters: CreateWorkspace,
|
||||
parameters: GetWorkspaces,
|
||||
) -> Result<GetWorkspacesResult, String> {
|
||||
match &state
|
||||
.0
|
||||
@@ -27,6 +28,30 @@ pub async fn get_workspaces<'s>(
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
/// create yDoc for a workspace
|
||||
pub async fn get_workspace<'s>(
|
||||
state: tauri::State<'s, AppState>,
|
||||
parameters: GetWorkspace,
|
||||
) -> Result<GetWorkspaceResult, String> {
|
||||
match &state
|
||||
.0
|
||||
.lock()
|
||||
.await
|
||||
.metadata_db
|
||||
.get_workspace_by_id(parameters.id)
|
||||
.await
|
||||
{
|
||||
Ok(user_workspace_option) => match user_workspace_option {
|
||||
Some(user_workspace) => Ok(GetWorkspaceResult {
|
||||
workspace: user_workspace.clone(),
|
||||
}),
|
||||
None => Err("Get workspace has no result".to_string())
|
||||
},
|
||||
Err(error_message) => Err(error_message.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
/// create yDoc for a workspace
|
||||
pub async fn create_workspace<'s>(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use jwst_storage::model::WorkspaceWithPermission;
|
||||
use jwst_storage::{model::WorkspaceWithPermission, WorkspaceDetail};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
@@ -18,26 +18,37 @@ pub struct GetWorkspaces {
|
||||
pub user_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct GetWorkspace {
|
||||
pub id: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct CreateWorkspaceResult {
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct GetWorkspacesResult {
|
||||
pub workspaces: Vec<WorkspaceWithPermission>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct GetWorkspaceResult {
|
||||
pub workspace: WorkspaceDetail,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub struct UpdateWorkspace {
|
||||
pub id: i64,
|
||||
pub public: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, JsonSchema)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub enum IWorkspaceParameters {
|
||||
CreateWorkspace(CreateWorkspace),
|
||||
GetWorkspace(GetWorkspace),
|
||||
GetWorkspaces(GetWorkspaces),
|
||||
GetWorkspacesResult(GetWorkspacesResult),
|
||||
UpdateWorkspace(UpdateWorkspace),
|
||||
|
||||
Reference in New Issue
Block a user