mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-24 22:09:08 +08:00
feat: create user if not exist
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
use ipc_types::{blob::IBlobParameters, document::IDocumentParameters, workspace::IWorkspaceParameters};
|
||||
use ipc_types::{
|
||||
blob::IBlobParameters, document::IDocumentParameters, user::IUserParameters,
|
||||
workspace::IWorkspaceParameters,
|
||||
};
|
||||
/**
|
||||
* convert serde to jsonschema: https://imfeld.dev/writing/generating_typescript_types_from_rust
|
||||
* with way to optimize
|
||||
@@ -30,4 +33,5 @@ fn main() {
|
||||
generate::<IDocumentParameters>(Path::join(&data_center_ipc_type_folder, "document.json"));
|
||||
generate::<IWorkspaceParameters>(Path::join(&data_center_ipc_type_folder, "workspace.json"));
|
||||
generate::<IBlobParameters>(Path::join(&data_center_ipc_type_folder, "blob.json"));
|
||||
generate::<IUserParameters>(Path::join(&data_center_ipc_type_folder, "user.json"));
|
||||
}
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
pub mod blob;
|
||||
pub mod workspace;
|
||||
pub mod document;
|
||||
pub mod user;
|
||||
|
||||
use blob::*;
|
||||
use workspace::*;
|
||||
use document::*;
|
||||
use user::*;
|
||||
|
||||
pub fn invoke_handler() -> impl Fn(tauri::Invoke) + Send + Sync + 'static {
|
||||
tauri::generate_handler![
|
||||
@@ -13,6 +15,7 @@ pub fn invoke_handler() -> impl Fn(tauri::Invoke) + Send + Sync + 'static {
|
||||
update_workspace,
|
||||
get_workspaces,
|
||||
get_workspace,
|
||||
create_user,
|
||||
get_doc,
|
||||
put_blob,
|
||||
get_blob
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
use jwst_storage::{CreateUser, User};
|
||||
|
||||
use crate::state::AppState;
|
||||
|
||||
#[tauri::command]
|
||||
/// create yDoc for a workspace
|
||||
pub async fn create_user<'s>(
|
||||
state: tauri::State<'s, AppState>,
|
||||
parameters: CreateUser,
|
||||
) -> Result<User, String> {
|
||||
match &state
|
||||
.0
|
||||
.lock()
|
||||
.await
|
||||
.metadata_db
|
||||
.create_user(parameters.clone())
|
||||
.await
|
||||
{
|
||||
Ok(new_user_option) => match new_user_option {
|
||||
Some(new_user) => Ok(new_user.clone()),
|
||||
None => Err("User creation failed".to_string()),
|
||||
},
|
||||
Err(error_message) => Err(error_message.to_string()),
|
||||
}
|
||||
}
|
||||
@@ -6,3 +6,4 @@ extern crate jwst_storage;
|
||||
pub mod blob;
|
||||
pub mod document;
|
||||
pub mod workspace;
|
||||
pub mod user;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
use jwst_storage::{CreateUser, User};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
|
||||
pub enum IUserParameters {
|
||||
CreateUser(CreateUser),
|
||||
User(User),
|
||||
}
|
||||
Reference in New Issue
Block a user