From 182adafee5f90d439491bdbe986a507fb8f35025 Mon Sep 17 00:00:00 2001 From: appflowy Date: Wed, 14 Jul 2021 21:12:52 +0800 Subject: [PATCH] add update user test & add app and workspace test --- .../protobuf/flowy-user/errors.pbenum.dart | 4 + .../protobuf/flowy-user/errors.pbjson.dart | 4 +- .../lib/protobuf/flowy-user/event.pbenum.dart | 2 + .../lib/protobuf/flowy-user/event.pbjson.dart | 3 +- .../lib/protobuf/flowy-user/protobuf.dart | 1 + .../protobuf/flowy-user/user_detail.pb.dart | 58 +- .../flowy-user/user_detail.pbjson.dart | 10 +- .../protobuf/flowy-user/user_update.pb.dart | 166 ++++++ .../flowy-user/user_update.pbenum.dart | 7 + .../flowy-user/user_update.pbjson.dart | 30 + .../flowy-user/user_update.pbserver.dart | 9 + .../flowy-workspace/app_create.pb.dart | 89 +++ .../flowy-workspace/app_create.pbjson.dart | 13 + .../flowy-workspace/errors.pbenum.dart | 2 + .../flowy-workspace/errors.pbjson.dart | 3 +- rust-lib/dart-ffi/src/lib.rs | 5 +- .../2021-07-14-022241_flowy-user/down.sql | 2 + .../2021-07-14-022241_flowy-user/up.sql | 2 + rust-lib/flowy-database/src/lib.rs | 8 + rust-lib/flowy-database/src/macros.rs | 15 + rust-lib/flowy-database/src/schema.rs | 1 + .../src/derive_cache/derive_cache.rs | 2 + rust-lib/flowy-sdk/src/flowy_server.rs | 46 ++ rust-lib/flowy-sdk/src/lib.rs | 43 +- rust-lib/flowy-sdk/src/module.rs | 44 +- rust-lib/flowy-test/src/lib.rs | 24 +- rust-lib/flowy-user/src/entities/mod.rs | 18 +- .../flowy-user/src/entities/parser/mod.rs | 12 + .../src/entities/{ => parser}/user_email.rs | 0 .../src/entities/{ => parser}/user_id.rs | 0 .../src/entities/{ => parser}/user_name.rs | 0 .../entities/{ => parser}/user_password.rs | 0 .../src/entities/parser/user_workspace.rs | 16 + rust-lib/flowy-user/src/entities/sign_in.rs | 5 +- rust-lib/flowy-user/src/entities/sign_up.rs | 2 +- .../flowy-user/src/entities/user_detail.rs | 12 +- .../flowy-user/src/entities/user_update.rs | 106 ++++ rust-lib/flowy-user/src/errors.rs | 4 + rust-lib/flowy-user/src/event.rs | 11 +- .../flowy-user/src/handlers/auth_handler.rs | 16 +- rust-lib/flowy-user/src/handlers/mod.rs | 4 +- .../flowy-user/src/handlers/user_handler.rs | 24 + rust-lib/flowy-user/src/lib.rs | 2 +- rust-lib/flowy-user/src/module.rs | 9 +- .../flowy-user/src/protobuf/model/errors.rs | 81 +-- .../flowy-user/src/protobuf/model/event.rs | 31 +- rust-lib/flowy-user/src/protobuf/model/mod.rs | 3 + .../src/protobuf/model/user_detail.rs | 159 +++-- .../src/protobuf/model/user_update.rs | 549 ++++++++++++++++++ .../src/protobuf/proto/errors.proto | 2 + .../flowy-user/src/protobuf/proto/event.proto | 1 + .../src/protobuf/proto/user_detail.proto | 8 +- .../src/protobuf/proto/user_update.proto | 9 + .../src/services/user_session/builder.rs | 11 +- .../src/services/user_session/mod.rs | 1 + .../src/services/user_session/user_server.rs | 34 +- .../src/services/user_session/user_session.rs | 55 +- rust-lib/flowy-user/src/sql_tables/mod.rs | 4 +- rust-lib/flowy-user/src/sql_tables/user.rs | 51 ++ .../flowy-user/src/sql_tables/user_table.rs | 21 - rust-lib/flowy-user/tests/event/helper.rs | 4 +- .../flowy-user/tests/event/sign_in_test.rs | 8 +- .../flowy-user/tests/event/sign_up_test.rs | 2 +- .../tests/event/user_status_test.rs | 43 +- rust-lib/flowy-workspace/Cargo.toml | 1 + .../src/entities/app/app_create.rs | 19 +- .../src/entities/app/app_update.rs | 7 +- .../flowy-workspace/src/entities/app/mod.rs | 10 +- .../app/{ => parser}/app_color_style.rs | 0 .../src/entities/app/{ => parser}/app_id.rs | 0 .../src/entities/app/{ => parser}/app_name.rs | 0 .../src/entities/app/parser/mod.rs | 7 + .../src/entities/workspace/mod.rs | 13 +- .../src/entities/workspace/parser/mod.rs | 5 + .../workspace/{ => parser}/workspace_id.rs | 0 .../workspace/{ => parser}/workspace_name.rs | 6 + .../entities/workspace/workspace_create.rs | 2 +- .../entities/workspace/workspace_update.rs | 9 +- rust-lib/flowy-workspace/src/errors.rs | 3 + .../src/handlers/app_handler.rs | 16 + rust-lib/flowy-workspace/src/handlers/mod.rs | 2 + rust-lib/flowy-workspace/src/macros.rs | 6 +- rust-lib/flowy-workspace/src/module.rs | 22 +- .../src/protobuf/model/app_create.rs | 322 +++++++++- .../src/protobuf/model/errors.rs | 55 +- .../src/protobuf/proto/app_create.proto | 6 + .../src/protobuf/proto/errors.proto | 1 + .../src/services/app_controller.rs | 34 ++ .../flowy-workspace/src/services/helper.rs | 1 + rust-lib/flowy-workspace/src/services/mod.rs | 3 + .../src/services/workspace_controller.rs | 64 +- .../flowy-workspace/src/sql_tables/app/app.rs | 15 +- .../src/sql_tables/workspace/workspace.rs | 7 +- .../flowy-workspace/tests/event/app_test.rs | 15 + .../flowy-workspace/tests/event/helper.rs | 7 + rust-lib/flowy-workspace/tests/event/main.rs | 1 + .../tests/event/workspace_test.rs | 45 +- 97 files changed, 2217 insertions(+), 398 deletions(-) create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pb.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pbenum.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pbjson.dart create mode 100644 app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pbserver.dart create mode 100644 rust-lib/flowy-database/migrations/2021-07-14-022241_flowy-user/down.sql create mode 100644 rust-lib/flowy-database/migrations/2021-07-14-022241_flowy-user/up.sql create mode 100644 rust-lib/flowy-database/src/macros.rs create mode 100644 rust-lib/flowy-sdk/src/flowy_server.rs create mode 100644 rust-lib/flowy-user/src/entities/parser/mod.rs rename rust-lib/flowy-user/src/entities/{ => parser}/user_email.rs (100%) rename rust-lib/flowy-user/src/entities/{ => parser}/user_id.rs (100%) rename rust-lib/flowy-user/src/entities/{ => parser}/user_name.rs (100%) rename rust-lib/flowy-user/src/entities/{ => parser}/user_password.rs (100%) create mode 100644 rust-lib/flowy-user/src/entities/parser/user_workspace.rs create mode 100644 rust-lib/flowy-user/src/entities/user_update.rs create mode 100644 rust-lib/flowy-user/src/handlers/user_handler.rs create mode 100644 rust-lib/flowy-user/src/protobuf/model/user_update.rs create mode 100644 rust-lib/flowy-user/src/protobuf/proto/user_update.proto create mode 100644 rust-lib/flowy-user/src/sql_tables/user.rs delete mode 100644 rust-lib/flowy-user/src/sql_tables/user_table.rs rename rust-lib/flowy-workspace/src/entities/app/{ => parser}/app_color_style.rs (100%) rename rust-lib/flowy-workspace/src/entities/app/{ => parser}/app_id.rs (100%) rename rust-lib/flowy-workspace/src/entities/app/{ => parser}/app_name.rs (100%) create mode 100644 rust-lib/flowy-workspace/src/entities/app/parser/mod.rs create mode 100644 rust-lib/flowy-workspace/src/entities/workspace/parser/mod.rs rename rust-lib/flowy-workspace/src/entities/workspace/{ => parser}/workspace_id.rs (100%) rename rust-lib/flowy-workspace/src/entities/workspace/{ => parser}/workspace_name.rs (69%) create mode 100644 rust-lib/flowy-workspace/src/handlers/app_handler.rs create mode 100644 rust-lib/flowy-workspace/src/services/app_controller.rs create mode 100644 rust-lib/flowy-workspace/src/services/helper.rs create mode 100644 rust-lib/flowy-workspace/tests/event/app_test.rs diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dart index 1d693f87e3..9b07cc71c3 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbenum.dart @@ -22,6 +22,8 @@ class UserErrorCode extends $pb.ProtobufEnum { static const UserErrorCode EmailInvalid = UserErrorCode._(20, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'EmailInvalid'); static const UserErrorCode PasswordInvalid = UserErrorCode._(21, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'PasswordInvalid'); static const UserErrorCode UserNameInvalid = UserErrorCode._(22, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserNameInvalid'); + static const UserErrorCode UserWorkspaceInvalid = UserErrorCode._(23, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserWorkspaceInvalid'); + static const UserErrorCode UserIdInvalid = UserErrorCode._(24, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserIdInvalid'); static const $core.List values = [ Unknown, @@ -36,6 +38,8 @@ class UserErrorCode extends $pb.ProtobufEnum { EmailInvalid, PasswordInvalid, UserNameInvalid, + UserWorkspaceInvalid, + UserIdInvalid, ]; static final $core.Map<$core.int, UserErrorCode> _byValue = $pb.ProtobufEnum.initByValue(values); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dart index 8c6bc09085..217cb44134 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/errors.pbjson.dart @@ -24,11 +24,13 @@ const UserErrorCode$json = const { const {'1': 'EmailInvalid', '2': 20}, const {'1': 'PasswordInvalid', '2': 21}, const {'1': 'UserNameInvalid', '2': 22}, + const {'1': 'UserWorkspaceInvalid', '2': 23}, + const {'1': 'UserIdInvalid', '2': 24}, ], }; /// Descriptor for `UserErrorCode`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List userErrorCodeDescriptor = $convert.base64Decode('Cg1Vc2VyRXJyb3JDb2RlEgsKB1Vua25vd24QABIWChJEYXRhYmFzZUluaXRGYWlsZWQQARIXChNEYXRhYmFzZVdyaXRlTG9ja2VkEAISFgoSRGF0YWJhc2VSZWFkTG9ja2VkEAMSGwoXRGF0YWJhc2VVc2VyRGlkTm90TWF0Y2gQBBIZChVEYXRhYmFzZUludGVybmFsRXJyb3IQBRITCg9Vc2VyTm90TG9naW5ZZXQQChIXChNSZWFkQ3VycmVudElkRmFpbGVkEAsSGAoUV3JpdGVDdXJyZW50SWRGYWlsZWQQDBIQCgxFbWFpbEludmFsaWQQFBITCg9QYXNzd29yZEludmFsaWQQFRITCg9Vc2VyTmFtZUludmFsaWQQFg=='); +final $typed_data.Uint8List userErrorCodeDescriptor = $convert.base64Decode('Cg1Vc2VyRXJyb3JDb2RlEgsKB1Vua25vd24QABIWChJEYXRhYmFzZUluaXRGYWlsZWQQARIXChNEYXRhYmFzZVdyaXRlTG9ja2VkEAISFgoSRGF0YWJhc2VSZWFkTG9ja2VkEAMSGwoXRGF0YWJhc2VVc2VyRGlkTm90TWF0Y2gQBBIZChVEYXRhYmFzZUludGVybmFsRXJyb3IQBRITCg9Vc2VyTm90TG9naW5ZZXQQChIXChNSZWFkQ3VycmVudElkRmFpbGVkEAsSGAoUV3JpdGVDdXJyZW50SWRGYWlsZWQQDBIQCgxFbWFpbEludmFsaWQQFBITCg9QYXNzd29yZEludmFsaWQQFRITCg9Vc2VyTmFtZUludmFsaWQQFhIYChRVc2VyV29ya3NwYWNlSW52YWxpZBAXEhEKDVVzZXJJZEludmFsaWQQGA=='); @$core.Deprecated('Use userErrorDescriptor instead') const UserError$json = const { '1': 'UserError', diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/event.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/event.pbenum.dart index ce184a3fc8..9cd1a5ad21 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/event.pbenum.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/event.pbenum.dart @@ -14,12 +14,14 @@ class UserEvent extends $pb.ProtobufEnum { static const UserEvent SignIn = UserEvent._(1, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'SignIn'); static const UserEvent SignUp = UserEvent._(2, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'SignUp'); static const UserEvent SignOut = UserEvent._(3, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'SignOut'); + static const UserEvent UpdateUser = UserEvent._(4, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UpdateUser'); static const $core.List values = [ GetStatus, SignIn, SignUp, SignOut, + UpdateUser, ]; static final $core.Map<$core.int, UserEvent> _byValue = $pb.ProtobufEnum.initByValue(values); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/event.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/event.pbjson.dart index 22561662a4..b514b74420 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/event.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/event.pbjson.dart @@ -16,8 +16,9 @@ const UserEvent$json = const { const {'1': 'SignIn', '2': 1}, const {'1': 'SignUp', '2': 2}, const {'1': 'SignOut', '2': 3}, + const {'1': 'UpdateUser', '2': 4}, ], }; /// Descriptor for `UserEvent`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List userEventDescriptor = $convert.base64Decode('CglVc2VyRXZlbnQSDQoJR2V0U3RhdHVzEAASCgoGU2lnbkluEAESCgoGU2lnblVwEAISCwoHU2lnbk91dBAD'); +final $typed_data.Uint8List userEventDescriptor = $convert.base64Decode('CglVc2VyRXZlbnQSDQoJR2V0U3RhdHVzEAASCgoGU2lnbkluEAESCgoGU2lnblVwEAISCwoHU2lnbk91dBADEg4KClVwZGF0ZVVzZXIQBA=='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/protobuf.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/protobuf.dart index 2032b9f5c2..3776e46038 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/protobuf.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/protobuf.dart @@ -4,4 +4,5 @@ export './sign_in.pb.dart'; export './user_table.pb.dart'; export './errors.pb.dart'; export './user_detail.pb.dart'; +export './user_update.pb.dart'; export './event.pb.dart'; diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_detail.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_detail.pb.dart index 0589e58a8b..6dc1482726 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_detail.pb.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_detail.pb.dart @@ -15,19 +15,26 @@ export 'user_detail.pbenum.dart'; class UserDetail extends $pb.GeneratedMessage { static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UserDetail', createEmptyInstance: create) - ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'email') - ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') - ..e(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'status', $pb.PbFieldType.OE, defaultOrMaker: UserStatus.Unknown, valueOf: UserStatus.valueOf, enumValues: UserStatus.values) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id') + ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'email') + ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') + ..e(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'status', $pb.PbFieldType.OE, defaultOrMaker: UserStatus.Unknown, valueOf: UserStatus.valueOf, enumValues: UserStatus.values) + ..aOS(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'workspace') ..hasRequiredFields = false ; UserDetail._() : super(); factory UserDetail({ + $core.String? id, $core.String? email, $core.String? name, UserStatus? status, + $core.String? workspace, }) { final _result = create(); + if (id != null) { + _result.id = id; + } if (email != null) { _result.email = email; } @@ -37,6 +44,9 @@ class UserDetail extends $pb.GeneratedMessage { if (status != null) { _result.status = status; } + if (workspace != null) { + _result.workspace = workspace; + } return _result; } factory UserDetail.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); @@ -61,30 +71,48 @@ class UserDetail extends $pb.GeneratedMessage { static UserDetail? _defaultInstance; @$pb.TagNumber(1) - $core.String get email => $_getSZ(0); + $core.String get id => $_getSZ(0); @$pb.TagNumber(1) - set email($core.String v) { $_setString(0, v); } + set id($core.String v) { $_setString(0, v); } @$pb.TagNumber(1) - $core.bool hasEmail() => $_has(0); + $core.bool hasId() => $_has(0); @$pb.TagNumber(1) - void clearEmail() => clearField(1); + void clearId() => clearField(1); @$pb.TagNumber(2) - $core.String get name => $_getSZ(1); + $core.String get email => $_getSZ(1); @$pb.TagNumber(2) - set name($core.String v) { $_setString(1, v); } + set email($core.String v) { $_setString(1, v); } @$pb.TagNumber(2) - $core.bool hasName() => $_has(1); + $core.bool hasEmail() => $_has(1); @$pb.TagNumber(2) - void clearName() => clearField(2); + void clearEmail() => clearField(2); @$pb.TagNumber(3) - UserStatus get status => $_getN(2); + $core.String get name => $_getSZ(2); @$pb.TagNumber(3) - set status(UserStatus v) { setField(3, v); } + set name($core.String v) { $_setString(2, v); } @$pb.TagNumber(3) - $core.bool hasStatus() => $_has(2); + $core.bool hasName() => $_has(2); @$pb.TagNumber(3) - void clearStatus() => clearField(3); + void clearName() => clearField(3); + + @$pb.TagNumber(4) + UserStatus get status => $_getN(3); + @$pb.TagNumber(4) + set status(UserStatus v) { setField(4, v); } + @$pb.TagNumber(4) + $core.bool hasStatus() => $_has(3); + @$pb.TagNumber(4) + void clearStatus() => clearField(4); + + @$pb.TagNumber(5) + $core.String get workspace => $_getSZ(4); + @$pb.TagNumber(5) + set workspace($core.String v) { $_setString(4, v); } + @$pb.TagNumber(5) + $core.bool hasWorkspace() => $_has(4); + @$pb.TagNumber(5) + void clearWorkspace() => clearField(5); } diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_detail.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_detail.pbjson.dart index 55617844b6..608b1131f5 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_detail.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_detail.pbjson.dart @@ -24,11 +24,13 @@ final $typed_data.Uint8List userStatusDescriptor = $convert.base64Decode('CgpVc2 const UserDetail$json = const { '1': 'UserDetail', '2': const [ - const {'1': 'email', '3': 1, '4': 1, '5': 9, '10': 'email'}, - const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'}, - const {'1': 'status', '3': 3, '4': 1, '5': 14, '6': '.UserStatus', '10': 'status'}, + const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'}, + const {'1': 'email', '3': 2, '4': 1, '5': 9, '10': 'email'}, + const {'1': 'name', '3': 3, '4': 1, '5': 9, '10': 'name'}, + const {'1': 'status', '3': 4, '4': 1, '5': 14, '6': '.UserStatus', '10': 'status'}, + const {'1': 'workspace', '3': 5, '4': 1, '5': 9, '10': 'workspace'}, ], }; /// Descriptor for `UserDetail`. Decode as a `google.protobuf.DescriptorProto`. -final $typed_data.Uint8List userDetailDescriptor = $convert.base64Decode('CgpVc2VyRGV0YWlsEhQKBWVtYWlsGAEgASgJUgVlbWFpbBISCgRuYW1lGAIgASgJUgRuYW1lEiMKBnN0YXR1cxgDIAEoDjILLlVzZXJTdGF0dXNSBnN0YXR1cw=='); +final $typed_data.Uint8List userDetailDescriptor = $convert.base64Decode('CgpVc2VyRGV0YWlsEg4KAmlkGAEgASgJUgJpZBIUCgVlbWFpbBgCIAEoCVIFZW1haWwSEgoEbmFtZRgDIAEoCVIEbmFtZRIjCgZzdGF0dXMYBCABKA4yCy5Vc2VyU3RhdHVzUgZzdGF0dXMSHAoJd29ya3NwYWNlGAUgASgJUgl3b3Jrc3BhY2U='); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pb.dart new file mode 100644 index 0000000000..f85989c260 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pb.dart @@ -0,0 +1,166 @@ +/// +// Generated code. Do not modify. +// source: user_update.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + +import 'dart:core' as $core; + +import 'package:protobuf/protobuf.dart' as $pb; + +enum UpdateUserRequest_OneOfName { + name, + notSet +} + +enum UpdateUserRequest_OneOfEmail { + email, + notSet +} + +enum UpdateUserRequest_OneOfWorkspace { + workspace, + notSet +} + +enum UpdateUserRequest_OneOfPassword { + password, + notSet +} + +class UpdateUserRequest extends $pb.GeneratedMessage { + static const $core.Map<$core.int, UpdateUserRequest_OneOfName> _UpdateUserRequest_OneOfNameByTag = { + 2 : UpdateUserRequest_OneOfName.name, + 0 : UpdateUserRequest_OneOfName.notSet + }; + static const $core.Map<$core.int, UpdateUserRequest_OneOfEmail> _UpdateUserRequest_OneOfEmailByTag = { + 3 : UpdateUserRequest_OneOfEmail.email, + 0 : UpdateUserRequest_OneOfEmail.notSet + }; + static const $core.Map<$core.int, UpdateUserRequest_OneOfWorkspace> _UpdateUserRequest_OneOfWorkspaceByTag = { + 4 : UpdateUserRequest_OneOfWorkspace.workspace, + 0 : UpdateUserRequest_OneOfWorkspace.notSet + }; + static const $core.Map<$core.int, UpdateUserRequest_OneOfPassword> _UpdateUserRequest_OneOfPasswordByTag = { + 5 : UpdateUserRequest_OneOfPassword.password, + 0 : UpdateUserRequest_OneOfPassword.notSet + }; + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UpdateUserRequest', createEmptyInstance: create) + ..oo(0, [2]) + ..oo(1, [3]) + ..oo(2, [4]) + ..oo(3, [5]) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id') + ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') + ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'email') + ..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'workspace') + ..aOS(5, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'password') + ..hasRequiredFields = false + ; + + UpdateUserRequest._() : super(); + factory UpdateUserRequest({ + $core.String? id, + $core.String? name, + $core.String? email, + $core.String? workspace, + $core.String? password, + }) { + final _result = create(); + if (id != null) { + _result.id = id; + } + if (name != null) { + _result.name = name; + } + if (email != null) { + _result.email = email; + } + if (workspace != null) { + _result.workspace = workspace; + } + if (password != null) { + _result.password = password; + } + return _result; + } + factory UpdateUserRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory UpdateUserRequest.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + UpdateUserRequest clone() => UpdateUserRequest()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + UpdateUserRequest copyWith(void Function(UpdateUserRequest) updates) => super.copyWith((message) => updates(message as UpdateUserRequest)) as UpdateUserRequest; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static UpdateUserRequest create() => UpdateUserRequest._(); + UpdateUserRequest createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static UpdateUserRequest getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static UpdateUserRequest? _defaultInstance; + + UpdateUserRequest_OneOfName whichOneOfName() => _UpdateUserRequest_OneOfNameByTag[$_whichOneof(0)]!; + void clearOneOfName() => clearField($_whichOneof(0)); + + UpdateUserRequest_OneOfEmail whichOneOfEmail() => _UpdateUserRequest_OneOfEmailByTag[$_whichOneof(1)]!; + void clearOneOfEmail() => clearField($_whichOneof(1)); + + UpdateUserRequest_OneOfWorkspace whichOneOfWorkspace() => _UpdateUserRequest_OneOfWorkspaceByTag[$_whichOneof(2)]!; + void clearOneOfWorkspace() => clearField($_whichOneof(2)); + + UpdateUserRequest_OneOfPassword whichOneOfPassword() => _UpdateUserRequest_OneOfPasswordByTag[$_whichOneof(3)]!; + void clearOneOfPassword() => clearField($_whichOneof(3)); + + @$pb.TagNumber(1) + $core.String get id => $_getSZ(0); + @$pb.TagNumber(1) + set id($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasId() => $_has(0); + @$pb.TagNumber(1) + void clearId() => clearField(1); + + @$pb.TagNumber(2) + $core.String get name => $_getSZ(1); + @$pb.TagNumber(2) + set name($core.String v) { $_setString(1, v); } + @$pb.TagNumber(2) + $core.bool hasName() => $_has(1); + @$pb.TagNumber(2) + void clearName() => clearField(2); + + @$pb.TagNumber(3) + $core.String get email => $_getSZ(2); + @$pb.TagNumber(3) + set email($core.String v) { $_setString(2, v); } + @$pb.TagNumber(3) + $core.bool hasEmail() => $_has(2); + @$pb.TagNumber(3) + void clearEmail() => clearField(3); + + @$pb.TagNumber(4) + $core.String get workspace => $_getSZ(3); + @$pb.TagNumber(4) + set workspace($core.String v) { $_setString(3, v); } + @$pb.TagNumber(4) + $core.bool hasWorkspace() => $_has(3); + @$pb.TagNumber(4) + void clearWorkspace() => clearField(4); + + @$pb.TagNumber(5) + $core.String get password => $_getSZ(4); + @$pb.TagNumber(5) + set password($core.String v) { $_setString(4, v); } + @$pb.TagNumber(5) + $core.bool hasPassword() => $_has(4); + @$pb.TagNumber(5) + void clearPassword() => clearField(5); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pbenum.dart new file mode 100644 index 0000000000..b2d9d57d6d --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pbenum.dart @@ -0,0 +1,7 @@ +/// +// Generated code. Do not modify. +// source: user_update.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pbjson.dart new file mode 100644 index 0000000000..29476cdf02 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pbjson.dart @@ -0,0 +1,30 @@ +/// +// Generated code. Do not modify. +// source: user_update.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +import 'dart:core' as $core; +import 'dart:convert' as $convert; +import 'dart:typed_data' as $typed_data; +@$core.Deprecated('Use updateUserRequestDescriptor instead') +const UpdateUserRequest$json = const { + '1': 'UpdateUserRequest', + '2': const [ + const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'}, + const {'1': 'name', '3': 2, '4': 1, '5': 9, '9': 0, '10': 'name'}, + const {'1': 'email', '3': 3, '4': 1, '5': 9, '9': 1, '10': 'email'}, + const {'1': 'workspace', '3': 4, '4': 1, '5': 9, '9': 2, '10': 'workspace'}, + const {'1': 'password', '3': 5, '4': 1, '5': 9, '9': 3, '10': 'password'}, + ], + '8': const [ + const {'1': 'one_of_name'}, + const {'1': 'one_of_email'}, + const {'1': 'one_of_workspace'}, + const {'1': 'one_of_password'}, + ], +}; + +/// Descriptor for `UpdateUserRequest`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List updateUserRequestDescriptor = $convert.base64Decode('ChFVcGRhdGVVc2VyUmVxdWVzdBIOCgJpZBgBIAEoCVICaWQSFAoEbmFtZRgCIAEoCUgAUgRuYW1lEhYKBWVtYWlsGAMgASgJSAFSBWVtYWlsEh4KCXdvcmtzcGFjZRgEIAEoCUgCUgl3b3Jrc3BhY2USHAoIcGFzc3dvcmQYBSABKAlIA1IIcGFzc3dvcmRCDQoLb25lX29mX25hbWVCDgoMb25lX29mX2VtYWlsQhIKEG9uZV9vZl93b3Jrc3BhY2VCEQoPb25lX29mX3Bhc3N3b3Jk'); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pbserver.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pbserver.dart new file mode 100644 index 0000000000..ead5954726 --- /dev/null +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-user/user_update.pbserver.dart @@ -0,0 +1,9 @@ +/// +// Generated code. Do not modify. +// source: user_update.proto +// +// @dart = 2.12 +// ignore_for_file: annotate_overrides,camel_case_types,unnecessary_const,non_constant_identifier_names,library_prefixes,unused_import,unused_shown_name,return_of_invalid_type,unnecessary_this,prefer_final_fields,deprecated_member_use_from_same_package + +export 'user_update.pb.dart'; + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pb.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pb.dart index bda773c373..7358eb7dca 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pb.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pb.dart @@ -147,3 +147,92 @@ class ColorStyle extends $pb.GeneratedMessage { void clearThemeColor() => clearField(1); } +class AppDetail extends $pb.GeneratedMessage { + static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'AppDetail', createEmptyInstance: create) + ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id') + ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'workspaceId') + ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name') + ..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc') + ..hasRequiredFields = false + ; + + AppDetail._() : super(); + factory AppDetail({ + $core.String? id, + $core.String? workspaceId, + $core.String? name, + $core.String? desc, + }) { + final _result = create(); + if (id != null) { + _result.id = id; + } + if (workspaceId != null) { + _result.workspaceId = workspaceId; + } + if (name != null) { + _result.name = name; + } + if (desc != null) { + _result.desc = desc; + } + return _result; + } + factory AppDetail.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r); + factory AppDetail.fromJson($core.String i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromJson(i, r); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.deepCopy] instead. ' + 'Will be removed in next major version') + AppDetail clone() => AppDetail()..mergeFromMessage(this); + @$core.Deprecated( + 'Using this can add significant overhead to your binary. ' + 'Use [GeneratedMessageGenericExtensions.rebuild] instead. ' + 'Will be removed in next major version') + AppDetail copyWith(void Function(AppDetail) updates) => super.copyWith((message) => updates(message as AppDetail)) as AppDetail; // ignore: deprecated_member_use + $pb.BuilderInfo get info_ => _i; + @$core.pragma('dart2js:noInline') + static AppDetail create() => AppDetail._(); + AppDetail createEmptyInstance() => create(); + static $pb.PbList createRepeated() => $pb.PbList(); + @$core.pragma('dart2js:noInline') + static AppDetail getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor(create); + static AppDetail? _defaultInstance; + + @$pb.TagNumber(1) + $core.String get id => $_getSZ(0); + @$pb.TagNumber(1) + set id($core.String v) { $_setString(0, v); } + @$pb.TagNumber(1) + $core.bool hasId() => $_has(0); + @$pb.TagNumber(1) + void clearId() => clearField(1); + + @$pb.TagNumber(2) + $core.String get workspaceId => $_getSZ(1); + @$pb.TagNumber(2) + set workspaceId($core.String v) { $_setString(1, v); } + @$pb.TagNumber(2) + $core.bool hasWorkspaceId() => $_has(1); + @$pb.TagNumber(2) + void clearWorkspaceId() => clearField(2); + + @$pb.TagNumber(3) + $core.String get name => $_getSZ(2); + @$pb.TagNumber(3) + set name($core.String v) { $_setString(2, v); } + @$pb.TagNumber(3) + $core.bool hasName() => $_has(2); + @$pb.TagNumber(3) + void clearName() => clearField(3); + + @$pb.TagNumber(4) + $core.String get desc => $_getSZ(3); + @$pb.TagNumber(4) + set desc($core.String v) { $_setString(3, v); } + @$pb.TagNumber(4) + $core.bool hasDesc() => $_has(3); + @$pb.TagNumber(4) + void clearDesc() => clearField(4); +} + diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbjson.dart index 25137cc238..3e2548d302 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/app_create.pbjson.dart @@ -31,3 +31,16 @@ const ColorStyle$json = const { /// Descriptor for `ColorStyle`. Decode as a `google.protobuf.DescriptorProto`. final $typed_data.Uint8List colorStyleDescriptor = $convert.base64Decode('CgpDb2xvclN0eWxlEh8KC3RoZW1lX2NvbG9yGAEgASgJUgp0aGVtZUNvbG9y'); +@$core.Deprecated('Use appDetailDescriptor instead') +const AppDetail$json = const { + '1': 'AppDetail', + '2': const [ + const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'}, + const {'1': 'workspace_id', '3': 2, '4': 1, '5': 9, '10': 'workspaceId'}, + const {'1': 'name', '3': 3, '4': 1, '5': 9, '10': 'name'}, + const {'1': 'desc', '3': 4, '4': 1, '5': 9, '10': 'desc'}, + ], +}; + +/// Descriptor for `AppDetail`. Decode as a `google.protobuf.DescriptorProto`. +final $typed_data.Uint8List appDetailDescriptor = $convert.base64Decode('CglBcHBEZXRhaWwSDgoCaWQYASABKAlSAmlkEiEKDHdvcmtzcGFjZV9pZBgCIAEoCVILd29ya3NwYWNlSWQSEgoEbmFtZRgDIAEoCVIEbmFtZRISCgRkZXNjGAQgASgJUgRkZXNj'); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbenum.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbenum.dart index 851c65355d..37693a76d2 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbenum.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbenum.dart @@ -17,6 +17,7 @@ class WorkspaceErrorCode extends $pb.ProtobufEnum { static const WorkspaceErrorCode AppIdInvalid = WorkspaceErrorCode._(4, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'AppIdInvalid'); static const WorkspaceErrorCode DatabaseConnectionFail = WorkspaceErrorCode._(5, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DatabaseConnectionFail'); static const WorkspaceErrorCode DatabaseInternalError = WorkspaceErrorCode._(6, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'DatabaseInternalError'); + static const WorkspaceErrorCode UserInternalError = WorkspaceErrorCode._(10, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'UserInternalError'); static const $core.List values = [ Unknown, @@ -26,6 +27,7 @@ class WorkspaceErrorCode extends $pb.ProtobufEnum { AppIdInvalid, DatabaseConnectionFail, DatabaseInternalError, + UserInternalError, ]; static final $core.Map<$core.int, WorkspaceErrorCode> _byValue = $pb.ProtobufEnum.initByValue(values); diff --git a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbjson.dart b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbjson.dart index 53cb316fd0..e2ce8025a2 100644 --- a/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbjson.dart +++ b/app_flowy/packages/flowy_sdk/lib/protobuf/flowy-workspace/errors.pbjson.dart @@ -19,11 +19,12 @@ const WorkspaceErrorCode$json = const { const {'1': 'AppIdInvalid', '2': 4}, const {'1': 'DatabaseConnectionFail', '2': 5}, const {'1': 'DatabaseInternalError', '2': 6}, + const {'1': 'UserInternalError', '2': 10}, ], }; /// Descriptor for `WorkspaceErrorCode`. Decode as a `google.protobuf.EnumDescriptorProto`. -final $typed_data.Uint8List workspaceErrorCodeDescriptor = $convert.base64Decode('ChJXb3Jrc3BhY2VFcnJvckNvZGUSCwoHVW5rbm93bhAAEhgKFFdvcmtzcGFjZU5hbWVJbnZhbGlkEAESFgoSV29ya3NwYWNlSWRJbnZhbGlkEAISGAoUQXBwQ29sb3JTdHlsZUludmFsaWQQAxIQCgxBcHBJZEludmFsaWQQBBIaChZEYXRhYmFzZUNvbm5lY3Rpb25GYWlsEAUSGQoVRGF0YWJhc2VJbnRlcm5hbEVycm9yEAY='); +final $typed_data.Uint8List workspaceErrorCodeDescriptor = $convert.base64Decode('ChJXb3Jrc3BhY2VFcnJvckNvZGUSCwoHVW5rbm93bhAAEhgKFFdvcmtzcGFjZU5hbWVJbnZhbGlkEAESFgoSV29ya3NwYWNlSWRJbnZhbGlkEAISGAoUQXBwQ29sb3JTdHlsZUludmFsaWQQAxIQCgxBcHBJZEludmFsaWQQBBIaChZEYXRhYmFzZUNvbm5lY3Rpb25GYWlsEAUSGQoVRGF0YWJhc2VJbnRlcm5hbEVycm9yEAYSFQoRVXNlckludGVybmFsRXJyb3IQCg=='); @$core.Deprecated('Use workspaceErrorDescriptor instead') const WorkspaceError$json = const { '1': 'WorkspaceError', diff --git a/rust-lib/dart-ffi/src/lib.rs b/rust-lib/dart-ffi/src/lib.rs index f492acf5cf..9a04592458 100644 --- a/rust-lib/dart-ffi/src/lib.rs +++ b/rust-lib/dart-ffi/src/lib.rs @@ -24,10 +24,9 @@ lazy_static! { pub extern "C" fn init_sdk(path: *mut c_char) -> i64 { let c_str: &CStr = unsafe { CStr::from_ptr(path) }; let path: &str = c_str.to_str().unwrap(); - FlowySDK::init_log(path); - log::info!("🔥 FlowySDK start running"); - FlowySDK::init(path); + FlowySDK::new(path).construct(); + return 1; } diff --git a/rust-lib/flowy-database/migrations/2021-07-14-022241_flowy-user/down.sql b/rust-lib/flowy-database/migrations/2021-07-14-022241_flowy-user/down.sql new file mode 100644 index 0000000000..f1119aa25a --- /dev/null +++ b/rust-lib/flowy-database/migrations/2021-07-14-022241_flowy-user/down.sql @@ -0,0 +1,2 @@ +-- This file should undo anything in `up.sql` +DROP TABLE user_table; \ No newline at end of file diff --git a/rust-lib/flowy-database/migrations/2021-07-14-022241_flowy-user/up.sql b/rust-lib/flowy-database/migrations/2021-07-14-022241_flowy-user/up.sql new file mode 100644 index 0000000000..81d091085d --- /dev/null +++ b/rust-lib/flowy-database/migrations/2021-07-14-022241_flowy-user/up.sql @@ -0,0 +1,2 @@ +-- Your SQL goes here +ALTER TABLE user_table ADD COLUMN workspace TEXT NOT NULL DEFAULT ''; \ No newline at end of file diff --git a/rust-lib/flowy-database/src/lib.rs b/rust-lib/flowy-database/src/lib.rs index c35fc10563..c107aa23ad 100644 --- a/rust-lib/flowy-database/src/lib.rs +++ b/rust-lib/flowy-database/src/lib.rs @@ -1,5 +1,8 @@ pub mod schema; +#[macro_use] +pub mod macros; + #[macro_use] extern crate diesel; pub use diesel::*; @@ -17,6 +20,11 @@ use diesel_migrations::*; use flowy_sqlite::{Error, PoolConfig}; use std::{fmt::Debug, io, path::Path}; +pub mod prelude { + pub use super::UserDatabaseConnection; + pub use diesel::{query_dsl::*, ExpressionMethods, RunQueryDsl}; +} + embed_migrations!("../flowy-database/migrations/"); pub const DB_NAME: &str = "flowy-database.db"; diff --git a/rust-lib/flowy-database/src/macros.rs b/rust-lib/flowy-database/src/macros.rs new file mode 100644 index 0000000000..08ca0e85b8 --- /dev/null +++ b/rust-lib/flowy-database/src/macros.rs @@ -0,0 +1,15 @@ +#[macro_export] +macro_rules! diesel_update_table { + ( + $table_name:ident, + $changeset:ident, + $connection:ident + ) => { + let filter = + $table_name::dsl::$table_name.filter($table_name::dsl::id.eq($changeset.id.clone())); + let affected_row = diesel::update(filter) + .set($changeset) + .execute(&*$connection)?; + debug_assert_eq!(affected_row, 1); + }; +} diff --git a/rust-lib/flowy-database/src/schema.rs b/rust-lib/flowy-database/src/schema.rs index aa59c7a6ad..a7034dbe1c 100644 --- a/rust-lib/flowy-database/src/schema.rs +++ b/rust-lib/flowy-database/src/schema.rs @@ -18,6 +18,7 @@ table! { name -> Text, password -> Text, email -> Text, + workspace -> Text, } } diff --git a/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs b/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs index b79e27c164..c0efa13115 100644 --- a/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs +++ b/rust-lib/flowy-derive/src/derive_cache/derive_cache.rs @@ -18,6 +18,7 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { "KeyValue" | "CreateAppRequest" | "ColorStyle" + | "AppDetail" | "UpdateAppRequest" | "UpdateWorkspaceRequest" | "CreateWorkspaceRequest" @@ -26,6 +27,7 @@ pub fn category_from_str(type_str: &str) -> TypeCategory { | "FFIRequest" | "FFIResponse" | "UserDetail" + | "UpdateUserRequest" | "SignUpRequest" | "SignUpParams" | "SignUpResponse" diff --git a/rust-lib/flowy-sdk/src/flowy_server.rs b/rust-lib/flowy-sdk/src/flowy_server.rs new file mode 100644 index 0000000000..1ca319b6b9 --- /dev/null +++ b/rust-lib/flowy-sdk/src/flowy_server.rs @@ -0,0 +1,46 @@ +use flowy_infra::uuid; +use flowy_user::{ + entities::{SignInParams, SignUpParams, UserDetail}, + errors::{ErrorBuilder, UserError, UserErrorCode}, + prelude::UserServer, + sql_tables::User, +}; + +pub type ArcFlowyServer = std::sync::Arc; + +pub trait FlowyServer: UserServer {} + +pub struct MockFlowyServer {} + +impl FlowyServer for MockFlowyServer {} + +impl UserServer for MockFlowyServer { + fn sign_up(&self, params: SignUpParams) -> Result { + // let user_id = "9527".to_owned(); + let user_id = uuid(); + Ok(User::new( + user_id, + params.name, + params.email, + params.password, + )) + } + + fn sign_in(&self, params: SignInParams) -> Result { + let user_id = uuid(); + Ok(User::new( + user_id, + "".to_owned(), + params.email, + params.password, + )) + } + + fn get_user_info(&self, _user_id: &str) -> Result { + Err(ErrorBuilder::new(UserErrorCode::Unknown).build()) + } + + fn sign_out(&self, _user_id: &str) -> Result<(), UserError> { + Err(ErrorBuilder::new(UserErrorCode::Unknown).build()) + } +} diff --git a/rust-lib/flowy-sdk/src/lib.rs b/rust-lib/flowy-sdk/src/lib.rs index 494d220d8b..c1f2366bae 100644 --- a/rust-lib/flowy-sdk/src/lib.rs +++ b/rust-lib/flowy-sdk/src/lib.rs @@ -1,27 +1,52 @@ +mod flowy_server; pub mod module; -pub use module::*; +use crate::{ + flowy_server::{ArcFlowyServer, MockFlowyServer}, + user_server::MockUserServer, +}; use flowy_dispatch::prelude::*; use module::build_modules; -use std::sync::atomic::{AtomicBool, Ordering}; +pub use module::*; +use std::sync::{ + atomic::{AtomicBool, Ordering}, + Arc, +}; static INIT_LOG: AtomicBool = AtomicBool::new(false); -pub struct FlowySDK {} +pub struct FlowySDK { + root: String, + server: ArcFlowyServer, +} impl FlowySDK { - pub fn init_log(directory: &str) { + pub fn new(root: &str) -> Self { + let server = Arc::new(MockFlowyServer {}); + Self { + root: root.to_owned(), + server, + } + } + + pub fn construct(self) { + FlowySDK::init_log(&self.root); + + tracing::info!("🔥 Root path: {}", self.root); + flowy_infra::kv::KVStore::init(path); + FlowySDK::init_modules(&self.root, self.server); + } + + fn init_log(directory: &str) { if !INIT_LOG.load(Ordering::SeqCst) { INIT_LOG.store(true, Ordering::SeqCst); flowy_log::init_log("flowy", directory, "Debug").unwrap(); } } - pub fn init(path: &str) { - tracing::info!("🔥 Root path: {}", path); - flowy_infra::kv::KVStore::init(path); + fn init_modules(root: &str, server: ArcFlowyServer) { let config = ModuleConfig { - root: path.to_string(), + root: root.to_owned(), }; - EventDispatch::construct(|| build_modules(config)); + EventDispatch::construct(|| build_modules(config, server)); } } diff --git a/rust-lib/flowy-sdk/src/module.rs b/rust-lib/flowy-sdk/src/module.rs index 2c45741c6f..60551a2bbd 100644 --- a/rust-lib/flowy-sdk/src/module.rs +++ b/rust-lib/flowy-sdk/src/module.rs @@ -1,6 +1,9 @@ -use flowy_database::{DBConnection, UserDatabaseConnection}; use flowy_dispatch::prelude::Module; use flowy_user::prelude::*; + +use crate::{flowy_server::ArcFlowyServer, user_server::MockUserServer}; +use flowy_database::DBConnection; +use flowy_user::errors::UserError; use flowy_workspace::prelude::*; use std::sync::Arc; @@ -8,12 +11,43 @@ pub struct ModuleConfig { pub root: String, } -pub fn build_modules(config: ModuleConfig) -> Vec { - let user_session = Arc::new(UserSessionBuilder::new().root_dir(&config.root).build()); - let controller = Arc::new(WorkspaceController::new(user_session.clone())); +pub fn build_modules(config: ModuleConfig, server: ArcFlowyServer) -> Vec { + let user_session = Arc::new( + UserSessionBuilder::new() + .root_dir(&config.root) + .build(config.server), + ); + + let workspace_user_impl = Arc::new(WorkspaceUserImpl { + user_session: user_session.clone(), + }); vec![ flowy_user::module::create(user_session), - flowy_workspace::module::create(controller), + flowy_workspace::module::create(workspace_user_impl), ] } + +pub struct WorkspaceUserImpl { + user_session: Arc, +} + +impl WorkspaceUser for WorkspaceUserImpl { + fn set_current_workspace(&self, id: &str) { unimplemented!() } + + fn get_current_workspace(&self) -> Result { + self.user_session.get_current_workspace().map_err(|e| { + ErrorBuilder::new(WorkspaceErrorCode::UserInternalError) + .error(e) + .build() + }) + } + + fn db_connection(&self) -> Result { + self.user_session.get_db_connection().map_err(|e| { + ErrorBuilder::new(WorkspaceErrorCode::DatabaseConnectionFail) + .error(e) + .build() + }) + } +} diff --git a/rust-lib/flowy-test/src/lib.rs b/rust-lib/flowy-test/src/lib.rs index 741597e01a..f8f9de1a06 100644 --- a/rust-lib/flowy-test/src/lib.rs +++ b/rust-lib/flowy-test/src/lib.rs @@ -22,8 +22,7 @@ pub fn init_sdk() { let root_dir = root_dir(); INIT.call_once(|| { - FlowySDK::init_log(&root_dir); - FlowySDK::init(&root_dir); + FlowySDK::new(&root_dir).construct(); }); } @@ -43,16 +42,20 @@ fn root_dir() -> String { root_dir } -pub struct EventTester { +pub trait TesterConfig { + fn auto_sign_in() -> bool { false } +} + +pub struct EventTester { inner_request: Option, assert_status_code: Option, response: Option, - phantom: PhantomData, + err_phantom: PhantomData, } -impl EventTester +impl EventTester where - ErrType: FromBytes + Debug, + Error: FromBytes + Debug, { pub fn new(event: E) -> Self where @@ -64,11 +67,12 @@ where thread::current(), thread_id::get() ); + Self { inner_request: Some(ModuleRequest::new(event)), assert_status_code: None, response: None, - phantom: PhantomData, + err_phantom: PhantomData, } } @@ -117,7 +121,7 @@ where { let response = self.response.unwrap(); if response.status_code == StatusCode::Err { - let error = >::try_from(response.payload) + let error = >::try_from(response.payload) .unwrap() .into_inner(); dbg!(&error); @@ -127,10 +131,10 @@ where } } - pub fn error(self) -> ErrType { + pub fn error(self) -> Error { let response = self.response.unwrap(); assert_eq!(response.status_code, StatusCode::Err); - >::try_from(response.payload) + >::try_from(response.payload) .unwrap() .into_inner() } diff --git a/rust-lib/flowy-user/src/entities/mod.rs b/rust-lib/flowy-user/src/entities/mod.rs index 4fa6f0ca1f..7792d9de21 100644 --- a/rust-lib/flowy-user/src/entities/mod.rs +++ b/rust-lib/flowy-user/src/entities/mod.rs @@ -1,15 +1,9 @@ -mod sign_in; -mod sign_up; -mod user_detail; -mod user_email; -mod user_id; -mod user_name; -mod user_password; - pub use sign_in::*; pub use sign_up::*; pub use user_detail::*; -pub use user_email::*; -pub use user_id::*; -pub use user_name::*; -pub use user_password::*; +pub use user_update::*; +mod parser; +mod sign_in; +mod sign_up; +mod user_detail; +mod user_update; diff --git a/rust-lib/flowy-user/src/entities/parser/mod.rs b/rust-lib/flowy-user/src/entities/parser/mod.rs new file mode 100644 index 0000000000..71259509f2 --- /dev/null +++ b/rust-lib/flowy-user/src/entities/parser/mod.rs @@ -0,0 +1,12 @@ +// https://lexi-lambda.github.io/blog/2019/11/05/parse-don-t-validate/ +mod user_email; +mod user_id; +mod user_name; +mod user_password; +mod user_workspace; + +pub use user_email::*; +pub use user_id::*; +pub use user_name::*; +pub use user_password::*; +pub use user_workspace::*; diff --git a/rust-lib/flowy-user/src/entities/user_email.rs b/rust-lib/flowy-user/src/entities/parser/user_email.rs similarity index 100% rename from rust-lib/flowy-user/src/entities/user_email.rs rename to rust-lib/flowy-user/src/entities/parser/user_email.rs diff --git a/rust-lib/flowy-user/src/entities/user_id.rs b/rust-lib/flowy-user/src/entities/parser/user_id.rs similarity index 100% rename from rust-lib/flowy-user/src/entities/user_id.rs rename to rust-lib/flowy-user/src/entities/parser/user_id.rs diff --git a/rust-lib/flowy-user/src/entities/user_name.rs b/rust-lib/flowy-user/src/entities/parser/user_name.rs similarity index 100% rename from rust-lib/flowy-user/src/entities/user_name.rs rename to rust-lib/flowy-user/src/entities/parser/user_name.rs diff --git a/rust-lib/flowy-user/src/entities/user_password.rs b/rust-lib/flowy-user/src/entities/parser/user_password.rs similarity index 100% rename from rust-lib/flowy-user/src/entities/user_password.rs rename to rust-lib/flowy-user/src/entities/parser/user_password.rs diff --git a/rust-lib/flowy-user/src/entities/parser/user_workspace.rs b/rust-lib/flowy-user/src/entities/parser/user_workspace.rs new file mode 100644 index 0000000000..312a4e6b0c --- /dev/null +++ b/rust-lib/flowy-user/src/entities/parser/user_workspace.rs @@ -0,0 +1,16 @@ +#[derive(Debug)] +pub struct UserWorkspace(pub String); + +impl UserWorkspace { + pub fn parse(s: String) -> Result { + let is_empty_or_whitespace = s.trim().is_empty(); + if is_empty_or_whitespace { + return Err(format!("workspace id is empty or whitespace")); + } + Ok(Self(s)) + } +} + +impl AsRef for UserWorkspace { + fn as_ref(&self) -> &str { &self.0 } +} diff --git a/rust-lib/flowy-user/src/entities/sign_in.rs b/rust-lib/flowy-user/src/entities/sign_in.rs index c77bb530af..252b2c2636 100644 --- a/rust-lib/flowy-user/src/entities/sign_in.rs +++ b/rust-lib/flowy-user/src/entities/sign_in.rs @@ -1,7 +1,4 @@ -use crate::{ - entities::{UserEmail, UserPassword}, - errors::*, -}; +use crate::{entities::parser::*, errors::*}; use flowy_derive::ProtoBuf; use std::convert::TryInto; diff --git a/rust-lib/flowy-user/src/entities/sign_up.rs b/rust-lib/flowy-user/src/entities/sign_up.rs index da1688c558..57c4878b87 100644 --- a/rust-lib/flowy-user/src/entities/sign_up.rs +++ b/rust-lib/flowy-user/src/entities/sign_up.rs @@ -1,5 +1,5 @@ use crate::{ - entities::{UserEmail, UserName, UserPassword}, + entities::parser::*, errors::{ErrorBuilder, UserError, UserErrorCode}, }; use flowy_derive::ProtoBuf; diff --git a/rust-lib/flowy-user/src/entities/user_detail.rs b/rust-lib/flowy-user/src/entities/user_detail.rs index bf035b0aa6..e59a421a7a 100644 --- a/rust-lib/flowy-user/src/entities/user_detail.rs +++ b/rust-lib/flowy-user/src/entities/user_detail.rs @@ -14,22 +14,30 @@ impl std::default::Default for UserStatus { #[derive(ProtoBuf, Default, Debug)] pub struct UserDetail { #[pb(index = 1)] - pub email: String, + pub id: String, #[pb(index = 2)] - pub name: String, + pub email: String, #[pb(index = 3)] + pub name: String, + + #[pb(index = 4)] pub status: UserStatus, + + #[pb(index = 5)] + pub workspace: String, } use crate::sql_tables::User; impl std::convert::From for UserDetail { fn from(user: User) -> Self { UserDetail { + id: user.id, email: user.email, name: user.name, status: UserStatus::Login, + workspace: user.workspace, } } } diff --git a/rust-lib/flowy-user/src/entities/user_update.rs b/rust-lib/flowy-user/src/entities/user_update.rs new file mode 100644 index 0000000000..5d8a2da342 --- /dev/null +++ b/rust-lib/flowy-user/src/entities/user_update.rs @@ -0,0 +1,106 @@ +use crate::{ + entities::parser::*, + errors::{ErrorBuilder, UserError, UserErrorCode}, +}; +use flowy_derive::ProtoBuf; +use std::convert::TryInto; + +#[derive(ProtoBuf, Default)] +pub struct UpdateUserRequest { + #[pb(index = 1)] + pub id: String, + + #[pb(index = 2, one_of)] + pub name: Option, + + #[pb(index = 3, one_of)] + pub email: Option, + + #[pb(index = 4, one_of)] + pub workspace: Option, + + #[pb(index = 5, one_of)] + pub password: Option, +} + +pub struct UpdateUserParams { + pub id: String, + pub name: Option, + pub email: Option, + pub workspace: Option, + pub password: Option, +} + +impl TryInto for UpdateUserRequest { + type Error = UserError; + + fn try_into(self) -> Result { + let id = UserId::parse(self.id) + .map_err(|e| { + ErrorBuilder::new(UserErrorCode::UserIdInvalid) + .msg(e) + .build() + })? + .0; + + let name = match self.name { + None => None, + Some(name) => Some( + UserName::parse(name) + .map_err(|e| { + ErrorBuilder::new(UserErrorCode::UserNameInvalid) + .msg(e) + .build() + })? + .0, + ), + }; + + let email = match self.email { + None => None, + Some(email) => Some( + UserEmail::parse(email) + .map_err(|e| { + ErrorBuilder::new(UserErrorCode::EmailInvalid) + .msg(e) + .build() + })? + .0, + ), + }; + + let workspace = match self.workspace { + None => None, + Some(workspace) => Some( + UserWorkspace::parse(workspace) + .map_err(|e| { + ErrorBuilder::new(UserErrorCode::UserWorkspaceInvalid) + .msg(e) + .build() + })? + .0, + ), + }; + + let password = match self.password { + None => None, + Some(password) => Some( + UserPassword::parse(password) + .map_err(|e| { + ErrorBuilder::new(UserErrorCode::PasswordInvalid) + .msg(e) + .build() + })? + .0, + ), + }; + + Ok(UpdateUserParams { + id, + name, + email, + workspace, + password, + }) + } +} diff --git a/rust-lib/flowy-user/src/errors.rs b/rust-lib/flowy-user/src/errors.rs index 0e4110a414..0fd42758df 100644 --- a/rust-lib/flowy-user/src/errors.rs +++ b/rust-lib/flowy-user/src/errors.rs @@ -49,6 +49,10 @@ pub enum UserErrorCode { PasswordInvalid = 21, #[display(fmt = "User is invalid")] UserNameInvalid = 22, + #[display(fmt = "User workspace is invalid")] + UserWorkspaceInvalid = 23, + #[display(fmt = "User id is invalid")] + UserIdInvalid = 24, } impl std::default::Default for UserErrorCode { diff --git a/rust-lib/flowy-user/src/event.rs b/rust-lib/flowy-user/src/event.rs index d21eb7acbf..d8d7843c5f 100644 --- a/rust-lib/flowy-user/src/event.rs +++ b/rust-lib/flowy-user/src/event.rs @@ -6,14 +6,17 @@ use flowy_derive::{Flowy_Event, ProtoBuf_Enum}; pub enum UserEvent { #[display(fmt = "GetStatus")] #[event(output = "UserDetail")] - GetStatus = 0, + GetStatus = 0, #[display(fmt = "SignIn")] #[event(input = "SignInRequest", output = "UserDetail")] - SignIn = 1, + SignIn = 1, #[display(fmt = "SignUp")] #[event(input = "SignUpRequest", output = "UserDetail")] - SignUp = 2, + SignUp = 2, #[display(fmt = "SignOut")] #[event(passthrough)] - SignOut = 3, + SignOut = 3, + #[display(fmt = "UpdateUser")] + #[event(input = "UpdateUserRequest", output = "UserDetail")] + UpdateUser = 4, } diff --git a/rust-lib/flowy-user/src/handlers/auth_handler.rs b/rust-lib/flowy-user/src/handlers/auth_handler.rs index 9a25fd8cd0..601d8b6f09 100644 --- a/rust-lib/flowy-user/src/handlers/auth_handler.rs +++ b/rust-lib/flowy-user/src/handlers/auth_handler.rs @@ -10,7 +10,7 @@ use std::{convert::TryInto, sync::Arc}; email = %data.email, ) )] -pub async fn user_sign_in( +pub async fn user_sign_in_handler( data: Data, session: ModuleData>, ) -> ResponseResult { @@ -28,7 +28,7 @@ pub async fn user_sign_in( name = %data.name, ) )] -pub async fn user_sign_up( +pub async fn user_sign_up_handler( data: Data, session: ModuleData>, ) -> ResponseResult { @@ -37,15 +37,3 @@ pub async fn user_sign_up( let user_detail = UserDetail::from(user); response_ok(user_detail) } - -pub async fn user_get_status( - session: ModuleData>, -) -> ResponseResult { - let user_detail = session.current_user_detail().await?; - response_ok(user_detail) -} - -pub async fn user_sign_out(session: ModuleData>) -> Result<(), UserError> { - let _ = session.sign_out().await?; - Ok(()) -} diff --git a/rust-lib/flowy-user/src/handlers/mod.rs b/rust-lib/flowy-user/src/handlers/mod.rs index e66bf9eb02..b220539145 100644 --- a/rust-lib/flowy-user/src/handlers/mod.rs +++ b/rust-lib/flowy-user/src/handlers/mod.rs @@ -1,3 +1,5 @@ -pub mod auth_handler; +mod auth_handler; +mod user_handler; pub use auth_handler::*; +pub use user_handler::*; diff --git a/rust-lib/flowy-user/src/handlers/user_handler.rs b/rust-lib/flowy-user/src/handlers/user_handler.rs new file mode 100644 index 0000000000..34b627e2a0 --- /dev/null +++ b/rust-lib/flowy-user/src/handlers/user_handler.rs @@ -0,0 +1,24 @@ +use crate::{entities::*, errors::UserError, services::user_session::UserSession}; +use flowy_dispatch::prelude::*; +use std::{convert::TryInto, sync::Arc}; + +pub async fn user_get_status_handler( + session: ModuleData>, +) -> ResponseResult { + let user_detail = session.current_user_detail()?; + response_ok(user_detail) +} + +pub async fn sign_out_handler(session: ModuleData>) -> Result<(), UserError> { + let _ = session.sign_out().await?; + Ok(()) +} + +pub async fn update_user_handler( + data: Data, + session: ModuleData>, +) -> ResponseResult { + let params: UpdateUserParams = data.into_inner().try_into()?; + let user_detail = session.update_user(params).await?; + response_ok(user_detail) +} diff --git a/rust-lib/flowy-user/src/lib.rs b/rust-lib/flowy-user/src/lib.rs index 76dccfe4bc..55099e214f 100644 --- a/rust-lib/flowy-user/src/lib.rs +++ b/rust-lib/flowy-user/src/lib.rs @@ -11,5 +11,5 @@ pub mod sql_tables; extern crate flowy_database; pub mod prelude { - pub use crate::{entities::*, handlers::auth_handler::*, services::user_session::*}; + pub use crate::{entities::*, handlers::*, services::user_session::*}; } diff --git a/rust-lib/flowy-user/src/module.rs b/rust-lib/flowy-user/src/module.rs index 3b54441067..699a25dd22 100644 --- a/rust-lib/flowy-user/src/module.rs +++ b/rust-lib/flowy-user/src/module.rs @@ -7,8 +7,9 @@ pub fn create(user_session: Arc) -> Module { Module::new() .name("Flowy-User") .data(user_session) - .event(UserEvent::SignIn, user_sign_in) - .event(UserEvent::SignUp, user_sign_up) - .event(UserEvent::GetStatus, user_get_status) - .event(UserEvent::SignOut, user_sign_out) + .event(UserEvent::SignIn, user_sign_in_handler) + .event(UserEvent::SignUp, user_sign_up_handler) + .event(UserEvent::GetStatus, user_get_status_handler) + .event(UserEvent::SignOut, sign_out_handler) + .event(UserEvent::UpdateUser, update_user_handler) } diff --git a/rust-lib/flowy-user/src/protobuf/model/errors.rs b/rust-lib/flowy-user/src/protobuf/model/errors.rs index 3e980606a0..56637c911d 100644 --- a/rust-lib/flowy-user/src/protobuf/model/errors.rs +++ b/rust-lib/flowy-user/src/protobuf/model/errors.rs @@ -227,6 +227,8 @@ pub enum UserErrorCode { EmailInvalid = 20, PasswordInvalid = 21, UserNameInvalid = 22, + UserWorkspaceInvalid = 23, + UserIdInvalid = 24, } impl ::protobuf::ProtobufEnum for UserErrorCode { @@ -248,6 +250,8 @@ impl ::protobuf::ProtobufEnum for UserErrorCode { 20 => ::std::option::Option::Some(UserErrorCode::EmailInvalid), 21 => ::std::option::Option::Some(UserErrorCode::PasswordInvalid), 22 => ::std::option::Option::Some(UserErrorCode::UserNameInvalid), + 23 => ::std::option::Option::Some(UserErrorCode::UserWorkspaceInvalid), + 24 => ::std::option::Option::Some(UserErrorCode::UserIdInvalid), _ => ::std::option::Option::None } } @@ -266,6 +270,8 @@ impl ::protobuf::ProtobufEnum for UserErrorCode { UserErrorCode::EmailInvalid, UserErrorCode::PasswordInvalid, UserErrorCode::UserNameInvalid, + UserErrorCode::UserWorkspaceInvalid, + UserErrorCode::UserIdInvalid, ]; values } @@ -296,46 +302,51 @@ impl ::protobuf::reflect::ProtobufValue for UserErrorCode { static file_descriptor_proto_data: &'static [u8] = b"\ \n\x0cerrors.proto\"A\n\tUserError\x12\"\n\x04code\x18\x01\x20\x01(\x0e2\ \x0e.UserErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\tR\x03msg*\ - \xa1\x02\n\rUserErrorCode\x12\x0b\n\x07Unknown\x10\0\x12\x16\n\x12Databa\ + \xce\x02\n\rUserErrorCode\x12\x0b\n\x07Unknown\x10\0\x12\x16\n\x12Databa\ seInitFailed\x10\x01\x12\x17\n\x13DatabaseWriteLocked\x10\x02\x12\x16\n\ \x12DatabaseReadLocked\x10\x03\x12\x1b\n\x17DatabaseUserDidNotMatch\x10\ \x04\x12\x19\n\x15DatabaseInternalError\x10\x05\x12\x13\n\x0fUserNotLogi\ nYet\x10\n\x12\x17\n\x13ReadCurrentIdFailed\x10\x0b\x12\x18\n\x14WriteCu\ rrentIdFailed\x10\x0c\x12\x10\n\x0cEmailInvalid\x10\x14\x12\x13\n\x0fPas\ - swordInvalid\x10\x15\x12\x13\n\x0fUserNameInvalid\x10\x16J\x9c\x05\n\x06\ - \x12\x04\0\0\x13\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\ - \x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x11\n\x0b\n\x04\ - \x04\0\x02\0\x12\x03\x03\x04\x1b\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\x03\ - \x04\x11\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x12\x16\n\x0c\n\x05\x04\ - \0\x02\0\x03\x12\x03\x03\x19\x1a\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\ - \x04\x13\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\ - \0\x02\x01\x01\x12\x03\x04\x0b\x0e\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\ - \x04\x11\x12\n\n\n\x02\x05\0\x12\x04\x06\0\x13\x01\n\n\n\x03\x05\0\x01\ - \x12\x03\x06\x05\x12\n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\x04\x10\n\x0c\n\ - \x05\x05\0\x02\0\x01\x12\x03\x07\x04\x0b\n\x0c\n\x05\x05\0\x02\0\x02\x12\ - \x03\x07\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x08\x04\x1b\n\x0c\n\ - \x05\x05\0\x02\x01\x01\x12\x03\x08\x04\x16\n\x0c\n\x05\x05\0\x02\x01\x02\ - \x12\x03\x08\x19\x1a\n\x0b\n\x04\x05\0\x02\x02\x12\x03\t\x04\x1c\n\x0c\n\ - \x05\x05\0\x02\x02\x01\x12\x03\t\x04\x17\n\x0c\n\x05\x05\0\x02\x02\x02\ - \x12\x03\t\x1a\x1b\n\x0b\n\x04\x05\0\x02\x03\x12\x03\n\x04\x1b\n\x0c\n\ - \x05\x05\0\x02\x03\x01\x12\x03\n\x04\x16\n\x0c\n\x05\x05\0\x02\x03\x02\ - \x12\x03\n\x19\x1a\n\x0b\n\x04\x05\0\x02\x04\x12\x03\x0b\x04\x20\n\x0c\n\ - \x05\x05\0\x02\x04\x01\x12\x03\x0b\x04\x1b\n\x0c\n\x05\x05\0\x02\x04\x02\ - \x12\x03\x0b\x1e\x1f\n\x0b\n\x04\x05\0\x02\x05\x12\x03\x0c\x04\x1e\n\x0c\ - \n\x05\x05\0\x02\x05\x01\x12\x03\x0c\x04\x19\n\x0c\n\x05\x05\0\x02\x05\ - \x02\x12\x03\x0c\x1c\x1d\n\x0b\n\x04\x05\0\x02\x06\x12\x03\r\x04\x19\n\ - \x0c\n\x05\x05\0\x02\x06\x01\x12\x03\r\x04\x13\n\x0c\n\x05\x05\0\x02\x06\ - \x02\x12\x03\r\x16\x18\n\x0b\n\x04\x05\0\x02\x07\x12\x03\x0e\x04\x1d\n\ - \x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\x04\x17\n\x0c\n\x05\x05\0\x02\ - \x07\x02\x12\x03\x0e\x1a\x1c\n\x0b\n\x04\x05\0\x02\x08\x12\x03\x0f\x04\ - \x1e\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\x0f\x04\x18\n\x0c\n\x05\x05\0\ - \x02\x08\x02\x12\x03\x0f\x1b\x1d\n\x0b\n\x04\x05\0\x02\t\x12\x03\x10\x04\ - \x16\n\x0c\n\x05\x05\0\x02\t\x01\x12\x03\x10\x04\x10\n\x0c\n\x05\x05\0\ - \x02\t\x02\x12\x03\x10\x13\x15\n\x0b\n\x04\x05\0\x02\n\x12\x03\x11\x04\ - \x19\n\x0c\n\x05\x05\0\x02\n\x01\x12\x03\x11\x04\x13\n\x0c\n\x05\x05\0\ - \x02\n\x02\x12\x03\x11\x16\x18\n\x0b\n\x04\x05\0\x02\x0b\x12\x03\x12\x04\ - \x19\n\x0c\n\x05\x05\0\x02\x0b\x01\x12\x03\x12\x04\x13\n\x0c\n\x05\x05\0\ - \x02\x0b\x02\x12\x03\x12\x16\x18b\x06proto3\ + swordInvalid\x10\x15\x12\x13\n\x0fUserNameInvalid\x10\x16\x12\x18\n\x14U\ + serWorkspaceInvalid\x10\x17\x12\x11\n\rUserIdInvalid\x10\x18J\xee\x05\n\ + \x06\x12\x04\0\0\x15\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\ + \x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x11\n\x0b\n\ + \x04\x04\0\x02\0\x12\x03\x03\x04\x1b\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\ + \x03\x04\x11\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x12\x16\n\x0c\n\x05\ + \x04\0\x02\0\x03\x12\x03\x03\x19\x1a\n\x0b\n\x04\x04\0\x02\x01\x12\x03\ + \x04\x04\x13\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\ + \x04\0\x02\x01\x01\x12\x03\x04\x0b\x0e\n\x0c\n\x05\x04\0\x02\x01\x03\x12\ + \x03\x04\x11\x12\n\n\n\x02\x05\0\x12\x04\x06\0\x15\x01\n\n\n\x03\x05\0\ + \x01\x12\x03\x06\x05\x12\n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\x04\x10\n\ + \x0c\n\x05\x05\0\x02\0\x01\x12\x03\x07\x04\x0b\n\x0c\n\x05\x05\0\x02\0\ + \x02\x12\x03\x07\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x08\x04\x1b\n\ + \x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x08\x04\x16\n\x0c\n\x05\x05\0\x02\ + \x01\x02\x12\x03\x08\x19\x1a\n\x0b\n\x04\x05\0\x02\x02\x12\x03\t\x04\x1c\ + \n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\t\x04\x17\n\x0c\n\x05\x05\0\x02\ + \x02\x02\x12\x03\t\x1a\x1b\n\x0b\n\x04\x05\0\x02\x03\x12\x03\n\x04\x1b\n\ + \x0c\n\x05\x05\0\x02\x03\x01\x12\x03\n\x04\x16\n\x0c\n\x05\x05\0\x02\x03\ + \x02\x12\x03\n\x19\x1a\n\x0b\n\x04\x05\0\x02\x04\x12\x03\x0b\x04\x20\n\ + \x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x0b\x04\x1b\n\x0c\n\x05\x05\0\x02\ + \x04\x02\x12\x03\x0b\x1e\x1f\n\x0b\n\x04\x05\0\x02\x05\x12\x03\x0c\x04\ + \x1e\n\x0c\n\x05\x05\0\x02\x05\x01\x12\x03\x0c\x04\x19\n\x0c\n\x05\x05\0\ + \x02\x05\x02\x12\x03\x0c\x1c\x1d\n\x0b\n\x04\x05\0\x02\x06\x12\x03\r\x04\ + \x19\n\x0c\n\x05\x05\0\x02\x06\x01\x12\x03\r\x04\x13\n\x0c\n\x05\x05\0\ + \x02\x06\x02\x12\x03\r\x16\x18\n\x0b\n\x04\x05\0\x02\x07\x12\x03\x0e\x04\ + \x1d\n\x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\x04\x17\n\x0c\n\x05\x05\0\ + \x02\x07\x02\x12\x03\x0e\x1a\x1c\n\x0b\n\x04\x05\0\x02\x08\x12\x03\x0f\ + \x04\x1e\n\x0c\n\x05\x05\0\x02\x08\x01\x12\x03\x0f\x04\x18\n\x0c\n\x05\ + \x05\0\x02\x08\x02\x12\x03\x0f\x1b\x1d\n\x0b\n\x04\x05\0\x02\t\x12\x03\ + \x10\x04\x16\n\x0c\n\x05\x05\0\x02\t\x01\x12\x03\x10\x04\x10\n\x0c\n\x05\ + \x05\0\x02\t\x02\x12\x03\x10\x13\x15\n\x0b\n\x04\x05\0\x02\n\x12\x03\x11\ + \x04\x19\n\x0c\n\x05\x05\0\x02\n\x01\x12\x03\x11\x04\x13\n\x0c\n\x05\x05\ + \0\x02\n\x02\x12\x03\x11\x16\x18\n\x0b\n\x04\x05\0\x02\x0b\x12\x03\x12\ + \x04\x19\n\x0c\n\x05\x05\0\x02\x0b\x01\x12\x03\x12\x04\x13\n\x0c\n\x05\ + \x05\0\x02\x0b\x02\x12\x03\x12\x16\x18\n\x0b\n\x04\x05\0\x02\x0c\x12\x03\ + \x13\x04\x1e\n\x0c\n\x05\x05\0\x02\x0c\x01\x12\x03\x13\x04\x18\n\x0c\n\ + \x05\x05\0\x02\x0c\x02\x12\x03\x13\x1b\x1d\n\x0b\n\x04\x05\0\x02\r\x12\ + \x03\x14\x04\x17\n\x0c\n\x05\x05\0\x02\r\x01\x12\x03\x14\x04\x11\n\x0c\n\ + \x05\x05\0\x02\r\x02\x12\x03\x14\x14\x16b\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-user/src/protobuf/model/event.rs b/rust-lib/flowy-user/src/protobuf/model/event.rs index d4478eb060..f22923026e 100644 --- a/rust-lib/flowy-user/src/protobuf/model/event.rs +++ b/rust-lib/flowy-user/src/protobuf/model/event.rs @@ -29,6 +29,7 @@ pub enum UserEvent { SignIn = 1, SignUp = 2, SignOut = 3, + UpdateUser = 4, } impl ::protobuf::ProtobufEnum for UserEvent { @@ -42,6 +43,7 @@ impl ::protobuf::ProtobufEnum for UserEvent { 1 => ::std::option::Option::Some(UserEvent::SignIn), 2 => ::std::option::Option::Some(UserEvent::SignUp), 3 => ::std::option::Option::Some(UserEvent::SignOut), + 4 => ::std::option::Option::Some(UserEvent::UpdateUser), _ => ::std::option::Option::None } } @@ -52,6 +54,7 @@ impl ::protobuf::ProtobufEnum for UserEvent { UserEvent::SignIn, UserEvent::SignUp, UserEvent::SignOut, + UserEvent::UpdateUser, ]; values } @@ -80,19 +83,21 @@ impl ::protobuf::reflect::ProtobufValue for UserEvent { } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x0bevent.proto*?\n\tUserEvent\x12\r\n\tGetStatus\x10\0\x12\n\n\x06Sig\ - nIn\x10\x01\x12\n\n\x06SignUp\x10\x02\x12\x0b\n\x07SignOut\x10\x03J\xce\ - \x01\n\x06\x12\x04\0\0\x07\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\ - \x05\0\x12\x04\x02\0\x07\x01\n\n\n\x03\x05\0\x01\x12\x03\x02\x05\x0e\n\ - \x0b\n\x04\x05\0\x02\0\x12\x03\x03\x04\x12\n\x0c\n\x05\x05\0\x02\0\x01\ - \x12\x03\x03\x04\r\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x03\x10\x11\n\x0b\ - \n\x04\x05\0\x02\x01\x12\x03\x04\x04\x0f\n\x0c\n\x05\x05\0\x02\x01\x01\ - \x12\x03\x04\x04\n\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x04\r\x0e\n\x0b\ - \n\x04\x05\0\x02\x02\x12\x03\x05\x04\x0f\n\x0c\n\x05\x05\0\x02\x02\x01\ - \x12\x03\x05\x04\n\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\x05\r\x0e\n\x0b\ - \n\x04\x05\0\x02\x03\x12\x03\x06\x04\x10\n\x0c\n\x05\x05\0\x02\x03\x01\ - \x12\x03\x06\x04\x0b\n\x0c\n\x05\x05\0\x02\x03\x02\x12\x03\x06\x0e\x0fb\ - \x06proto3\ + \n\x0bevent.proto*O\n\tUserEvent\x12\r\n\tGetStatus\x10\0\x12\n\n\x06Sig\ + nIn\x10\x01\x12\n\n\x06SignUp\x10\x02\x12\x0b\n\x07SignOut\x10\x03\x12\ + \x0e\n\nUpdateUser\x10\x04J\xf7\x01\n\x06\x12\x04\0\0\x08\x01\n\x08\n\ + \x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x05\0\x12\x04\x02\0\x08\x01\n\n\n\x03\ + \x05\0\x01\x12\x03\x02\x05\x0e\n\x0b\n\x04\x05\0\x02\0\x12\x03\x03\x04\ + \x12\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x03\x04\r\n\x0c\n\x05\x05\0\x02\ + \0\x02\x12\x03\x03\x10\x11\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x04\x04\x0f\ + \n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x04\x04\n\n\x0c\n\x05\x05\0\x02\ + \x01\x02\x12\x03\x04\r\x0e\n\x0b\n\x04\x05\0\x02\x02\x12\x03\x05\x04\x0f\ + \n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\x05\x04\n\n\x0c\n\x05\x05\0\x02\ + \x02\x02\x12\x03\x05\r\x0e\n\x0b\n\x04\x05\0\x02\x03\x12\x03\x06\x04\x10\ + \n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\x06\x04\x0b\n\x0c\n\x05\x05\0\x02\ + \x03\x02\x12\x03\x06\x0e\x0f\n\x0b\n\x04\x05\0\x02\x04\x12\x03\x07\x04\ + \x13\n\x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x07\x04\x0e\n\x0c\n\x05\x05\0\ + \x02\x04\x02\x12\x03\x07\x11\x12b\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-user/src/protobuf/model/mod.rs b/rust-lib/flowy-user/src/protobuf/model/mod.rs index d86ca368de..9d238d852e 100644 --- a/rust-lib/flowy-user/src/protobuf/model/mod.rs +++ b/rust-lib/flowy-user/src/protobuf/model/mod.rs @@ -15,5 +15,8 @@ pub use errors::*; mod user_detail; pub use user_detail::*; +mod user_update; +pub use user_update::*; + mod event; pub use event::*; diff --git a/rust-lib/flowy-user/src/protobuf/model/user_detail.rs b/rust-lib/flowy-user/src/protobuf/model/user_detail.rs index 8009945a54..efd4175426 100644 --- a/rust-lib/flowy-user/src/protobuf/model/user_detail.rs +++ b/rust-lib/flowy-user/src/protobuf/model/user_detail.rs @@ -26,9 +26,11 @@ #[derive(PartialEq,Clone,Default)] pub struct UserDetail { // message fields + pub id: ::std::string::String, pub email: ::std::string::String, pub name: ::std::string::String, pub status: UserStatus, + pub workspace: ::std::string::String, // special fields pub unknown_fields: ::protobuf::UnknownFields, pub cached_size: ::protobuf::CachedSize, @@ -45,7 +47,33 @@ impl UserDetail { ::std::default::Default::default() } - // string email = 1; + // string id = 1; + + + pub fn get_id(&self) -> &str { + &self.id + } + pub fn clear_id(&mut self) { + self.id.clear(); + } + + // Param is passed by value, moved + pub fn set_id(&mut self, v: ::std::string::String) { + self.id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_id(&mut self) -> &mut ::std::string::String { + &mut self.id + } + + // Take field + pub fn take_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.id, ::std::string::String::new()) + } + + // string email = 2; pub fn get_email(&self) -> &str { @@ -71,7 +99,7 @@ impl UserDetail { ::std::mem::replace(&mut self.email, ::std::string::String::new()) } - // string name = 2; + // string name = 3; pub fn get_name(&self) -> &str { @@ -97,7 +125,7 @@ impl UserDetail { ::std::mem::replace(&mut self.name, ::std::string::String::new()) } - // .UserStatus status = 3; + // .UserStatus status = 4; pub fn get_status(&self) -> UserStatus { @@ -111,6 +139,32 @@ impl UserDetail { pub fn set_status(&mut self, v: UserStatus) { self.status = v; } + + // string workspace = 5; + + + pub fn get_workspace(&self) -> &str { + &self.workspace + } + pub fn clear_workspace(&mut self) { + self.workspace.clear(); + } + + // Param is passed by value, moved + pub fn set_workspace(&mut self, v: ::std::string::String) { + self.workspace = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_workspace(&mut self) -> &mut ::std::string::String { + &mut self.workspace + } + + // Take field + pub fn take_workspace(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.workspace, ::std::string::String::new()) + } } impl ::protobuf::Message for UserDetail { @@ -123,13 +177,19 @@ impl ::protobuf::Message for UserDetail { let (field_number, wire_type) = is.read_tag_unpack()?; match field_number { 1 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.email)?; + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.id)?; }, 2 => { - ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.name)?; + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.email)?; }, 3 => { - ::protobuf::rt::read_proto3_enum_with_unknown_fields_into(wire_type, is, &mut self.status, 3, &mut self.unknown_fields)? + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.name)?; + }, + 4 => { + ::protobuf::rt::read_proto3_enum_with_unknown_fields_into(wire_type, is, &mut self.status, 4, &mut self.unknown_fields)? + }, + 5 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.workspace)?; }, _ => { ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; @@ -143,14 +203,20 @@ impl ::protobuf::Message for UserDetail { #[allow(unused_variables)] fn compute_size(&self) -> u32 { let mut my_size = 0; + if !self.id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.id); + } if !self.email.is_empty() { - my_size += ::protobuf::rt::string_size(1, &self.email); + my_size += ::protobuf::rt::string_size(2, &self.email); } if !self.name.is_empty() { - my_size += ::protobuf::rt::string_size(2, &self.name); + my_size += ::protobuf::rt::string_size(3, &self.name); } if self.status != UserStatus::Unknown { - my_size += ::protobuf::rt::enum_size(3, self.status); + my_size += ::protobuf::rt::enum_size(4, self.status); + } + if !self.workspace.is_empty() { + my_size += ::protobuf::rt::string_size(5, &self.workspace); } my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); self.cached_size.set(my_size); @@ -158,14 +224,20 @@ impl ::protobuf::Message for UserDetail { } fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.id.is_empty() { + os.write_string(1, &self.id)?; + } if !self.email.is_empty() { - os.write_string(1, &self.email)?; + os.write_string(2, &self.email)?; } if !self.name.is_empty() { - os.write_string(2, &self.name)?; + os.write_string(3, &self.name)?; } if self.status != UserStatus::Unknown { - os.write_enum(3, ::protobuf::ProtobufEnum::value(&self.status))?; + os.write_enum(4, ::protobuf::ProtobufEnum::value(&self.status))?; + } + if !self.workspace.is_empty() { + os.write_string(5, &self.workspace)?; } os.write_unknown_fields(self.get_unknown_fields())?; ::std::result::Result::Ok(()) @@ -205,6 +277,11 @@ impl ::protobuf::Message for UserDetail { static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; descriptor.get(|| { let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "id", + |m: &UserDetail| { &m.id }, + |m: &mut UserDetail| { &mut m.id }, + )); fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( "email", |m: &UserDetail| { &m.email }, @@ -220,6 +297,11 @@ impl ::protobuf::Message for UserDetail { |m: &UserDetail| { &m.status }, |m: &mut UserDetail| { &mut m.status }, )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "workspace", + |m: &UserDetail| { &m.workspace }, + |m: &mut UserDetail| { &mut m.workspace }, + )); ::protobuf::reflect::MessageDescriptor::new_pb_name::( "UserDetail", fields, @@ -236,9 +318,11 @@ impl ::protobuf::Message for UserDetail { impl ::protobuf::Clear for UserDetail { fn clear(&mut self) { + self.id.clear(); self.email.clear(); self.name.clear(); self.status = UserStatus::Unknown; + self.workspace.clear(); self.unknown_fields.clear(); } } @@ -309,28 +393,35 @@ impl ::protobuf::reflect::ProtobufValue for UserStatus { } static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x11user_detail.proto\"[\n\nUserDetail\x12\x14\n\x05email\x18\x01\x20\ - \x01(\tR\x05email\x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12#\n\ - \x06status\x18\x03\x20\x01(\x0e2\x0b.UserStatusR\x06status*1\n\nUserStat\ - us\x12\x0b\n\x07Unknown\x10\0\x12\t\n\x05Login\x10\x01\x12\x0b\n\x07Expi\ - red\x10\x02J\xe2\x02\n\x06\x12\x04\0\0\x0b\x01\n\x08\n\x01\x0c\x12\x03\0\ - \0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x06\x01\n\n\n\x03\x04\0\x01\x12\x03\ - \x02\x08\x12\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x15\n\x0c\n\x05\x04\ - \0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\ - \x0b\x10\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x13\x14\n\x0b\n\x04\x04\ - \0\x02\x01\x12\x03\x04\x04\x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\ - \x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0f\n\x0c\n\x05\x04\ - \0\x02\x01\x03\x12\x03\x04\x12\x13\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\ - \x04\x1a\n\x0c\n\x05\x04\0\x02\x02\x06\x12\x03\x05\x04\x0e\n\x0c\n\x05\ - \x04\0\x02\x02\x01\x12\x03\x05\x0f\x15\n\x0c\n\x05\x04\0\x02\x02\x03\x12\ - \x03\x05\x18\x19\n\n\n\x02\x05\0\x12\x04\x07\0\x0b\x01\n\n\n\x03\x05\0\ - \x01\x12\x03\x07\x05\x0f\n\x0b\n\x04\x05\0\x02\0\x12\x03\x08\x04\x10\n\ - \x0c\n\x05\x05\0\x02\0\x01\x12\x03\x08\x04\x0b\n\x0c\n\x05\x05\0\x02\0\ - \x02\x12\x03\x08\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\x12\x03\t\x04\x0e\n\ - \x0c\n\x05\x05\0\x02\x01\x01\x12\x03\t\x04\t\n\x0c\n\x05\x05\0\x02\x01\ - \x02\x12\x03\t\x0c\r\n\x0b\n\x04\x05\0\x02\x02\x12\x03\n\x04\x10\n\x0c\n\ - \x05\x05\0\x02\x02\x01\x12\x03\n\x04\x0b\n\x0c\n\x05\x05\0\x02\x02\x02\ - \x12\x03\n\x0e\x0fb\x06proto3\ + \n\x11user_detail.proto\"\x89\x01\n\nUserDetail\x12\x0e\n\x02id\x18\x01\ + \x20\x01(\tR\x02id\x12\x14\n\x05email\x18\x02\x20\x01(\tR\x05email\x12\ + \x12\n\x04name\x18\x03\x20\x01(\tR\x04name\x12#\n\x06status\x18\x04\x20\ + \x01(\x0e2\x0b.UserStatusR\x06status\x12\x1c\n\tworkspace\x18\x05\x20\ + \x01(\tR\tworkspace*1\n\nUserStatus\x12\x0b\n\x07Unknown\x10\0\x12\t\n\ + \x05Login\x10\x01\x12\x0b\n\x07Expired\x10\x02J\xd0\x03\n\x06\x12\x04\0\ + \0\r\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\ + \x08\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x12\n\x0b\n\x04\x04\0\x02\0\ + \x12\x03\x03\x04\x12\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\ + \n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\r\n\x0c\n\x05\x04\0\x02\0\x03\x12\ + \x03\x03\x10\x11\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x15\n\x0c\n\ + \x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\ + \x12\x03\x04\x0b\x10\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x13\x14\n\ + \x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x04\x14\n\x0c\n\x05\x04\0\x02\x02\ + \x05\x12\x03\x05\x04\n\n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x05\x0b\x0f\ + \n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x12\x13\n\x0b\n\x04\x04\0\x02\ + \x03\x12\x03\x06\x04\x1a\n\x0c\n\x05\x04\0\x02\x03\x06\x12\x03\x06\x04\ + \x0e\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x06\x0f\x15\n\x0c\n\x05\x04\0\ + \x02\x03\x03\x12\x03\x06\x18\x19\n\x0b\n\x04\x04\0\x02\x04\x12\x03\x07\ + \x04\x19\n\x0c\n\x05\x04\0\x02\x04\x05\x12\x03\x07\x04\n\n\x0c\n\x05\x04\ + \0\x02\x04\x01\x12\x03\x07\x0b\x14\n\x0c\n\x05\x04\0\x02\x04\x03\x12\x03\ + \x07\x17\x18\n\n\n\x02\x05\0\x12\x04\t\0\r\x01\n\n\n\x03\x05\0\x01\x12\ + \x03\t\x05\x0f\n\x0b\n\x04\x05\0\x02\0\x12\x03\n\x04\x10\n\x0c\n\x05\x05\ + \0\x02\0\x01\x12\x03\n\x04\x0b\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\n\x0e\ + \x0f\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x0b\x04\x0e\n\x0c\n\x05\x05\0\x02\ + \x01\x01\x12\x03\x0b\x04\t\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x0b\x0c\ + \r\n\x0b\n\x04\x05\0\x02\x02\x12\x03\x0c\x04\x10\n\x0c\n\x05\x05\0\x02\ + \x02\x01\x12\x03\x0c\x04\x0b\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\x0c\ + \x0e\x0fb\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-user/src/protobuf/model/user_update.rs b/rust-lib/flowy-user/src/protobuf/model/user_update.rs new file mode 100644 index 0000000000..6025cb501c --- /dev/null +++ b/rust-lib/flowy-user/src/protobuf/model/user_update.rs @@ -0,0 +1,549 @@ +// This file is generated by rust-protobuf 2.22.1. Do not edit +// @generated + +// https://github.com/rust-lang/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy::all)] + +#![allow(unused_attributes)] +#![cfg_attr(rustfmt, rustfmt::skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unused_imports)] +#![allow(unused_results)] +//! Generated file from `user_update.proto` + +/// Generated files are compatible only with the same version +/// of protobuf runtime. +// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1; + +#[derive(PartialEq,Clone,Default)] +pub struct UpdateUserRequest { + // message fields + pub id: ::std::string::String, + // message oneof groups + pub one_of_name: ::std::option::Option, + pub one_of_email: ::std::option::Option, + pub one_of_workspace: ::std::option::Option, + pub one_of_password: ::std::option::Option, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a UpdateUserRequest { + fn default() -> &'a UpdateUserRequest { + ::default_instance() + } +} + +#[derive(Clone,PartialEq,Debug)] +pub enum UpdateUserRequest_oneof_one_of_name { + name(::std::string::String), +} + +#[derive(Clone,PartialEq,Debug)] +pub enum UpdateUserRequest_oneof_one_of_email { + email(::std::string::String), +} + +#[derive(Clone,PartialEq,Debug)] +pub enum UpdateUserRequest_oneof_one_of_workspace { + workspace(::std::string::String), +} + +#[derive(Clone,PartialEq,Debug)] +pub enum UpdateUserRequest_oneof_one_of_password { + password(::std::string::String), +} + +impl UpdateUserRequest { + pub fn new() -> UpdateUserRequest { + ::std::default::Default::default() + } + + // string id = 1; + + + pub fn get_id(&self) -> &str { + &self.id + } + pub fn clear_id(&mut self) { + self.id.clear(); + } + + // Param is passed by value, moved + pub fn set_id(&mut self, v: ::std::string::String) { + self.id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_id(&mut self) -> &mut ::std::string::String { + &mut self.id + } + + // Take field + pub fn take_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.id, ::std::string::String::new()) + } + + // string name = 2; + + + pub fn get_name(&self) -> &str { + match self.one_of_name { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_name::name(ref v)) => v, + _ => "", + } + } + pub fn clear_name(&mut self) { + self.one_of_name = ::std::option::Option::None; + } + + pub fn has_name(&self) -> bool { + match self.one_of_name { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_name::name(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_name(&mut self, v: ::std::string::String) { + self.one_of_name = ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_name::name(v)) + } + + // Mutable pointer to the field. + pub fn mut_name(&mut self) -> &mut ::std::string::String { + if let ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_name::name(_)) = self.one_of_name { + } else { + self.one_of_name = ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_name::name(::std::string::String::new())); + } + match self.one_of_name { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_name::name(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_name(&mut self) -> ::std::string::String { + if self.has_name() { + match self.one_of_name.take() { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_name::name(v)) => v, + _ => panic!(), + } + } else { + ::std::string::String::new() + } + } + + // string email = 3; + + + pub fn get_email(&self) -> &str { + match self.one_of_email { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_email::email(ref v)) => v, + _ => "", + } + } + pub fn clear_email(&mut self) { + self.one_of_email = ::std::option::Option::None; + } + + pub fn has_email(&self) -> bool { + match self.one_of_email { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_email::email(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_email(&mut self, v: ::std::string::String) { + self.one_of_email = ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_email::email(v)) + } + + // Mutable pointer to the field. + pub fn mut_email(&mut self) -> &mut ::std::string::String { + if let ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_email::email(_)) = self.one_of_email { + } else { + self.one_of_email = ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_email::email(::std::string::String::new())); + } + match self.one_of_email { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_email::email(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_email(&mut self) -> ::std::string::String { + if self.has_email() { + match self.one_of_email.take() { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_email::email(v)) => v, + _ => panic!(), + } + } else { + ::std::string::String::new() + } + } + + // string workspace = 4; + + + pub fn get_workspace(&self) -> &str { + match self.one_of_workspace { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_workspace::workspace(ref v)) => v, + _ => "", + } + } + pub fn clear_workspace(&mut self) { + self.one_of_workspace = ::std::option::Option::None; + } + + pub fn has_workspace(&self) -> bool { + match self.one_of_workspace { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_workspace::workspace(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_workspace(&mut self, v: ::std::string::String) { + self.one_of_workspace = ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_workspace::workspace(v)) + } + + // Mutable pointer to the field. + pub fn mut_workspace(&mut self) -> &mut ::std::string::String { + if let ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_workspace::workspace(_)) = self.one_of_workspace { + } else { + self.one_of_workspace = ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_workspace::workspace(::std::string::String::new())); + } + match self.one_of_workspace { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_workspace::workspace(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_workspace(&mut self) -> ::std::string::String { + if self.has_workspace() { + match self.one_of_workspace.take() { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_workspace::workspace(v)) => v, + _ => panic!(), + } + } else { + ::std::string::String::new() + } + } + + // string password = 5; + + + pub fn get_password(&self) -> &str { + match self.one_of_password { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_password::password(ref v)) => v, + _ => "", + } + } + pub fn clear_password(&mut self) { + self.one_of_password = ::std::option::Option::None; + } + + pub fn has_password(&self) -> bool { + match self.one_of_password { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_password::password(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_password(&mut self, v: ::std::string::String) { + self.one_of_password = ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_password::password(v)) + } + + // Mutable pointer to the field. + pub fn mut_password(&mut self) -> &mut ::std::string::String { + if let ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_password::password(_)) = self.one_of_password { + } else { + self.one_of_password = ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_password::password(::std::string::String::new())); + } + match self.one_of_password { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_password::password(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_password(&mut self) -> ::std::string::String { + if self.has_password() { + match self.one_of_password.take() { + ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_password::password(v)) => v, + _ => panic!(), + } + } else { + ::std::string::String::new() + } + } +} + +impl ::protobuf::Message for UpdateUserRequest { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.id)?; + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.one_of_name = ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_name::name(is.read_string()?)); + }, + 3 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.one_of_email = ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_email::email(is.read_string()?)); + }, + 4 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.one_of_workspace = ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_workspace::workspace(is.read_string()?)); + }, + 5 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.one_of_password = ::std::option::Option::Some(UpdateUserRequest_oneof_one_of_password::password(is.read_string()?)); + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.id); + } + if let ::std::option::Option::Some(ref v) = self.one_of_name { + match v { + &UpdateUserRequest_oneof_one_of_name::name(ref v) => { + my_size += ::protobuf::rt::string_size(2, &v); + }, + }; + } + if let ::std::option::Option::Some(ref v) = self.one_of_email { + match v { + &UpdateUserRequest_oneof_one_of_email::email(ref v) => { + my_size += ::protobuf::rt::string_size(3, &v); + }, + }; + } + if let ::std::option::Option::Some(ref v) = self.one_of_workspace { + match v { + &UpdateUserRequest_oneof_one_of_workspace::workspace(ref v) => { + my_size += ::protobuf::rt::string_size(4, &v); + }, + }; + } + if let ::std::option::Option::Some(ref v) = self.one_of_password { + match v { + &UpdateUserRequest_oneof_one_of_password::password(ref v) => { + my_size += ::protobuf::rt::string_size(5, &v); + }, + }; + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.id.is_empty() { + os.write_string(1, &self.id)?; + } + if let ::std::option::Option::Some(ref v) = self.one_of_name { + match v { + &UpdateUserRequest_oneof_one_of_name::name(ref v) => { + os.write_string(2, v)?; + }, + }; + } + if let ::std::option::Option::Some(ref v) = self.one_of_email { + match v { + &UpdateUserRequest_oneof_one_of_email::email(ref v) => { + os.write_string(3, v)?; + }, + }; + } + if let ::std::option::Option::Some(ref v) = self.one_of_workspace { + match v { + &UpdateUserRequest_oneof_one_of_workspace::workspace(ref v) => { + os.write_string(4, v)?; + }, + }; + } + if let ::std::option::Option::Some(ref v) = self.one_of_password { + match v { + &UpdateUserRequest_oneof_one_of_password::password(ref v) => { + os.write_string(5, v)?; + }, + }; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> UpdateUserRequest { + UpdateUserRequest::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "id", + |m: &UpdateUserRequest| { &m.id }, + |m: &mut UpdateUserRequest| { &mut m.id }, + )); + fields.push(::protobuf::reflect::accessor::make_singular_string_accessor::<_>( + "name", + UpdateUserRequest::has_name, + UpdateUserRequest::get_name, + )); + fields.push(::protobuf::reflect::accessor::make_singular_string_accessor::<_>( + "email", + UpdateUserRequest::has_email, + UpdateUserRequest::get_email, + )); + fields.push(::protobuf::reflect::accessor::make_singular_string_accessor::<_>( + "workspace", + UpdateUserRequest::has_workspace, + UpdateUserRequest::get_workspace, + )); + fields.push(::protobuf::reflect::accessor::make_singular_string_accessor::<_>( + "password", + UpdateUserRequest::has_password, + UpdateUserRequest::get_password, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "UpdateUserRequest", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static UpdateUserRequest { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(UpdateUserRequest::new) + } +} + +impl ::protobuf::Clear for UpdateUserRequest { + fn clear(&mut self) { + self.id.clear(); + self.one_of_name = ::std::option::Option::None; + self.one_of_email = ::std::option::Option::None; + self.one_of_workspace = ::std::option::Option::None; + self.one_of_password = ::std::option::Option::None; + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for UpdateUserRequest { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for UpdateUserRequest { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x11user_update.proto\"\xd5\x01\n\x11UpdateUserRequest\x12\x0e\n\x02id\ + \x18\x01\x20\x01(\tR\x02id\x12\x14\n\x04name\x18\x02\x20\x01(\tH\0R\x04n\ + ame\x12\x16\n\x05email\x18\x03\x20\x01(\tH\x01R\x05email\x12\x1e\n\twork\ + space\x18\x04\x20\x01(\tH\x02R\tworkspace\x12\x1c\n\x08password\x18\x05\ + \x20\x01(\tH\x03R\x08passwordB\r\n\x0bone_of_nameB\x0e\n\x0cone_of_email\ + B\x12\n\x10one_of_workspaceB\x11\n\x0fone_of_passwordJ\xa9\x03\n\x06\x12\ + \x04\0\0\x08\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\ + \x02\0\x08\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x19\n\x0b\n\x04\x04\0\ + \x02\0\x12\x03\x03\x04\x12\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\ + \n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\r\n\x0c\n\x05\x04\0\x02\0\ + \x03\x12\x03\x03\x10\x11\n\x0b\n\x04\x04\0\x08\0\x12\x03\x04\x04*\n\x0c\ + \n\x05\x04\0\x08\0\x01\x12\x03\x04\n\x15\n\x0b\n\x04\x04\0\x02\x01\x12\ + \x03\x04\x18(\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x18\x1e\n\x0c\n\ + \x05\x04\0\x02\x01\x01\x12\x03\x04\x1f#\n\x0c\n\x05\x04\0\x02\x01\x03\ + \x12\x03\x04&'\n\x0b\n\x04\x04\0\x08\x01\x12\x03\x05\x04,\n\x0c\n\x05\ + \x04\0\x08\x01\x01\x12\x03\x05\n\x16\n\x0b\n\x04\x04\0\x02\x02\x12\x03\ + \x05\x19*\n\x0c\n\x05\x04\0\x02\x02\x05\x12\x03\x05\x19\x1f\n\x0c\n\x05\ + \x04\0\x02\x02\x01\x12\x03\x05\x20%\n\x0c\n\x05\x04\0\x02\x02\x03\x12\ + \x03\x05()\n\x0b\n\x04\x04\0\x08\x02\x12\x03\x06\x044\n\x0c\n\x05\x04\0\ + \x08\x02\x01\x12\x03\x06\n\x1a\n\x0b\n\x04\x04\0\x02\x03\x12\x03\x06\x1d\ + 2\n\x0c\n\x05\x04\0\x02\x03\x05\x12\x03\x06\x1d#\n\x0c\n\x05\x04\0\x02\ + \x03\x01\x12\x03\x06$-\n\x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x0601\n\x0b\ + \n\x04\x04\0\x08\x03\x12\x03\x07\x042\n\x0c\n\x05\x04\0\x08\x03\x01\x12\ + \x03\x07\n\x19\n\x0b\n\x04\x04\0\x02\x04\x12\x03\x07\x1c0\n\x0c\n\x05\ + \x04\0\x02\x04\x05\x12\x03\x07\x1c\"\n\x0c\n\x05\x04\0\x02\x04\x01\x12\ + \x03\x07#+\n\x0c\n\x05\x04\0\x02\x04\x03\x12\x03\x07./b\x06proto3\ +"; + +static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::Message::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) +} diff --git a/rust-lib/flowy-user/src/protobuf/proto/errors.proto b/rust-lib/flowy-user/src/protobuf/proto/errors.proto index 9d087ef9d2..0d880f5fa1 100644 --- a/rust-lib/flowy-user/src/protobuf/proto/errors.proto +++ b/rust-lib/flowy-user/src/protobuf/proto/errors.proto @@ -17,4 +17,6 @@ enum UserErrorCode { EmailInvalid = 20; PasswordInvalid = 21; UserNameInvalid = 22; + UserWorkspaceInvalid = 23; + UserIdInvalid = 24; } diff --git a/rust-lib/flowy-user/src/protobuf/proto/event.proto b/rust-lib/flowy-user/src/protobuf/proto/event.proto index b1c3b7bcca..21a6f65d7c 100644 --- a/rust-lib/flowy-user/src/protobuf/proto/event.proto +++ b/rust-lib/flowy-user/src/protobuf/proto/event.proto @@ -5,4 +5,5 @@ enum UserEvent { SignIn = 1; SignUp = 2; SignOut = 3; + UpdateUser = 4; } diff --git a/rust-lib/flowy-user/src/protobuf/proto/user_detail.proto b/rust-lib/flowy-user/src/protobuf/proto/user_detail.proto index 0dfa623fc8..f3fc4f8b6e 100644 --- a/rust-lib/flowy-user/src/protobuf/proto/user_detail.proto +++ b/rust-lib/flowy-user/src/protobuf/proto/user_detail.proto @@ -1,9 +1,11 @@ syntax = "proto3"; message UserDetail { - string email = 1; - string name = 2; - UserStatus status = 3; + string id = 1; + string email = 2; + string name = 3; + UserStatus status = 4; + string workspace = 5; } enum UserStatus { Unknown = 0; diff --git a/rust-lib/flowy-user/src/protobuf/proto/user_update.proto b/rust-lib/flowy-user/src/protobuf/proto/user_update.proto new file mode 100644 index 0000000000..c2db6abc44 --- /dev/null +++ b/rust-lib/flowy-user/src/protobuf/proto/user_update.proto @@ -0,0 +1,9 @@ +syntax = "proto3"; + +message UpdateUserRequest { + string id = 1; + oneof one_of_name { string name = 2; }; + oneof one_of_email { string email = 3; }; + oneof one_of_workspace { string workspace = 4; }; + oneof one_of_password { string password = 5; }; +} diff --git a/rust-lib/flowy-user/src/services/user_session/builder.rs b/rust-lib/flowy-user/src/services/user_session/builder.rs index fe893a71b4..462e7a57a5 100644 --- a/rust-lib/flowy-user/src/services/user_session/builder.rs +++ b/rust-lib/flowy-user/src/services/user_session/builder.rs @@ -1,4 +1,4 @@ -use crate::services::user_session::{user_server::MockUserServer, UserSession, UserSessionConfig}; +use crate::services::user_session::{user_server::UserServer, UserSession, UserSessionConfig}; pub struct UserSessionBuilder { config: Option, @@ -12,9 +12,12 @@ impl UserSessionBuilder { self } - pub fn build(mut self) -> UserSession { + pub fn build(mut self, server: S) -> UserSession + where + S: 'static + UserServer + Send + Sync, + { let config = self.config.take().unwrap(); - let register = MockUserServer {}; - UserSession::new(config, register) + + UserSession::new(config, server) } } diff --git a/rust-lib/flowy-user/src/services/user_session/mod.rs b/rust-lib/flowy-user/src/services/user_session/mod.rs index c5a4914720..896a1afc9f 100644 --- a/rust-lib/flowy-user/src/services/user_session/mod.rs +++ b/rust-lib/flowy-user/src/services/user_session/mod.rs @@ -1,4 +1,5 @@ pub use builder::*; +pub use user_server::*; pub use user_session::*; mod builder; diff --git a/rust-lib/flowy-user/src/services/user_session/user_server.rs b/rust-lib/flowy-user/src/services/user_session/user_server.rs index a9e7c444c6..ef9636adab 100644 --- a/rust-lib/flowy-user/src/services/user_session/user_server.rs +++ b/rust-lib/flowy-user/src/services/user_session/user_server.rs @@ -3,6 +3,7 @@ use crate::{ errors::{ErrorBuilder, UserError, UserErrorCode}, sql_tables::User, }; +use flowy_infra::uuid; pub trait UserServer { fn sign_up(&self, params: SignUpParams) -> Result; @@ -10,36 +11,3 @@ pub trait UserServer { fn get_user_info(&self, user_id: &str) -> Result; fn sign_out(&self, user_id: &str) -> Result<(), UserError>; } - -pub struct MockUserServer {} - -impl UserServer for MockUserServer { - fn sign_up(&self, params: SignUpParams) -> Result { - let user_id = "9527".to_owned(); - // let user_id = uuid(); - Ok(User::new( - user_id, - params.name, - params.email, - params.password, - )) - } - - fn sign_in(&self, params: SignInParams) -> Result { - let user_id = "9527".to_owned(); - Ok(User::new( - user_id, - "".to_owned(), - params.email, - params.password, - )) - } - - fn get_user_info(&self, _user_id: &str) -> Result { - Err(ErrorBuilder::new(UserErrorCode::Unknown).build()) - } - - fn sign_out(&self, _user_id: &str) -> Result<(), UserError> { - Err(ErrorBuilder::new(UserErrorCode::Unknown).build()) - } -} diff --git a/rust-lib/flowy-user/src/services/user_session/user_session.rs b/rust-lib/flowy-user/src/services/user_session/user_session.rs index 5c3498fc53..871fbb79ea 100644 --- a/rust-lib/flowy-user/src/services/user_session/user_session.rs +++ b/rust-lib/flowy-user/src/services/user_session/user_session.rs @@ -10,13 +10,10 @@ use lazy_static::lazy_static; use std::sync::RwLock; use crate::{ - entities::{SignInParams, SignUpParams, UserDetail}, + entities::{SignInParams, SignUpParams, UpdateUserParams, UserDetail}, errors::{ErrorBuilder, UserError, UserErrorCode}, - services::user_session::{ - database::UserDB, - user_server::{UserServer, *}, - }, - sql_tables::User, + services::user_session::{database::UserDB, user_server::UserServer}, + sql_tables::{User, UserChangeset}, }; pub struct UserSessionConfig { @@ -38,7 +35,7 @@ pub struct UserSession { } impl UserSession { - pub fn new(config: UserSessionConfig, register: R) -> Self + pub fn new(config: UserSessionConfig, server: R) -> Self where R: 'static + UserServer + Send + Sync, { @@ -46,7 +43,7 @@ impl UserSession { Self { database: db, config, - server: Box::new(register), + server: Box::new(server), } } @@ -77,7 +74,16 @@ impl UserSession { Ok(()) } - pub async fn current_user_detail(&self) -> Result { + pub async fn update_user(&self, params: UpdateUserParams) -> Result { + let changeset = UserChangeset::new(params); + let conn = self.get_db_connection()?; + diesel_update_table!(user_table, changeset, conn); + + let user_detail = self.current_user_detail()?; + Ok(user_detail) + } + + pub fn current_user_detail(&self) -> Result { let user_id = self.current_user_id()?; let conn = self.get_db_connection()?; @@ -98,10 +104,21 @@ impl UserSession { } pub fn get_db_connection(&self) -> Result { - match get_current_user_id()? { - None => Err(ErrorBuilder::new(UserErrorCode::UserNotLoginYet).build()), - Some(user_id) => self.database.get_connection(&user_id), - } + let user_id = get_current_user_id()?; + self.database.get_connection(&user_id) + } + + #[allow(dead_code)] + pub fn get_current_workspace(&self) -> Result { + let user_id = get_current_user_id()?; + let conn = self.get_db_connection()?; + + let workspace = dsl::user_table + .filter(user_table::id.eq(&user_id)) + .select(user_table::workspace) + .first::(&*conn)?; + + Ok(workspace) } } @@ -133,7 +150,8 @@ const USER_ID_DISK_CACHE_KEY: &str = "user_id"; lazy_static! { pub static ref CURRENT_USER_ID: RwLock> = RwLock::new(None); } -pub(crate) fn get_current_user_id() -> Result, UserError> { + +pub(crate) fn get_current_user_id() -> Result { let read_guard = CURRENT_USER_ID.read().map_err(|e| { ErrorBuilder::new(UserErrorCode::ReadCurrentIdFailed) .error(e) @@ -149,7 +167,14 @@ pub(crate) fn get_current_user_id() -> Result, UserError> { *(CURRENT_USER_ID.write().unwrap()) = user_id.clone(); } - Ok(user_id) + if user_id.is_none() { + return Err(ErrorBuilder::new(UserErrorCode::UserNotLoginYet).build()); + } + + match user_id { + None => Err(ErrorBuilder::new(UserErrorCode::UserNotLoginYet).build()), + Some(user_id) => Ok(user_id), + } } pub(crate) fn set_current_user_id(user_id: Option) -> Result<(), UserError> { diff --git a/rust-lib/flowy-user/src/sql_tables/mod.rs b/rust-lib/flowy-user/src/sql_tables/mod.rs index 9ec3bba54d..2478900d79 100644 --- a/rust-lib/flowy-user/src/sql_tables/mod.rs +++ b/rust-lib/flowy-user/src/sql_tables/mod.rs @@ -1,3 +1,3 @@ -mod user_table; +mod user; -pub use user_table::*; +pub use user::*; diff --git a/rust-lib/flowy-user/src/sql_tables/user.rs b/rust-lib/flowy-user/src/sql_tables/user.rs new file mode 100644 index 0000000000..826837e09d --- /dev/null +++ b/rust-lib/flowy-user/src/sql_tables/user.rs @@ -0,0 +1,51 @@ +use crate::entities::UpdateUserParams; +use flowy_database::schema::user_table; + +#[derive(Clone, Default, Queryable, Identifiable, Insertable)] +#[table_name = "user_table"] +pub struct User { + pub(crate) id: String, + pub(crate) name: String, + pub(crate) password: String, + pub(crate) email: String, + pub(crate) workspace: String, +} + +impl User { + pub fn new(id: String, name: String, email: String, password: String) -> Self { + Self { + id, + name, + email, + password, + workspace: "".to_owned(), + } + } + + pub fn set_workspace(mut self, workspace: String) -> Self { + self.workspace = workspace; + self + } +} + +#[derive(AsChangeset, Identifiable, Default, Debug)] +#[table_name = "user_table"] +pub struct UserChangeset { + pub id: String, + pub workspace: Option, + pub name: Option, + pub email: Option, + pub password: Option, +} + +impl UserChangeset { + pub fn new(params: UpdateUserParams) -> Self { + UserChangeset { + id: params.id, + workspace: params.workspace, + name: params.name, + email: params.email, + password: params.password, + } + } +} diff --git a/rust-lib/flowy-user/src/sql_tables/user_table.rs b/rust-lib/flowy-user/src/sql_tables/user_table.rs deleted file mode 100644 index dee641ae7b..0000000000 --- a/rust-lib/flowy-user/src/sql_tables/user_table.rs +++ /dev/null @@ -1,21 +0,0 @@ -use flowy_database::schema::user_table; - -#[derive(Clone, Default, Queryable, Identifiable, Insertable)] -#[table_name = "user_table"] -pub struct User { - pub(crate) id: String, - pub(crate) name: String, - password: String, - pub(crate) email: String, -} - -impl User { - pub fn new(id: String, name: String, email: String, password: String) -> Self { - Self { - id, - name, - email, - password, - } - } -} diff --git a/rust-lib/flowy-user/tests/event/helper.rs b/rust-lib/flowy-user/tests/event/helper.rs index bc1a6503f1..12bc74614a 100644 --- a/rust-lib/flowy-user/tests/event/helper.rs +++ b/rust-lib/flowy-user/tests/event/helper.rs @@ -1,7 +1,7 @@ -use flowy_test::EventTester; +use flowy_test::{EventTester, TesterConfig}; use flowy_user::errors::UserError; -pub type UserEventTester = EventTester; +pub type UserEventTester = EventTester; pub(crate) fn invalid_email_test_case() -> Vec { // https://gist.github.com/cjaoude/fd9910626629b53c4d25 diff --git a/rust-lib/flowy-user/tests/event/sign_in_test.rs b/rust-lib/flowy-user/tests/event/sign_in_test.rs index 3edd5a5011..f5219964fe 100644 --- a/rust-lib/flowy-user/tests/event/sign_in_test.rs +++ b/rust-lib/flowy-user/tests/event/sign_in_test.rs @@ -1,10 +1,6 @@ use crate::helper::*; -use flowy_test::prelude::*; -use flowy_user::{ - errors::{UserError, UserErrorCode}, - event::UserEvent::*, - prelude::*, -}; + +use flowy_user::{errors::UserErrorCode, event::UserEvent::*, prelude::*}; use serial_test::*; #[test] diff --git a/rust-lib/flowy-user/tests/event/sign_up_test.rs b/rust-lib/flowy-user/tests/event/sign_up_test.rs index 23efc4fb60..bf6f2bc3b1 100644 --- a/rust-lib/flowy-user/tests/event/sign_up_test.rs +++ b/rust-lib/flowy-user/tests/event/sign_up_test.rs @@ -1,5 +1,5 @@ use crate::helper::*; -use flowy_test::prelude::*; + use flowy_user::{errors::*, event::UserEvent::*, prelude::*}; use serial_test::*; diff --git a/rust-lib/flowy-user/tests/event/user_status_test.rs b/rust-lib/flowy-user/tests/event/user_status_test.rs index 102a7225c3..73e3b2581c 100644 --- a/rust-lib/flowy-user/tests/event/user_status_test.rs +++ b/rust-lib/flowy-user/tests/event/user_status_test.rs @@ -1,7 +1,8 @@ use crate::helper::*; -use flowy_test::prelude::*; -use flowy_user::{event::UserEvent::*, prelude::*}; + +use flowy_user::{errors::UserErrorCode, event::UserEvent::*, prelude::*}; use serial_test::*; + #[test] #[should_panic] #[serial] @@ -31,3 +32,41 @@ fn user_status_did_found_after_login() { .sync_send() .parse::(); } + +#[test] +#[serial] +fn user_update_with_invalid_email() { + let _ = UserEventTester::new(SignOut).sync_send(); + let request = SignInRequest { + email: valid_email(), + password: valid_password(), + }; + + let _ = UserEventTester::new(SignIn) + .request(request) + .sync_send() + .parse::(); + + let user_detail = UserEventTester::new(GetStatus) + .sync_send() + .parse::(); + + for email in invalid_email_test_case() { + let request = UpdateUserRequest { + id: user_detail.id.clone(), + name: None, + email: Some(email), + workspace: None, + password: None, + }; + + assert_eq!( + UserEventTester::new(UpdateUser) + .request(request) + .sync_send() + .error() + .code, + UserErrorCode::EmailInvalid + ); + } +} diff --git a/rust-lib/flowy-workspace/Cargo.toml b/rust-lib/flowy-workspace/Cargo.toml index aa576907a0..4610dcdcf7 100644 --- a/rust-lib/flowy-workspace/Cargo.toml +++ b/rust-lib/flowy-workspace/Cargo.toml @@ -21,6 +21,7 @@ lazy_static = "1.4.0" serde = { version = "1.0", features = ["derive"] } derive_more = {version = "0.99", features = ["display"]} bincode = { version = "1.3"} +unicode-segmentation = "1.7.1" [dev-dependencies] flowy-test = { path = "../flowy-test" } \ No newline at end of file diff --git a/rust-lib/flowy-workspace/src/entities/app/app_create.rs b/rust-lib/flowy-workspace/src/entities/app/app_create.rs index 1337b232f2..5d74537dcb 100644 --- a/rust-lib/flowy-workspace/src/entities/app/app_create.rs +++ b/rust-lib/flowy-workspace/src/entities/app/app_create.rs @@ -1,7 +1,7 @@ use crate::{ entities::{ - app::{app_color_style::AppColorStyle, app_name::AppName}, - workspace::WorkspaceId, + app::parser::{AppColorStyle, AppName}, + workspace::parser::WorkspaceId, }, errors::*, }; @@ -66,3 +66,18 @@ impl TryInto for CreateAppRequest { }) } } + +#[derive(ProtoBuf, Default, Debug)] +pub struct AppDetail { + #[pb(index = 1)] + pub id: String, + + #[pb(index = 2)] + pub workspace_id: String, + + #[pb(index = 3)] + pub name: String, + + #[pb(index = 4)] + pub desc: String, +} diff --git a/rust-lib/flowy-workspace/src/entities/app/app_update.rs b/rust-lib/flowy-workspace/src/entities/app/app_update.rs index 71e68570af..6b84df2428 100644 --- a/rust-lib/flowy-workspace/src/entities/app/app_update.rs +++ b/rust-lib/flowy-workspace/src/entities/app/app_update.rs @@ -1,7 +1,10 @@ use crate::{ entities::{ - app::{app_color_style::AppColorStyle, app_id::AppId, app_name::AppName, ColorStyle}, - workspace::WorkspaceId, + app::{ + parser::{AppColorStyle, AppId, AppName}, + ColorStyle, + }, + workspace::parser::WorkspaceId, }, errors::{ErrorBuilder, WorkspaceError, WorkspaceErrorCode}, }; diff --git a/rust-lib/flowy-workspace/src/entities/app/mod.rs b/rust-lib/flowy-workspace/src/entities/app/mod.rs index 5eaa96da68..d370d42cd8 100644 --- a/rust-lib/flowy-workspace/src/entities/app/mod.rs +++ b/rust-lib/flowy-workspace/src/entities/app/mod.rs @@ -1,8 +1,6 @@ -mod app_color_style; -mod app_create; -mod app_id; -mod app_name; -mod app_update; - pub use app_create::*; pub use app_update::*; + +mod app_create; +mod app_update; +mod parser; diff --git a/rust-lib/flowy-workspace/src/entities/app/app_color_style.rs b/rust-lib/flowy-workspace/src/entities/app/parser/app_color_style.rs similarity index 100% rename from rust-lib/flowy-workspace/src/entities/app/app_color_style.rs rename to rust-lib/flowy-workspace/src/entities/app/parser/app_color_style.rs diff --git a/rust-lib/flowy-workspace/src/entities/app/app_id.rs b/rust-lib/flowy-workspace/src/entities/app/parser/app_id.rs similarity index 100% rename from rust-lib/flowy-workspace/src/entities/app/app_id.rs rename to rust-lib/flowy-workspace/src/entities/app/parser/app_id.rs diff --git a/rust-lib/flowy-workspace/src/entities/app/app_name.rs b/rust-lib/flowy-workspace/src/entities/app/parser/app_name.rs similarity index 100% rename from rust-lib/flowy-workspace/src/entities/app/app_name.rs rename to rust-lib/flowy-workspace/src/entities/app/parser/app_name.rs diff --git a/rust-lib/flowy-workspace/src/entities/app/parser/mod.rs b/rust-lib/flowy-workspace/src/entities/app/parser/mod.rs new file mode 100644 index 0000000000..93d445d109 --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/app/parser/mod.rs @@ -0,0 +1,7 @@ +mod app_color_style; +mod app_id; +mod app_name; + +pub use app_color_style::*; +pub use app_id::*; +pub use app_name::*; diff --git a/rust-lib/flowy-workspace/src/entities/workspace/mod.rs b/rust-lib/flowy-workspace/src/entities/workspace/mod.rs index 7bbd8c96eb..8c44c9cd11 100644 --- a/rust-lib/flowy-workspace/src/entities/workspace/mod.rs +++ b/rust-lib/flowy-workspace/src/entities/workspace/mod.rs @@ -1,11 +1,8 @@ -mod workspace_create; -mod workspace_id; -mod workspace_name; -mod workspace_query; -mod workspace_update; - pub use workspace_create::*; -pub use workspace_id::*; -pub use workspace_name::*; pub use workspace_query::*; pub use workspace_update::*; + +pub(crate) mod parser; +mod workspace_create; +mod workspace_query; +mod workspace_update; diff --git a/rust-lib/flowy-workspace/src/entities/workspace/parser/mod.rs b/rust-lib/flowy-workspace/src/entities/workspace/parser/mod.rs new file mode 100644 index 0000000000..c266c5167f --- /dev/null +++ b/rust-lib/flowy-workspace/src/entities/workspace/parser/mod.rs @@ -0,0 +1,5 @@ +mod workspace_id; +mod workspace_name; + +pub use workspace_id::*; +pub use workspace_name::*; diff --git a/rust-lib/flowy-workspace/src/entities/workspace/workspace_id.rs b/rust-lib/flowy-workspace/src/entities/workspace/parser/workspace_id.rs similarity index 100% rename from rust-lib/flowy-workspace/src/entities/workspace/workspace_id.rs rename to rust-lib/flowy-workspace/src/entities/workspace/parser/workspace_id.rs diff --git a/rust-lib/flowy-workspace/src/entities/workspace/workspace_name.rs b/rust-lib/flowy-workspace/src/entities/workspace/parser/workspace_name.rs similarity index 69% rename from rust-lib/flowy-workspace/src/entities/workspace/workspace_name.rs rename to rust-lib/flowy-workspace/src/entities/workspace/parser/workspace_name.rs index 2132135b40..e464d553af 100644 --- a/rust-lib/flowy-workspace/src/entities/workspace/workspace_name.rs +++ b/rust-lib/flowy-workspace/src/entities/workspace/parser/workspace_name.rs @@ -1,3 +1,5 @@ +use unicode_segmentation::UnicodeSegmentation; + #[derive(Debug)] pub struct WorkspaceName(pub String); @@ -7,6 +9,10 @@ impl WorkspaceName { return Err(format!("Workspace name can not be empty or whitespace")); } + if s.graphemes(true).count() > 256 { + return Err(format!("Workspace name too long")); + } + Ok(Self(s)) } } diff --git a/rust-lib/flowy-workspace/src/entities/workspace/workspace_create.rs b/rust-lib/flowy-workspace/src/entities/workspace/workspace_create.rs index b4f972297f..8860009192 100644 --- a/rust-lib/flowy-workspace/src/entities/workspace/workspace_create.rs +++ b/rust-lib/flowy-workspace/src/entities/workspace/workspace_create.rs @@ -1,4 +1,4 @@ -use crate::{entities::workspace::workspace_name::WorkspaceName, errors::*}; +use crate::{entities::workspace::parser::*, errors::*}; use flowy_derive::ProtoBuf; use std::convert::TryInto; diff --git a/rust-lib/flowy-workspace/src/entities/workspace/workspace_update.rs b/rust-lib/flowy-workspace/src/entities/workspace/workspace_update.rs index 86cbe0edda..3352e69890 100644 --- a/rust-lib/flowy-workspace/src/entities/workspace/workspace_update.rs +++ b/rust-lib/flowy-workspace/src/entities/workspace/workspace_update.rs @@ -1,10 +1,9 @@ -use crate::{ - entities::workspace::{workspace_id::WorkspaceId, workspace_name::WorkspaceName}, - errors::*, -}; -use flowy_derive::ProtoBuf; use std::convert::TryInto; +use flowy_derive::ProtoBuf; + +use crate::{entities::workspace::parser::*, errors::*}; + #[derive(ProtoBuf, Default)] pub struct UpdateWorkspaceRequest { #[pb(index = 1)] diff --git a/rust-lib/flowy-workspace/src/errors.rs b/rust-lib/flowy-workspace/src/errors.rs index 4eaacaf3df..d9b5d71074 100644 --- a/rust-lib/flowy-workspace/src/errors.rs +++ b/rust-lib/flowy-workspace/src/errors.rs @@ -43,6 +43,9 @@ pub enum WorkspaceErrorCode { #[display(fmt = "Database internal error")] DatabaseInternalError = 6, + + #[display(fmt = "User internal error")] + UserInternalError = 10, } impl std::default::Default for WorkspaceErrorCode { diff --git a/rust-lib/flowy-workspace/src/handlers/app_handler.rs b/rust-lib/flowy-workspace/src/handlers/app_handler.rs new file mode 100644 index 0000000000..72e41a5cbe --- /dev/null +++ b/rust-lib/flowy-workspace/src/handlers/app_handler.rs @@ -0,0 +1,16 @@ +use crate::{ + entities::app::{AppDetail, CreateAppParams, CreateAppRequest}, + errors::WorkspaceError, + services::AppController, +}; +use flowy_dispatch::prelude::{response_ok, Data, ModuleData, ResponseResult}; +use std::{convert::TryInto, sync::Arc}; + +pub async fn create_app( + data: Data, + controller: ModuleData>, +) -> ResponseResult { + let params: CreateAppParams = data.into_inner().try_into()?; + let detail = controller.save_app(params)?; + response_ok(detail) +} diff --git a/rust-lib/flowy-workspace/src/handlers/mod.rs b/rust-lib/flowy-workspace/src/handlers/mod.rs index bfcb132c58..fdf08a9b51 100644 --- a/rust-lib/flowy-workspace/src/handlers/mod.rs +++ b/rust-lib/flowy-workspace/src/handlers/mod.rs @@ -1,3 +1,5 @@ +mod app_handler; mod workspace_handler; +pub use app_handler::*; pub use workspace_handler::*; diff --git a/rust-lib/flowy-workspace/src/macros.rs b/rust-lib/flowy-workspace/src/macros.rs index 3a3b297064..4690db7a9e 100644 --- a/rust-lib/flowy-workspace/src/macros.rs +++ b/rust-lib/flowy-workspace/src/macros.rs @@ -10,9 +10,9 @@ macro_rules! impl_sql_binary_expression { ) -> diesel::serialize::Result { let bytes: Vec = self.try_into().map_err(|e| format!("{:?}", e))?; diesel::serialize::ToSql::< - diesel::sql_types::Binary, - diesel::sqlite::Sqlite, - >::to_sql(&bytes, out) + diesel::sql_types::Binary, + diesel::sqlite::Sqlite, + >::to_sql(&bytes, out) // match self.try_into() { // Ok(bytes) => diesel::serialize::ToSql::< diff --git a/rust-lib/flowy-workspace/src/module.rs b/rust-lib/flowy-workspace/src/module.rs index 61dedbcf8e..40c060c060 100644 --- a/rust-lib/flowy-workspace/src/module.rs +++ b/rust-lib/flowy-workspace/src/module.rs @@ -1,11 +1,27 @@ use flowy_dispatch::prelude::*; -use crate::{event::WorkspaceEvent, handlers::create_workspace, services::WorkspaceController}; +use crate::{ + errors::WorkspaceError, + event::WorkspaceEvent, + handlers::create_workspace, + services::{AppController, WorkspaceController}, +}; +use flowy_database::{DBConnection, UserDatabaseConnection}; use std::sync::Arc; -pub fn create(controller: Arc) -> Module { +pub trait WorkspaceUser: Send + Sync { + fn set_current_workspace(&self, id: &str); + fn get_current_workspace(&self) -> Result; + fn db_connection(&self) -> Result; +} + +pub fn create(user: Arc) -> Module { + let workspace_controller = Arc::new(WorkspaceController::new(user.clone())); + let app_controller = Arc::new(AppController::new(user.clone())); + Module::new() .name("Flowy-Workspace") - .data(controller) + .data(workspace_controller) + .data(app_controller) .event(WorkspaceEvent::CreateWorkspace, create_workspace) } diff --git a/rust-lib/flowy-workspace/src/protobuf/model/app_create.rs b/rust-lib/flowy-workspace/src/protobuf/model/app_create.rs index 5c2fea644e..7e9d0986fe 100644 --- a/rust-lib/flowy-workspace/src/protobuf/model/app_create.rs +++ b/rust-lib/flowy-workspace/src/protobuf/model/app_create.rs @@ -482,21 +482,309 @@ impl ::protobuf::reflect::ProtobufValue for ColorStyle { } } +#[derive(PartialEq,Clone,Default)] +pub struct AppDetail { + // message fields + pub id: ::std::string::String, + pub workspace_id: ::std::string::String, + pub name: ::std::string::String, + pub desc: ::std::string::String, + // special fields + pub unknown_fields: ::protobuf::UnknownFields, + pub cached_size: ::protobuf::CachedSize, +} + +impl<'a> ::std::default::Default for &'a AppDetail { + fn default() -> &'a AppDetail { + ::default_instance() + } +} + +impl AppDetail { + pub fn new() -> AppDetail { + ::std::default::Default::default() + } + + // string id = 1; + + + pub fn get_id(&self) -> &str { + &self.id + } + pub fn clear_id(&mut self) { + self.id.clear(); + } + + // Param is passed by value, moved + pub fn set_id(&mut self, v: ::std::string::String) { + self.id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_id(&mut self) -> &mut ::std::string::String { + &mut self.id + } + + // Take field + pub fn take_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.id, ::std::string::String::new()) + } + + // string workspace_id = 2; + + + pub fn get_workspace_id(&self) -> &str { + &self.workspace_id + } + pub fn clear_workspace_id(&mut self) { + self.workspace_id.clear(); + } + + // Param is passed by value, moved + pub fn set_workspace_id(&mut self, v: ::std::string::String) { + self.workspace_id = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_workspace_id(&mut self) -> &mut ::std::string::String { + &mut self.workspace_id + } + + // Take field + pub fn take_workspace_id(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.workspace_id, ::std::string::String::new()) + } + + // string name = 3; + + + pub fn get_name(&self) -> &str { + &self.name + } + pub fn clear_name(&mut self) { + self.name.clear(); + } + + // Param is passed by value, moved + pub fn set_name(&mut self, v: ::std::string::String) { + self.name = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_name(&mut self) -> &mut ::std::string::String { + &mut self.name + } + + // Take field + pub fn take_name(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.name, ::std::string::String::new()) + } + + // string desc = 4; + + + pub fn get_desc(&self) -> &str { + &self.desc + } + pub fn clear_desc(&mut self) { + self.desc.clear(); + } + + // Param is passed by value, moved + pub fn set_desc(&mut self, v: ::std::string::String) { + self.desc = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_desc(&mut self) -> &mut ::std::string::String { + &mut self.desc + } + + // Take field + pub fn take_desc(&mut self) -> ::std::string::String { + ::std::mem::replace(&mut self.desc, ::std::string::String::new()) + } +} + +impl ::protobuf::Message for AppDetail { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.id)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.workspace_id)?; + }, + 3 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.name)?; + }, + 4 => { + ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.desc)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.id.is_empty() { + my_size += ::protobuf::rt::string_size(1, &self.id); + } + if !self.workspace_id.is_empty() { + my_size += ::protobuf::rt::string_size(2, &self.workspace_id); + } + if !self.name.is_empty() { + my_size += ::protobuf::rt::string_size(3, &self.name); + } + if !self.desc.is_empty() { + my_size += ::protobuf::rt::string_size(4, &self.desc); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { + if !self.id.is_empty() { + os.write_string(1, &self.id)?; + } + if !self.workspace_id.is_empty() { + os.write_string(2, &self.workspace_id)?; + } + if !self.name.is_empty() { + os.write_string(3, &self.name)?; + } + if !self.desc.is_empty() { + os.write_string(4, &self.desc)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &dyn (::std::any::Any) { + self as &dyn (::std::any::Any) + } + fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { + self as &mut dyn (::std::any::Any) + } + fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> AppDetail { + AppDetail::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "id", + |m: &AppDetail| { &m.id }, + |m: &mut AppDetail| { &mut m.id }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "workspace_id", + |m: &AppDetail| { &m.workspace_id }, + |m: &mut AppDetail| { &mut m.workspace_id }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "name", + |m: &AppDetail| { &m.name }, + |m: &mut AppDetail| { &mut m.name }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "desc", + |m: &AppDetail| { &m.desc }, + |m: &mut AppDetail| { &mut m.desc }, + )); + ::protobuf::reflect::MessageDescriptor::new_pb_name::( + "AppDetail", + fields, + file_descriptor_proto() + ) + }) + } + + fn default_instance() -> &'static AppDetail { + static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; + instance.get(AppDetail::new) + } +} + +impl ::protobuf::Clear for AppDetail { + fn clear(&mut self) { + self.id.clear(); + self.workspace_id.clear(); + self.name.clear(); + self.desc.clear(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for AppDetail { + fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for AppDetail { + fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { + ::protobuf::reflect::ReflectValueRef::Message(self) + } +} + static file_descriptor_proto_data: &'static [u8] = b"\ \n\x10app_create.proto\"\x8b\x01\n\x10CreateAppRequest\x12!\n\x0cworkspa\ ce_id\x18\x01\x20\x01(\tR\x0bworkspaceId\x12\x12\n\x04name\x18\x02\x20\ \x01(\tR\x04name\x12\x12\n\x04desc\x18\x03\x20\x01(\tR\x04desc\x12,\n\ \x0bcolor_style\x18\x04\x20\x01(\x0b2\x0b.ColorStyleR\ncolorStyle\"-\n\n\ - ColorStyle\x12\x1f\n\x0btheme_color\x18\x01\x20\x01(\tR\nthemeColorJ\xd5\ - \x02\n\x06\x12\x04\0\0\n\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\ - \x04\0\x12\x04\x02\0\x07\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x18\n\ - \x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x1c\n\x0c\n\x05\x04\0\x02\0\x05\ - \x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\x17\n\x0c\ - \n\x05\x04\0\x02\0\x03\x12\x03\x03\x1a\x1b\n\x0b\n\x04\x04\0\x02\x01\x12\ - \x03\x04\x04\x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\ - \x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0f\n\x0c\n\x05\x04\0\x02\x01\x03\ - \x12\x03\x04\x12\x13\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x04\x14\n\x0c\ - \n\x05\x04\0\x02\x02\x05\x12\x03\x05\x04\n\n\x0c\n\x05\x04\0\x02\x02\x01\ + ColorStyle\x12\x1f\n\x0btheme_color\x18\x01\x20\x01(\tR\nthemeColor\"f\n\ + \tAppDetail\x12\x0e\n\x02id\x18\x01\x20\x01(\tR\x02id\x12!\n\x0cworkspac\ + e_id\x18\x02\x20\x01(\tR\x0bworkspaceId\x12\x12\n\x04name\x18\x03\x20\ + \x01(\tR\x04name\x12\x12\n\x04desc\x18\x04\x20\x01(\tR\x04descJ\xc9\x04\ + \n\x06\x12\x04\0\0\x10\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\ + \0\x12\x04\x02\0\x07\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x18\n\x0b\n\ + \x04\x04\0\x02\0\x12\x03\x03\x04\x1c\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\ + \x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\x17\n\x0c\n\x05\ + \x04\0\x02\0\x03\x12\x03\x03\x1a\x1b\n\x0b\n\x04\x04\0\x02\x01\x12\x03\ + \x04\x04\x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\ + \x04\0\x02\x01\x01\x12\x03\x04\x0b\x0f\n\x0c\n\x05\x04\0\x02\x01\x03\x12\ + \x03\x04\x12\x13\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x04\x14\n\x0c\n\ + \x05\x04\0\x02\x02\x05\x12\x03\x05\x04\n\n\x0c\n\x05\x04\0\x02\x02\x01\ \x12\x03\x05\x0b\x0f\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x12\x13\n\ \x0b\n\x04\x04\0\x02\x03\x12\x03\x06\x04\x1f\n\x0c\n\x05\x04\0\x02\x03\ \x06\x12\x03\x06\x04\x0e\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x06\x0f\ @@ -504,7 +792,19 @@ static file_descriptor_proto_data: &'static [u8] = b"\ \x12\x04\x08\0\n\x01\n\n\n\x03\x04\x01\x01\x12\x03\x08\x08\x12\n\x0b\n\ \x04\x04\x01\x02\0\x12\x03\t\x04\x1b\n\x0c\n\x05\x04\x01\x02\0\x05\x12\ \x03\t\x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\t\x0b\x16\n\x0c\n\x05\ - \x04\x01\x02\0\x03\x12\x03\t\x19\x1ab\x06proto3\ + \x04\x01\x02\0\x03\x12\x03\t\x19\x1a\n\n\n\x02\x04\x02\x12\x04\x0b\0\x10\ + \x01\n\n\n\x03\x04\x02\x01\x12\x03\x0b\x08\x11\n\x0b\n\x04\x04\x02\x02\0\ + \x12\x03\x0c\x04\x12\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03\x0c\x04\n\n\ + \x0c\n\x05\x04\x02\x02\0\x01\x12\x03\x0c\x0b\r\n\x0c\n\x05\x04\x02\x02\0\ + \x03\x12\x03\x0c\x10\x11\n\x0b\n\x04\x04\x02\x02\x01\x12\x03\r\x04\x1c\n\ + \x0c\n\x05\x04\x02\x02\x01\x05\x12\x03\r\x04\n\n\x0c\n\x05\x04\x02\x02\ + \x01\x01\x12\x03\r\x0b\x17\n\x0c\n\x05\x04\x02\x02\x01\x03\x12\x03\r\x1a\ + \x1b\n\x0b\n\x04\x04\x02\x02\x02\x12\x03\x0e\x04\x14\n\x0c\n\x05\x04\x02\ + \x02\x02\x05\x12\x03\x0e\x04\n\n\x0c\n\x05\x04\x02\x02\x02\x01\x12\x03\ + \x0e\x0b\x0f\n\x0c\n\x05\x04\x02\x02\x02\x03\x12\x03\x0e\x12\x13\n\x0b\n\ + \x04\x04\x02\x02\x03\x12\x03\x0f\x04\x14\n\x0c\n\x05\x04\x02\x02\x03\x05\ + \x12\x03\x0f\x04\n\n\x0c\n\x05\x04\x02\x02\x03\x01\x12\x03\x0f\x0b\x0f\n\ + \x0c\n\x05\x04\x02\x02\x03\x03\x12\x03\x0f\x12\x13b\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-workspace/src/protobuf/model/errors.rs b/rust-lib/flowy-workspace/src/protobuf/model/errors.rs index 27d62bc954..2ac71808cd 100644 --- a/rust-lib/flowy-workspace/src/protobuf/model/errors.rs +++ b/rust-lib/flowy-workspace/src/protobuf/model/errors.rs @@ -222,6 +222,7 @@ pub enum WorkspaceErrorCode { AppIdInvalid = 4, DatabaseConnectionFail = 5, DatabaseInternalError = 6, + UserInternalError = 10, } impl ::protobuf::ProtobufEnum for WorkspaceErrorCode { @@ -238,6 +239,7 @@ impl ::protobuf::ProtobufEnum for WorkspaceErrorCode { 4 => ::std::option::Option::Some(WorkspaceErrorCode::AppIdInvalid), 5 => ::std::option::Option::Some(WorkspaceErrorCode::DatabaseConnectionFail), 6 => ::std::option::Option::Some(WorkspaceErrorCode::DatabaseInternalError), + 10 => ::std::option::Option::Some(WorkspaceErrorCode::UserInternalError), _ => ::std::option::Option::None } } @@ -251,6 +253,7 @@ impl ::protobuf::ProtobufEnum for WorkspaceErrorCode { WorkspaceErrorCode::AppIdInvalid, WorkspaceErrorCode::DatabaseConnectionFail, WorkspaceErrorCode::DatabaseInternalError, + WorkspaceErrorCode::UserInternalError, ]; values } @@ -281,34 +284,36 @@ impl ::protobuf::reflect::ProtobufValue for WorkspaceErrorCode { static file_descriptor_proto_data: &'static [u8] = b"\ \n\x0cerrors.proto\"K\n\x0eWorkspaceError\x12'\n\x04code\x18\x01\x20\x01\ (\x0e2\x13.WorkspaceErrorCodeR\x04code\x12\x10\n\x03msg\x18\x02\x20\x01(\ - \tR\x03msg*\xb6\x01\n\x12WorkspaceErrorCode\x12\x0b\n\x07Unknown\x10\0\ + \tR\x03msg*\xcd\x01\n\x12WorkspaceErrorCode\x12\x0b\n\x07Unknown\x10\0\ \x12\x18\n\x14WorkspaceNameInvalid\x10\x01\x12\x16\n\x12WorkspaceIdInval\ id\x10\x02\x12\x18\n\x14AppColorStyleInvalid\x10\x03\x12\x10\n\x0cAppIdI\ nvalid\x10\x04\x12\x1a\n\x16DatabaseConnectionFail\x10\x05\x12\x19\n\x15\ - DatabaseInternalError\x10\x06J\xcf\x03\n\x06\x12\x04\0\0\x0e\x01\n\x08\n\ - \x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\ - \x04\0\x01\x12\x03\x02\x08\x16\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\ - \x20\n\x0c\n\x05\x04\0\x02\0\x06\x12\x03\x03\x04\x16\n\x0c\n\x05\x04\0\ - \x02\0\x01\x12\x03\x03\x17\x1b\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\ - \x1e\x1f\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\x13\n\x0c\n\x05\x04\0\ - \x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\ - \x0b\x0e\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x11\x12\n\n\n\x02\x05\ - \0\x12\x04\x06\0\x0e\x01\n\n\n\x03\x05\0\x01\x12\x03\x06\x05\x17\n\x0b\n\ - \x04\x05\0\x02\0\x12\x03\x07\x04\x10\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\ - \x07\x04\x0b\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x07\x0e\x0f\n\x0b\n\x04\ - \x05\0\x02\x01\x12\x03\x08\x04\x1d\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\ - \x08\x04\x18\n\x0c\n\x05\x05\0\x02\x01\x02\x12\x03\x08\x1b\x1c\n\x0b\n\ - \x04\x05\0\x02\x02\x12\x03\t\x04\x1b\n\x0c\n\x05\x05\0\x02\x02\x01\x12\ - \x03\t\x04\x16\n\x0c\n\x05\x05\0\x02\x02\x02\x12\x03\t\x19\x1a\n\x0b\n\ - \x04\x05\0\x02\x03\x12\x03\n\x04\x1d\n\x0c\n\x05\x05\0\x02\x03\x01\x12\ - \x03\n\x04\x18\n\x0c\n\x05\x05\0\x02\x03\x02\x12\x03\n\x1b\x1c\n\x0b\n\ - \x04\x05\0\x02\x04\x12\x03\x0b\x04\x15\n\x0c\n\x05\x05\0\x02\x04\x01\x12\ - \x03\x0b\x04\x10\n\x0c\n\x05\x05\0\x02\x04\x02\x12\x03\x0b\x13\x14\n\x0b\ - \n\x04\x05\0\x02\x05\x12\x03\x0c\x04\x1f\n\x0c\n\x05\x05\0\x02\x05\x01\ - \x12\x03\x0c\x04\x1a\n\x0c\n\x05\x05\0\x02\x05\x02\x12\x03\x0c\x1d\x1e\n\ - \x0b\n\x04\x05\0\x02\x06\x12\x03\r\x04\x1e\n\x0c\n\x05\x05\0\x02\x06\x01\ - \x12\x03\r\x04\x19\n\x0c\n\x05\x05\0\x02\x06\x02\x12\x03\r\x1c\x1db\x06p\ - roto3\ + DatabaseInternalError\x10\x06\x12\x15\n\x11UserInternalError\x10\nJ\xf8\ + \x03\n\x06\x12\x04\0\0\x0f\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\ + \x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x16\n\ + \x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x20\n\x0c\n\x05\x04\0\x02\0\x06\ + \x12\x03\x03\x04\x16\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x17\x1b\n\ + \x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x1e\x1f\n\x0b\n\x04\x04\0\x02\x01\ + \x12\x03\x04\x04\x13\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\ + \x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0e\n\x0c\n\x05\x04\0\x02\ + \x01\x03\x12\x03\x04\x11\x12\n\n\n\x02\x05\0\x12\x04\x06\0\x0f\x01\n\n\n\ + \x03\x05\0\x01\x12\x03\x06\x05\x17\n\x0b\n\x04\x05\0\x02\0\x12\x03\x07\ + \x04\x10\n\x0c\n\x05\x05\0\x02\0\x01\x12\x03\x07\x04\x0b\n\x0c\n\x05\x05\ + \0\x02\0\x02\x12\x03\x07\x0e\x0f\n\x0b\n\x04\x05\0\x02\x01\x12\x03\x08\ + \x04\x1d\n\x0c\n\x05\x05\0\x02\x01\x01\x12\x03\x08\x04\x18\n\x0c\n\x05\ + \x05\0\x02\x01\x02\x12\x03\x08\x1b\x1c\n\x0b\n\x04\x05\0\x02\x02\x12\x03\ + \t\x04\x1b\n\x0c\n\x05\x05\0\x02\x02\x01\x12\x03\t\x04\x16\n\x0c\n\x05\ + \x05\0\x02\x02\x02\x12\x03\t\x19\x1a\n\x0b\n\x04\x05\0\x02\x03\x12\x03\n\ + \x04\x1d\n\x0c\n\x05\x05\0\x02\x03\x01\x12\x03\n\x04\x18\n\x0c\n\x05\x05\ + \0\x02\x03\x02\x12\x03\n\x1b\x1c\n\x0b\n\x04\x05\0\x02\x04\x12\x03\x0b\ + \x04\x15\n\x0c\n\x05\x05\0\x02\x04\x01\x12\x03\x0b\x04\x10\n\x0c\n\x05\ + \x05\0\x02\x04\x02\x12\x03\x0b\x13\x14\n\x0b\n\x04\x05\0\x02\x05\x12\x03\ + \x0c\x04\x1f\n\x0c\n\x05\x05\0\x02\x05\x01\x12\x03\x0c\x04\x1a\n\x0c\n\ + \x05\x05\0\x02\x05\x02\x12\x03\x0c\x1d\x1e\n\x0b\n\x04\x05\0\x02\x06\x12\ + \x03\r\x04\x1e\n\x0c\n\x05\x05\0\x02\x06\x01\x12\x03\r\x04\x19\n\x0c\n\ + \x05\x05\0\x02\x06\x02\x12\x03\r\x1c\x1d\n\x0b\n\x04\x05\0\x02\x07\x12\ + \x03\x0e\x04\x1b\n\x0c\n\x05\x05\0\x02\x07\x01\x12\x03\x0e\x04\x15\n\x0c\ + \n\x05\x05\0\x02\x07\x02\x12\x03\x0e\x18\x1ab\x06proto3\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/app_create.proto b/rust-lib/flowy-workspace/src/protobuf/proto/app_create.proto index 2f6bee1f19..fdb1591a26 100644 --- a/rust-lib/flowy-workspace/src/protobuf/proto/app_create.proto +++ b/rust-lib/flowy-workspace/src/protobuf/proto/app_create.proto @@ -9,3 +9,9 @@ message CreateAppRequest { message ColorStyle { string theme_color = 1; } +message AppDetail { + string id = 1; + string workspace_id = 2; + string name = 3; + string desc = 4; +} diff --git a/rust-lib/flowy-workspace/src/protobuf/proto/errors.proto b/rust-lib/flowy-workspace/src/protobuf/proto/errors.proto index b157366d38..bab7a7c5e8 100644 --- a/rust-lib/flowy-workspace/src/protobuf/proto/errors.proto +++ b/rust-lib/flowy-workspace/src/protobuf/proto/errors.proto @@ -12,4 +12,5 @@ enum WorkspaceErrorCode { AppIdInvalid = 4; DatabaseConnectionFail = 5; DatabaseInternalError = 6; + UserInternalError = 10; } diff --git a/rust-lib/flowy-workspace/src/services/app_controller.rs b/rust-lib/flowy-workspace/src/services/app_controller.rs new file mode 100644 index 0000000000..cfa5327574 --- /dev/null +++ b/rust-lib/flowy-workspace/src/services/app_controller.rs @@ -0,0 +1,34 @@ +use crate::{ + entities::app::{AppDetail, CreateAppParams, *}, + errors::*, + module::WorkspaceUser, + sql_tables::app::*, +}; +use flowy_database::{prelude::*, schema::app_table}; +use std::sync::Arc; + +pub struct AppController { + user: Arc, +} + +impl AppController { + pub fn new(user: Arc) -> Self { Self { user } } + + pub fn save_app(&self, params: CreateAppParams) -> Result { + let app = App::new(params); + let conn = self.user.db_connection()?; + + let detail: AppDetail = app.clone().into(); + let _ = diesel::insert_into(app_table::table) + .values(app) + .execute(&*conn)?; + Ok(detail) + } + + pub fn update_app(&self, params: UpdateAppParams) -> Result<(), WorkspaceError> { + let changeset = AppChangeset::new(params); + let conn = self.user.db_connection()?; + diesel_update_table!(app_table, changeset, conn); + Ok(()) + } +} diff --git a/rust-lib/flowy-workspace/src/services/helper.rs b/rust-lib/flowy-workspace/src/services/helper.rs new file mode 100644 index 0000000000..8b13789179 --- /dev/null +++ b/rust-lib/flowy-workspace/src/services/helper.rs @@ -0,0 +1 @@ + diff --git a/rust-lib/flowy-workspace/src/services/mod.rs b/rust-lib/flowy-workspace/src/services/mod.rs index 07fc06948d..0743fa6d23 100644 --- a/rust-lib/flowy-workspace/src/services/mod.rs +++ b/rust-lib/flowy-workspace/src/services/mod.rs @@ -1,4 +1,7 @@ +mod app_controller; mod database; +mod helper; mod workspace_controller; +pub use app_controller::*; pub use workspace_controller::*; diff --git a/rust-lib/flowy-workspace/src/services/workspace_controller.rs b/rust-lib/flowy-workspace/src/services/workspace_controller.rs index 40baf07baa..05e8c73375 100644 --- a/rust-lib/flowy-workspace/src/services/workspace_controller.rs +++ b/rust-lib/flowy-workspace/src/services/workspace_controller.rs @@ -1,46 +1,20 @@ -use crate::{ - entities::{app::*, workspace::*}, - errors::*, - sql_tables::{app::*, workspace::*}, -}; -use diesel::ExpressionMethods; -use flowy_database::{ - query_dsl::*, - schema::{app_table, workspace_table}, - DBConnection, - RunQueryDsl, - UserDatabaseConnection, -}; +use crate::{entities::workspace::*, errors::*, module::WorkspaceUser, sql_tables::workspace::*}; +use flowy_database::{prelude::*, schema::workspace_table}; use std::sync::Arc; -macro_rules! diesel_update_table { - ( - $table_name:ident, - $changeset:ident, - $connection:ident - ) => { - let filter = - $table_name::dsl::$table_name.filter($table_name::dsl::id.eq($changeset.id.clone())); - let affected_row = diesel::update(filter) - .set($changeset) - .execute(&*$connection)?; - debug_assert_eq!(affected_row, 1); - }; -} - pub struct WorkspaceController { - db: Arc, + pub(crate) user: Arc, } impl WorkspaceController { - pub fn new(db: Arc) -> Self { Self { db } } + pub fn new(user: Arc) -> Self { Self { user } } pub fn save_workspace( &self, params: CreateWorkspaceParams, ) -> Result { let workspace = Workspace::new(params); - let conn = self.get_connection()?; + let conn = self.user.db_connection()?; let detail: WorkspaceDetail = workspace.clone().into(); let _ = diesel::insert_into(workspace_table::table) @@ -52,35 +26,9 @@ impl WorkspaceController { pub fn update_workspace(&self, params: UpdateWorkspaceParams) -> Result<(), WorkspaceError> { let changeset = WorkspaceChangeset::new(params); - let conn = self.get_connection()?; + let conn = self.user.db_connection()?; diesel_update_table!(workspace_table, changeset, conn); Ok(()) } - - pub fn save_app(&self, params: CreateAppParams) -> Result<(), WorkspaceError> { - let app = App::new(params); - let conn = self.get_connection()?; - let _ = diesel::insert_into(app_table::table) - .values(app) - .execute(&*conn)?; - Ok(()) - } - - pub fn update_app(&self, params: UpdateAppParams) -> Result<(), WorkspaceError> { - let changeset = AppChangeset::new(params); - let conn = self.get_connection()?; - diesel_update_table!(app_table, changeset, conn); - Ok(()) - } -} - -impl WorkspaceController { - fn get_connection(&self) -> Result { - self.db.get_connection().map_err(|e| { - ErrorBuilder::new(WorkspaceErrorCode::DatabaseConnectionFail) - .msg(e) - .build() - }) - } } diff --git a/rust-lib/flowy-workspace/src/sql_tables/app/app.rs b/rust-lib/flowy-workspace/src/sql_tables/app/app.rs index b455c8fb03..1354fad323 100644 --- a/rust-lib/flowy-workspace/src/sql_tables/app/app.rs +++ b/rust-lib/flowy-workspace/src/sql_tables/app/app.rs @@ -1,10 +1,10 @@ use crate::{ - entities::app::{ColorStyle, CreateAppParams, UpdateAppParams}, + entities::app::{AppDetail, ColorStyle, CreateAppParams, UpdateAppParams}, impl_sql_binary_expression, sql_tables::workspace::Workspace, }; use diesel::sql_types::Binary; -use flowy_database::schema::{app_table, app_table::dsl}; +use flowy_database::schema::app_table; use flowy_infra::{timestamp, uuid}; use serde::{Deserialize, Serialize, __private::TryFrom}; use std::convert::TryInto; @@ -104,3 +104,14 @@ impl AppChangeset { } } } + +impl std::convert::Into for App { + fn into(self) -> AppDetail { + AppDetail { + id: self.id, + workspace_id: self.workspace_id, + name: self.name, + desc: self.desc, + } + } +} diff --git a/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace.rs b/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace.rs index a208fd6dd3..5ec20f2c20 100644 --- a/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace.rs +++ b/rust-lib/flowy-workspace/src/sql_tables/workspace/workspace.rs @@ -1,8 +1,5 @@ -use crate::{ - entities::workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceDetail}, - sql_tables::app::App, -}; -use flowy_database::schema::{workspace_table, workspace_table::dsl}; +use crate::entities::workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceDetail}; +use flowy_database::schema::workspace_table; use flowy_infra::{timestamp, uuid}; use serde::{Deserialize, Serialize}; diff --git a/rust-lib/flowy-workspace/tests/event/app_test.rs b/rust-lib/flowy-workspace/tests/event/app_test.rs new file mode 100644 index 0000000000..8a00950875 --- /dev/null +++ b/rust-lib/flowy-workspace/tests/event/app_test.rs @@ -0,0 +1,15 @@ +// #[test] +// fn app_create_success() { +// let request = CreateAppRequest { +// workspace_id: "".to_string(), +// name: "123".to_owned(), +// desc: "".to_owned(), +// color_style: Default::default(), +// }; +// +// let response = WorkspaceEventTester::new(CreateWorkspace) +// .request(request) +// .sync_send() +// .parse::(); +// dbg!(&response); +// } diff --git a/rust-lib/flowy-workspace/tests/event/helper.rs b/rust-lib/flowy-workspace/tests/event/helper.rs index 2aa50ccba6..584b8e1f55 100644 --- a/rust-lib/flowy-workspace/tests/event/helper.rs +++ b/rust-lib/flowy-workspace/tests/event/helper.rs @@ -2,3 +2,10 @@ use flowy_test::EventTester; use flowy_workspace::errors::WorkspaceError; pub type WorkspaceEventTester = EventTester; + +pub(crate) fn invalid_workspace_name_test_case() -> Vec { + vec!["", "1234".repeat(100).as_str()] + .iter() + .map(|s| s.to_string()) + .collect::>() +} diff --git a/rust-lib/flowy-workspace/tests/event/main.rs b/rust-lib/flowy-workspace/tests/event/main.rs index 190cfd57f1..bb71ee613f 100644 --- a/rust-lib/flowy-workspace/tests/event/main.rs +++ b/rust-lib/flowy-workspace/tests/event/main.rs @@ -1,2 +1,3 @@ +mod app_test; mod helper; mod workspace_test; diff --git a/rust-lib/flowy-workspace/tests/event/workspace_test.rs b/rust-lib/flowy-workspace/tests/event/workspace_test.rs index 44183b642e..de13ad0aac 100644 --- a/rust-lib/flowy-workspace/tests/event/workspace_test.rs +++ b/rust-lib/flowy-workspace/tests/event/workspace_test.rs @@ -1,4 +1,4 @@ -use crate::helper::WorkspaceEventTester; +use crate::helper::*; use flowy_workspace::{ entities::workspace::{CreateWorkspaceRequest, WorkspaceDetail}, event::WorkspaceEvent::*, @@ -6,10 +6,9 @@ use flowy_workspace::{ }; #[test] -#[should_panic] -fn workspace_create_test() { +fn workspace_create_success() { let request = CreateWorkspaceRequest { - name: "".to_owned(), + name: "123".to_owned(), desc: "".to_owned(), }; @@ -19,3 +18,41 @@ fn workspace_create_test() { .parse::(); dbg!(&response); } + +#[test] +fn workspace_create_with_invalid_name_test() { + for name in invalid_workspace_name_test_case() { + let request = CreateWorkspaceRequest { + name, + desc: "".to_owned(), + }; + + assert_eq!( + WorkspaceEventTester::new(CreateWorkspace) + .request(request) + .sync_send() + .error() + .code, + WorkspaceErrorCode::WorkspaceNameInvalid + ) + } +} + +// #[test] +// fn workspace_update_with_invalid_name_test() { +// for name in invalid_workspace_name_test_case() { +// let request = CreateWorkspaceRequest { +// name, +// desc: "".to_owned(), +// }; +// +// assert_eq!( +// WorkspaceEventTester::new(CreateWorkspace) +// .request(request) +// .sync_send() +// .error() +// .code, +// WorkspaceErrorCode::WorkspaceNameInvalid +// ) +// } +// }