Skip to content

Commit d04eae9

Browse files
committed
feat: add optional name param for workspace creation
1 parent 353065d commit d04eae9

File tree

5 files changed

+30
-11
lines changed

5 files changed

+30
-11
lines changed

libs/client-api/src/http.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::notify::{ClientToken, TokenStateReceiver};
22
use anyhow::Context;
33
use brotli::CompressorReader;
44
use gotrue_entity::dto::AuthProvider;
5+
use shared_entity::dto::workspace_dto::CreateWorkspaceParam;
56
use std::io::Read;
67

78
use app_error::AppError;
@@ -503,12 +504,15 @@ impl Client {
503504
}
504505

505506
#[instrument(level = "debug", skip_all, err)]
506-
pub async fn add_workspace(&self) -> Result<AFWorkspace, AppResponseError> {
507+
pub async fn create_workspace(
508+
&self,
509+
params: CreateWorkspaceParam,
510+
) -> Result<AFWorkspace, AppResponseError> {
507511
let url = format!("{}/api/workspace", self.base_url);
508512
let resp = self
509513
.http_client_with_auth(Method::POST, &url)
510514
.await?
511-
.json(&())
515+
.json(&params)
512516
.send()
513517
.await?;
514518
log_request_id(&resp);

libs/database-entity/src/dto.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ pub struct AFUserProfile {
416416
pub updated_at: i64,
417417
}
418418

419-
#[derive(Serialize, Deserialize)]
419+
#[derive(Debug, Serialize, Deserialize)]
420420
pub struct AFWorkspace {
421421
pub workspace_id: Uuid,
422422
pub database_storage_id: Uuid,

libs/shared-entity/src/dto/workspace_dto.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ impl From<Vec<CreateWorkspaceMember>> for CreateWorkspaceMembers {
2929
}
3030
}
3131

32-
#[derive(Deserialize)]
33-
pub struct CreateWorkspace {
34-
pub name: Option<String>,
35-
}
36-
3732
#[derive(Deserialize, Serialize)]
3833
pub struct CreateWorkspaceMember {
3934
pub email: String,
@@ -82,3 +77,8 @@ pub struct BlobMetadata {
8277
pub file_size: i64,
8378
pub modified_at: DateTime<Utc>,
8479
}
80+
81+
#[derive(Serialize, Deserialize)]
82+
pub struct CreateWorkspaceParam {
83+
pub workspace_name: Option<String>,
84+
}

src/api/workspace.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ pub fn collab_scope() -> Scope {
119119
async fn create_workpace_handler(
120120
uuid: UserUuid,
121121
state: Data<AppState>,
122-
create_workspace_param: Json<CreateWorkspace>,
122+
create_workspace_param: Json<CreateWorkspaceParam>,
123123
) -> Result<Json<AppResponse<AFWorkspace>>> {
124124
let workspace_name = create_workspace_param
125125
.into_inner()
126-
.name
126+
.workspace_name
127127
.unwrap_or_else(|| format!("workspace_{}", chrono::Utc::now().timestamp()));
128128
let new_workspace =
129129
workspace::ops::create_workspace_for_user(&state.pg_pool, &uuid, &workspace_name).await?;
@@ -140,6 +140,7 @@ async fn delete_workspace_handler(
140140
Ok(AppResponse::Ok().into())
141141
}
142142

143+
// TODO: also get shared workspaces
143144
#[instrument(skip_all, err)]
144145
async fn list_workspace_handler(
145146
uuid: UserUuid,

tests/workspace/workspace_crud.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
use client_api_test_util::generate_unique_registered_user_client;
2+
use shared_entity::dto::workspace_dto::CreateWorkspaceParam;
23

34
#[tokio::test]
45
async fn add_and_delete_workspace_for_user() {
56
let (c, _user) = generate_unique_registered_user_client().await;
67
let workspaces = c.get_workspaces().await.unwrap();
78
assert_eq!(workspaces.0.len(), 1);
8-
let newly_addad_workspace = c.add_workspace().await.unwrap();
9+
let newly_addad_workspace = c
10+
.create_workspace(CreateWorkspaceParam {
11+
workspace_name: Some("my_workspace".to_string()),
12+
})
13+
.await
14+
.unwrap();
915
let workspaces = c.get_workspaces().await.unwrap();
1016
assert_eq!(workspaces.0.len(), 2);
1117

18+
let _ = workspaces
19+
.0
20+
.iter()
21+
.find(|w| {
22+
w.workspace_name == "my_workspace" && w.workspace_id == newly_addad_workspace.workspace_id
23+
})
24+
.unwrap();
25+
1226
c.delete_workspace(&newly_addad_workspace.workspace_id.to_string())
1327
.await
1428
.unwrap();

0 commit comments

Comments
 (0)