feat: add optional name param for workspace creation
This commit is contained in:
parent
353065dfbf
commit
d04eae91e9
|
|
@ -2,6 +2,7 @@ use crate::notify::{ClientToken, TokenStateReceiver};
|
||||||
use anyhow::Context;
|
use anyhow::Context;
|
||||||
use brotli::CompressorReader;
|
use brotli::CompressorReader;
|
||||||
use gotrue_entity::dto::AuthProvider;
|
use gotrue_entity::dto::AuthProvider;
|
||||||
|
use shared_entity::dto::workspace_dto::CreateWorkspaceParam;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
|
||||||
use app_error::AppError;
|
use app_error::AppError;
|
||||||
|
|
@ -503,12 +504,15 @@ impl Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(level = "debug", skip_all, err)]
|
#[instrument(level = "debug", skip_all, err)]
|
||||||
pub async fn add_workspace(&self) -> Result<AFWorkspace, AppResponseError> {
|
pub async fn create_workspace(
|
||||||
|
&self,
|
||||||
|
params: CreateWorkspaceParam,
|
||||||
|
) -> Result<AFWorkspace, AppResponseError> {
|
||||||
let url = format!("{}/api/workspace", self.base_url);
|
let url = format!("{}/api/workspace", self.base_url);
|
||||||
let resp = self
|
let resp = self
|
||||||
.http_client_with_auth(Method::POST, &url)
|
.http_client_with_auth(Method::POST, &url)
|
||||||
.await?
|
.await?
|
||||||
.json(&())
|
.json(¶ms)
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
log_request_id(&resp);
|
log_request_id(&resp);
|
||||||
|
|
|
||||||
|
|
@ -416,7 +416,7 @@ pub struct AFUserProfile {
|
||||||
pub updated_at: i64,
|
pub updated_at: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
pub struct AFWorkspace {
|
pub struct AFWorkspace {
|
||||||
pub workspace_id: Uuid,
|
pub workspace_id: Uuid,
|
||||||
pub database_storage_id: Uuid,
|
pub database_storage_id: Uuid,
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,6 @@ impl From<Vec<CreateWorkspaceMember>> for CreateWorkspaceMembers {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
|
||||||
pub struct CreateWorkspace {
|
|
||||||
pub name: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
pub struct CreateWorkspaceMember {
|
pub struct CreateWorkspaceMember {
|
||||||
pub email: String,
|
pub email: String,
|
||||||
|
|
@ -82,3 +77,8 @@ pub struct BlobMetadata {
|
||||||
pub file_size: i64,
|
pub file_size: i64,
|
||||||
pub modified_at: DateTime<Utc>,
|
pub modified_at: DateTime<Utc>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct CreateWorkspaceParam {
|
||||||
|
pub workspace_name: Option<String>,
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -119,11 +119,11 @@ pub fn collab_scope() -> Scope {
|
||||||
async fn create_workpace_handler(
|
async fn create_workpace_handler(
|
||||||
uuid: UserUuid,
|
uuid: UserUuid,
|
||||||
state: Data<AppState>,
|
state: Data<AppState>,
|
||||||
create_workspace_param: Json<CreateWorkspace>,
|
create_workspace_param: Json<CreateWorkspaceParam>,
|
||||||
) -> Result<Json<AppResponse<AFWorkspace>>> {
|
) -> Result<Json<AppResponse<AFWorkspace>>> {
|
||||||
let workspace_name = create_workspace_param
|
let workspace_name = create_workspace_param
|
||||||
.into_inner()
|
.into_inner()
|
||||||
.name
|
.workspace_name
|
||||||
.unwrap_or_else(|| format!("workspace_{}", chrono::Utc::now().timestamp()));
|
.unwrap_or_else(|| format!("workspace_{}", chrono::Utc::now().timestamp()));
|
||||||
let new_workspace =
|
let new_workspace =
|
||||||
workspace::ops::create_workspace_for_user(&state.pg_pool, &uuid, &workspace_name).await?;
|
workspace::ops::create_workspace_for_user(&state.pg_pool, &uuid, &workspace_name).await?;
|
||||||
|
|
@ -140,6 +140,7 @@ async fn delete_workspace_handler(
|
||||||
Ok(AppResponse::Ok().into())
|
Ok(AppResponse::Ok().into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: also get shared workspaces
|
||||||
#[instrument(skip_all, err)]
|
#[instrument(skip_all, err)]
|
||||||
async fn list_workspace_handler(
|
async fn list_workspace_handler(
|
||||||
uuid: UserUuid,
|
uuid: UserUuid,
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,28 @@
|
||||||
use client_api_test_util::generate_unique_registered_user_client;
|
use client_api_test_util::generate_unique_registered_user_client;
|
||||||
|
use shared_entity::dto::workspace_dto::CreateWorkspaceParam;
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn add_and_delete_workspace_for_user() {
|
async fn add_and_delete_workspace_for_user() {
|
||||||
let (c, _user) = generate_unique_registered_user_client().await;
|
let (c, _user) = generate_unique_registered_user_client().await;
|
||||||
let workspaces = c.get_workspaces().await.unwrap();
|
let workspaces = c.get_workspaces().await.unwrap();
|
||||||
assert_eq!(workspaces.0.len(), 1);
|
assert_eq!(workspaces.0.len(), 1);
|
||||||
let newly_addad_workspace = c.add_workspace().await.unwrap();
|
let newly_addad_workspace = c
|
||||||
|
.create_workspace(CreateWorkspaceParam {
|
||||||
|
workspace_name: Some("my_workspace".to_string()),
|
||||||
|
})
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
let workspaces = c.get_workspaces().await.unwrap();
|
let workspaces = c.get_workspaces().await.unwrap();
|
||||||
assert_eq!(workspaces.0.len(), 2);
|
assert_eq!(workspaces.0.len(), 2);
|
||||||
|
|
||||||
|
let _ = workspaces
|
||||||
|
.0
|
||||||
|
.iter()
|
||||||
|
.find(|w| {
|
||||||
|
w.workspace_name == "my_workspace" && w.workspace_id == newly_addad_workspace.workspace_id
|
||||||
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
c.delete_workspace(&newly_addad_workspace.workspace_id.to_string())
|
c.delete_workspace(&newly_addad_workspace.workspace_id.to_string())
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue