fix: user id is now string, we need to get default on local

This commit is contained in:
linonetwo
2023-02-09 19:51:56 +08:00
parent fccf7e2f12
commit 483d1d67c6
11 changed files with 83 additions and 27 deletions
+1
View File
@@ -16,6 +16,7 @@ pub fn invoke_handler() -> impl Fn(tauri::Invoke) + Send + Sync + 'static {
get_workspaces,
get_workspace,
create_user,
get_user,
create_doc,
get_doc,
put_blob,
+15 -2
View File
@@ -1,5 +1,5 @@
use cloud_database::{CreateUser, User};
use ipc_types::document::CreateDocumentParameter;
use ipc_types::{document::CreateDocumentParameter, user::GetUserParameters};
use crate::state::AppState;
@@ -18,7 +18,7 @@ pub async fn create_user<'s>(
.metadata_db
.create_user(parameters.clone())
.await;
match new_user_result{
match new_user_result {
Ok(new_user_option) => match new_user_option {
Some((new_user, new_workspace)) => {
// a new private workspace is created, we have to create a yDoc for it
@@ -38,3 +38,16 @@ pub async fn create_user<'s>(
Err(error_message) => Err(error_message.to_string()),
}
}
#[tauri::command]
/// get the only one user in local sqlite
pub async fn get_user<'s>(
state: tauri::State<'s, AppState>,
parameters: GetUserParameters,
) -> Result<User, String> {
let db = &state.0.lock().await.metadata_db;
match db.get_user_by_email(&parameters.email).await.ok().unwrap() {
Some(user) => Ok(user),
None => Err("User not found".to_string()),
}
}
+6
View File
@@ -2,8 +2,14 @@ use cloud_database::{CreateUser, User};
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct GetUserParameters {
pub email: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub enum IUserParameters {
CreateUser(CreateUser),
User(User),
GetUserParameters(GetUserParameters),
}
+1 -2
View File
@@ -14,8 +14,7 @@ pub struct CreateWorkspace {
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]
pub struct GetWorkspaces {
// TODO: make all id string, on Octobase side, and rewrite all related tests
pub user_id: i32,
pub user_id: String,
}
#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema)]