File tree Expand file tree Collapse file tree 5 files changed +30
-11
lines changed Expand file tree Collapse file tree 5 files changed +30
-11
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ use crate::notify::{ClientToken, TokenStateReceiver};
2
2
use anyhow:: Context ;
3
3
use brotli:: CompressorReader ;
4
4
use gotrue_entity:: dto:: AuthProvider ;
5
+ use shared_entity:: dto:: workspace_dto:: CreateWorkspaceParam ;
5
6
use std:: io:: Read ;
6
7
7
8
use app_error:: AppError ;
@@ -503,12 +504,15 @@ impl Client {
503
504
}
504
505
505
506
#[ 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 > {
507
511
let url = format ! ( "{}/api/workspace" , self . base_url) ;
508
512
let resp = self
509
513
. http_client_with_auth ( Method :: POST , & url)
510
514
. await ?
511
- . json ( & ( ) )
515
+ . json ( & params )
512
516
. send ( )
513
517
. await ?;
514
518
log_request_id ( & resp) ;
Original file line number Diff line number Diff line change @@ -416,7 +416,7 @@ pub struct AFUserProfile {
416
416
pub updated_at : i64 ,
417
417
}
418
418
419
- #[ derive( Serialize , Deserialize ) ]
419
+ #[ derive( Debug , Serialize , Deserialize ) ]
420
420
pub struct AFWorkspace {
421
421
pub workspace_id : Uuid ,
422
422
pub database_storage_id : Uuid ,
Original file line number Diff line number Diff line change @@ -29,11 +29,6 @@ impl From<Vec<CreateWorkspaceMember>> for CreateWorkspaceMembers {
29
29
}
30
30
}
31
31
32
- #[ derive( Deserialize ) ]
33
- pub struct CreateWorkspace {
34
- pub name : Option < String > ,
35
- }
36
-
37
32
#[ derive( Deserialize , Serialize ) ]
38
33
pub struct CreateWorkspaceMember {
39
34
pub email : String ,
@@ -82,3 +77,8 @@ pub struct BlobMetadata {
82
77
pub file_size : i64 ,
83
78
pub modified_at : DateTime < Utc > ,
84
79
}
80
+
81
+ #[ derive( Serialize , Deserialize ) ]
82
+ pub struct CreateWorkspaceParam {
83
+ pub workspace_name : Option < String > ,
84
+ }
Original file line number Diff line number Diff line change @@ -119,11 +119,11 @@ pub fn collab_scope() -> Scope {
119
119
async fn create_workpace_handler (
120
120
uuid : UserUuid ,
121
121
state : Data < AppState > ,
122
- create_workspace_param : Json < CreateWorkspace > ,
122
+ create_workspace_param : Json < CreateWorkspaceParam > ,
123
123
) -> Result < Json < AppResponse < AFWorkspace > > > {
124
124
let workspace_name = create_workspace_param
125
125
. into_inner ( )
126
- . name
126
+ . workspace_name
127
127
. unwrap_or_else ( || format ! ( "workspace_{}" , chrono:: Utc :: now( ) . timestamp( ) ) ) ;
128
128
let new_workspace =
129
129
workspace:: ops:: create_workspace_for_user ( & state. pg_pool , & uuid, & workspace_name) . await ?;
@@ -140,6 +140,7 @@ async fn delete_workspace_handler(
140
140
Ok ( AppResponse :: Ok ( ) . into ( ) )
141
141
}
142
142
143
+ // TODO: also get shared workspaces
143
144
#[ instrument( skip_all, err) ]
144
145
async fn list_workspace_handler (
145
146
uuid : UserUuid ,
Original file line number Diff line number Diff line change 1
1
use client_api_test_util:: generate_unique_registered_user_client;
2
+ use shared_entity:: dto:: workspace_dto:: CreateWorkspaceParam ;
2
3
3
4
#[ tokio:: test]
4
5
async fn add_and_delete_workspace_for_user ( ) {
5
6
let ( c, _user) = generate_unique_registered_user_client ( ) . await ;
6
7
let workspaces = c. get_workspaces ( ) . await . unwrap ( ) ;
7
8
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 ( ) ;
9
15
let workspaces = c. get_workspaces ( ) . await . unwrap ( ) ;
10
16
assert_eq ! ( workspaces. 0 . len( ) , 2 ) ;
11
17
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
+
12
26
c. delete_workspace ( & newly_addad_workspace. workspace_id . to_string ( ) )
13
27
. await
14
28
. unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments