mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
config user mock server, integrate with backend
This commit is contained in:
parent
139a21d98a
commit
bda12233a1
@ -131,3 +131,78 @@ class SignInParams extends $pb.GeneratedMessage {
|
||||
void clearPassword() => clearField(2);
|
||||
}
|
||||
|
||||
class SignInResponse extends $pb.GeneratedMessage {
|
||||
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'SignInResponse', createEmptyInstance: create)
|
||||
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'uid')
|
||||
..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name')
|
||||
..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'email')
|
||||
..hasRequiredFields = false
|
||||
;
|
||||
|
||||
SignInResponse._() : super();
|
||||
factory SignInResponse({
|
||||
$core.String? uid,
|
||||
$core.String? name,
|
||||
$core.String? email,
|
||||
}) {
|
||||
final _result = create();
|
||||
if (uid != null) {
|
||||
_result.uid = uid;
|
||||
}
|
||||
if (name != null) {
|
||||
_result.name = name;
|
||||
}
|
||||
if (email != null) {
|
||||
_result.email = email;
|
||||
}
|
||||
return _result;
|
||||
}
|
||||
factory SignInResponse.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
|
||||
factory SignInResponse.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')
|
||||
SignInResponse clone() => SignInResponse()..mergeFromMessage(this);
|
||||
@$core.Deprecated(
|
||||
'Using this can add significant overhead to your binary. '
|
||||
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
|
||||
'Will be removed in next major version')
|
||||
SignInResponse copyWith(void Function(SignInResponse) updates) => super.copyWith((message) => updates(message as SignInResponse)) as SignInResponse; // ignore: deprecated_member_use
|
||||
$pb.BuilderInfo get info_ => _i;
|
||||
@$core.pragma('dart2js:noInline')
|
||||
static SignInResponse create() => SignInResponse._();
|
||||
SignInResponse createEmptyInstance() => create();
|
||||
static $pb.PbList<SignInResponse> createRepeated() => $pb.PbList<SignInResponse>();
|
||||
@$core.pragma('dart2js:noInline')
|
||||
static SignInResponse getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<SignInResponse>(create);
|
||||
static SignInResponse? _defaultInstance;
|
||||
|
||||
@$pb.TagNumber(1)
|
||||
$core.String get uid => $_getSZ(0);
|
||||
@$pb.TagNumber(1)
|
||||
set uid($core.String v) { $_setString(0, v); }
|
||||
@$pb.TagNumber(1)
|
||||
$core.bool hasUid() => $_has(0);
|
||||
@$pb.TagNumber(1)
|
||||
void clearUid() => 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);
|
||||
}
|
||||
|
||||
|
@ -30,3 +30,15 @@ const SignInParams$json = const {
|
||||
|
||||
/// Descriptor for `SignInParams`. Decode as a `google.protobuf.DescriptorProto`.
|
||||
final $typed_data.Uint8List signInParamsDescriptor = $convert.base64Decode('CgxTaWduSW5QYXJhbXMSFAoFZW1haWwYASABKAlSBWVtYWlsEhoKCHBhc3N3b3JkGAIgASgJUghwYXNzd29yZA==');
|
||||
@$core.Deprecated('Use signInResponseDescriptor instead')
|
||||
const SignInResponse$json = const {
|
||||
'1': 'SignInResponse',
|
||||
'2': const [
|
||||
const {'1': 'uid', '3': 1, '4': 1, '5': 9, '10': 'uid'},
|
||||
const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'},
|
||||
const {'1': 'email', '3': 3, '4': 1, '5': 9, '10': 'email'},
|
||||
],
|
||||
};
|
||||
|
||||
/// Descriptor for `SignInResponse`. Decode as a `google.protobuf.DescriptorProto`.
|
||||
final $typed_data.Uint8List signInResponseDescriptor = $convert.base64Decode('Cg5TaWduSW5SZXNwb25zZRIQCgN1aWQYASABKAlSA3VpZBISCgRuYW1lGAIgASgJUgRuYW1lEhQKBWVtYWlsGAMgASgJUgVlbWFpbA==');
|
||||
|
@ -161,17 +161,22 @@ class SignUpParams extends $pb.GeneratedMessage {
|
||||
|
||||
class SignUpResponse extends $pb.GeneratedMessage {
|
||||
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'SignUpResponse', createEmptyInstance: create)
|
||||
..aOB(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name')
|
||||
..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'email')
|
||||
..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'uid')
|
||||
..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name')
|
||||
..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'email')
|
||||
..hasRequiredFields = false
|
||||
;
|
||||
|
||||
SignUpResponse._() : super();
|
||||
factory SignUpResponse({
|
||||
$core.bool? name,
|
||||
$core.String? uid,
|
||||
$core.String? name,
|
||||
$core.String? email,
|
||||
}) {
|
||||
final _result = create();
|
||||
if (uid != null) {
|
||||
_result.uid = uid;
|
||||
}
|
||||
if (name != null) {
|
||||
_result.name = name;
|
||||
}
|
||||
@ -202,21 +207,30 @@ class SignUpResponse extends $pb.GeneratedMessage {
|
||||
static SignUpResponse? _defaultInstance;
|
||||
|
||||
@$pb.TagNumber(1)
|
||||
$core.bool get name => $_getBF(0);
|
||||
$core.String get uid => $_getSZ(0);
|
||||
@$pb.TagNumber(1)
|
||||
set name($core.bool v) { $_setBool(0, v); }
|
||||
set uid($core.String v) { $_setString(0, v); }
|
||||
@$pb.TagNumber(1)
|
||||
$core.bool hasName() => $_has(0);
|
||||
$core.bool hasUid() => $_has(0);
|
||||
@$pb.TagNumber(1)
|
||||
void clearName() => clearField(1);
|
||||
void clearUid() => clearField(1);
|
||||
|
||||
@$pb.TagNumber(2)
|
||||
$core.String get email => $_getSZ(1);
|
||||
$core.String get name => $_getSZ(1);
|
||||
@$pb.TagNumber(2)
|
||||
set email($core.String v) { $_setString(1, v); }
|
||||
set name($core.String v) { $_setString(1, v); }
|
||||
@$pb.TagNumber(2)
|
||||
$core.bool hasEmail() => $_has(1);
|
||||
$core.bool hasName() => $_has(1);
|
||||
@$pb.TagNumber(2)
|
||||
void clearEmail() => clearField(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);
|
||||
}
|
||||
|
||||
|
@ -36,10 +36,11 @@ final $typed_data.Uint8List signUpParamsDescriptor = $convert.base64Decode('CgxT
|
||||
const SignUpResponse$json = const {
|
||||
'1': 'SignUpResponse',
|
||||
'2': const [
|
||||
const {'1': 'name', '3': 1, '4': 1, '5': 8, '10': 'name'},
|
||||
const {'1': 'email', '3': 2, '4': 1, '5': 9, '10': 'email'},
|
||||
const {'1': 'uid', '3': 1, '4': 1, '5': 9, '10': 'uid'},
|
||||
const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'},
|
||||
const {'1': 'email', '3': 3, '4': 1, '5': 9, '10': 'email'},
|
||||
],
|
||||
};
|
||||
|
||||
/// Descriptor for `SignUpResponse`. Decode as a `google.protobuf.DescriptorProto`.
|
||||
final $typed_data.Uint8List signUpResponseDescriptor = $convert.base64Decode('Cg5TaWduVXBSZXNwb25zZRISCgRuYW1lGAEgASgIUgRuYW1lEhQKBWVtYWlsGAIgASgJUgVlbWFpbA==');
|
||||
final $typed_data.Uint8List signUpResponseDescriptor = $convert.base64Decode('Cg5TaWduVXBSZXNwb25zZRIQCgN1aWQYASABKAlSA3VpZBISCgRuYW1lGAIgASgJUgRuYW1lEhQKBWVtYWlsGAMgASgJUgVlbWFpbA==');
|
||||
|
@ -1,2 +1,4 @@
|
||||
|
||||
mod model;
|
||||
pub use model::*;
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Auto-generated, do not edit
|
||||
// Auto-generated, do not edit
|
||||
|
||||
mod ffi_response;
|
||||
pub use ffi_response::*;
|
||||
mod ffi_response;
|
||||
pub use ffi_response::*;
|
||||
|
||||
mod ffi_request;
|
||||
pub use ffi_request::*;
|
||||
mod ffi_request;
|
||||
pub use ffi_request::*;
|
||||
|
@ -54,7 +54,9 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {
|
||||
| "SignUpResponse"
|
||||
| "SignInRequest"
|
||||
| "SignInParams"
|
||||
| "UserError" => TypeCategory::Protobuf,
|
||||
| "SignInResponse"
|
||||
| "UserError"
|
||||
=> TypeCategory::Protobuf,
|
||||
"ViewType"
|
||||
| "WorkspaceEvent"
|
||||
| "WsErrCode"
|
||||
@ -64,7 +66,8 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {
|
||||
| "FFIStatusCode"
|
||||
| "UserStatus"
|
||||
| "UserEvent"
|
||||
| "UserErrCode" => TypeCategory::Enum,
|
||||
| "UserErrCode"
|
||||
=> TypeCategory::Enum,
|
||||
|
||||
"Option" => TypeCategory::Opt,
|
||||
_ => TypeCategory::Primitive,
|
||||
|
@ -1,2 +1,4 @@
|
||||
|
||||
mod model;
|
||||
pub use model::*;
|
||||
|
@ -1,16 +1,16 @@
|
||||
// Auto-generated, do not edit
|
||||
// Auto-generated, do not edit
|
||||
|
||||
mod doc_modify;
|
||||
pub use doc_modify::*;
|
||||
mod doc_modify;
|
||||
pub use doc_modify::*;
|
||||
|
||||
mod doc_create;
|
||||
pub use doc_create::*;
|
||||
mod doc_create;
|
||||
pub use doc_create::*;
|
||||
|
||||
mod errors;
|
||||
pub use errors::*;
|
||||
mod errors;
|
||||
pub use errors::*;
|
||||
|
||||
mod event;
|
||||
pub use event::*;
|
||||
mod event;
|
||||
pub use event::*;
|
||||
|
||||
mod doc_query;
|
||||
pub use doc_query::*;
|
||||
mod doc_query;
|
||||
pub use doc_query::*;
|
||||
|
@ -1,2 +1,4 @@
|
||||
|
||||
mod model;
|
||||
pub use model::*;
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Auto-generated, do not edit
|
||||
// Auto-generated, do not edit
|
||||
|
||||
mod kv;
|
||||
pub use kv::*;
|
||||
mod kv;
|
||||
pub use kv::*;
|
||||
|
@ -12,6 +12,8 @@ serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
serde_repr = "0.1"
|
||||
actix-web = {version = "3", optional = true}
|
||||
pin-project = "1.0.0"
|
||||
futures-core = { version = "0.3", default-features = false }
|
||||
|
||||
[features]
|
||||
http = ["actix-web"]
|
61
rust-lib/flowy-net/src/future.rs
Normal file
61
rust-lib/flowy-net/src/future.rs
Normal file
@ -0,0 +1,61 @@
|
||||
use futures_core::ready;
|
||||
use pin_project::pin_project;
|
||||
use std::{
|
||||
fmt::Debug,
|
||||
future::Future,
|
||||
pin::Pin,
|
||||
task::{Context, Poll},
|
||||
};
|
||||
|
||||
#[pin_project]
|
||||
pub struct RequestFuture<T> {
|
||||
#[pin]
|
||||
pub fut: Pin<Box<dyn Future<Output = T> + Sync + Send>>,
|
||||
}
|
||||
|
||||
impl<T> Future for RequestFuture<T>
|
||||
where
|
||||
T: Send + Sync,
|
||||
{
|
||||
type Output = T;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let this = self.as_mut().project();
|
||||
loop {
|
||||
return Poll::Ready(ready!(this.fut.poll(cx)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[pin_project]
|
||||
pub struct ResultFuture<T, E> {
|
||||
#[pin]
|
||||
pub fut: Pin<Box<dyn Future<Output = Result<T, E>> + Sync + Send>>,
|
||||
}
|
||||
|
||||
impl<T, E> ResultFuture<T, E> {
|
||||
pub fn new<F>(f: F) -> Self
|
||||
where
|
||||
F: Future<Output = Result<T, E>> + Send + Sync + 'static,
|
||||
{
|
||||
Self {
|
||||
fut: Box::pin(async { f.await }),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, E> Future for ResultFuture<T, E>
|
||||
where
|
||||
T: Send + Sync,
|
||||
E: Debug,
|
||||
{
|
||||
type Output = Result<T, E>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
let this = self.as_mut().project();
|
||||
loop {
|
||||
let result = ready!(this.fut.poll(cx));
|
||||
return Poll::Ready(result);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,2 +1,4 @@
|
||||
pub mod errors;
|
||||
pub mod future;
|
||||
|
||||
pub mod response;
|
||||
|
@ -1,4 +1,3 @@
|
||||
use crate::errors::ServerError;
|
||||
use serde::Serialize;
|
||||
|
||||
use serde_repr::*;
|
||||
|
@ -1,2 +1,4 @@
|
||||
|
||||
mod model;
|
||||
pub use model::*;
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Auto-generated, do not edit
|
||||
// Auto-generated, do not edit
|
||||
|
||||
mod subject;
|
||||
pub use subject::*;
|
||||
mod subject;
|
||||
pub use subject::*;
|
||||
|
@ -1,5 +1,7 @@
|
||||
mod editor_deps_impl;
|
||||
mod user_deps_impl;
|
||||
mod workspace_deps_impl;
|
||||
|
||||
pub use editor_deps_impl::*;
|
||||
pub use user_deps_impl::*;
|
||||
pub use workspace_deps_impl::*;
|
||||
|
54
rust-lib/flowy-sdk/src/deps_resolve/user_deps_impl.rs
Normal file
54
rust-lib/flowy-sdk/src/deps_resolve/user_deps_impl.rs
Normal file
@ -0,0 +1,54 @@
|
||||
use flowy_dispatch::prelude::{
|
||||
DispatchError,
|
||||
DispatchFuture,
|
||||
EventDispatch,
|
||||
ModuleRequest,
|
||||
ToBytes,
|
||||
};
|
||||
use flowy_user::{
|
||||
errors::{ErrorBuilder, UserErrCode, UserError},
|
||||
prelude::WorkspaceAction,
|
||||
};
|
||||
use flowy_workspace::{
|
||||
entities::workspace::{CreateWorkspaceRequest, Workspace},
|
||||
event::WorkspaceEvent::CreateWorkspace,
|
||||
};
|
||||
|
||||
pub struct UserWorkspaceActionImpl {}
|
||||
impl WorkspaceAction for UserWorkspaceActionImpl {
|
||||
fn create_workspace(
|
||||
&self,
|
||||
name: &str,
|
||||
desc: &str,
|
||||
_user_id: &str,
|
||||
) -> DispatchFuture<Result<String, UserError>> {
|
||||
log::info!("Create user workspace: {:?}", name);
|
||||
let payload: Vec<u8> = CreateWorkspaceRequest {
|
||||
name: name.to_string(),
|
||||
desc: desc.to_string(),
|
||||
}
|
||||
.into_bytes()
|
||||
.unwrap();
|
||||
|
||||
let request = ModuleRequest::new(CreateWorkspace).payload(payload);
|
||||
DispatchFuture {
|
||||
fut: Box::pin(async move {
|
||||
let result = EventDispatch::async_send(request)
|
||||
.await
|
||||
.parse::<Workspace, DispatchError>()
|
||||
.map_err(|e| {
|
||||
ErrorBuilder::new(UserErrCode::CreateDefaultWorkspaceFailed)
|
||||
.error(e)
|
||||
.build()
|
||||
})?;
|
||||
|
||||
let workspace = result.map_err(|e| {
|
||||
ErrorBuilder::new(UserErrCode::CreateDefaultWorkspaceFailed)
|
||||
.error(e)
|
||||
.build()
|
||||
})?;
|
||||
Ok(workspace.id)
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
@ -8,7 +8,7 @@ use flowy_dispatch::prelude::{
|
||||
use flowy_user::{
|
||||
entities::{SignInParams, SignUpParams, UserDetail},
|
||||
errors::{ErrorBuilder, UserErrCode, UserError},
|
||||
prelude::UserServer,
|
||||
prelude::UserWorkspaceAction,
|
||||
sql_tables::UserTable,
|
||||
};
|
||||
use flowy_workspace::{
|
||||
@ -18,41 +18,13 @@ use flowy_workspace::{
|
||||
|
||||
pub type ArcFlowyServer = std::sync::Arc<dyn FlowyServer>;
|
||||
|
||||
pub trait FlowyServer: UserServer {}
|
||||
pub trait FlowyServer: UserWorkspaceAction {}
|
||||
|
||||
pub struct FlowyServerMocker {}
|
||||
|
||||
impl FlowyServer for FlowyServerMocker {}
|
||||
|
||||
impl UserServer for FlowyServerMocker {
|
||||
fn sign_up(&self, params: SignUpParams) -> Result<UserTable, UserError> {
|
||||
let user_id = params.email.clone();
|
||||
Ok(UserTable::new(
|
||||
user_id,
|
||||
params.name,
|
||||
params.email,
|
||||
params.password,
|
||||
))
|
||||
}
|
||||
|
||||
fn sign_in(&self, params: SignInParams) -> Result<UserTable, UserError> {
|
||||
let user_id = params.email.clone();
|
||||
Ok(UserTable::new(
|
||||
user_id,
|
||||
"".to_owned(),
|
||||
params.email,
|
||||
params.password,
|
||||
))
|
||||
}
|
||||
|
||||
fn sign_out(&self, _user_id: &str) -> Result<(), UserError> {
|
||||
Err(ErrorBuilder::new(UserErrCode::Unknown).build())
|
||||
}
|
||||
|
||||
fn get_user_info(&self, _user_id: &str) -> Result<UserDetail, UserError> {
|
||||
Err(ErrorBuilder::new(UserErrCode::Unknown).build())
|
||||
}
|
||||
|
||||
impl UserWorkspaceAction for FlowyServerMocker {
|
||||
fn create_workspace(
|
||||
&self,
|
||||
name: &str,
|
||||
|
@ -1,34 +1,27 @@
|
||||
mod deps_resolve;
|
||||
mod flowy_server;
|
||||
// mod flowy_server;
|
||||
pub mod module;
|
||||
|
||||
pub use crate::flowy_server::{ArcFlowyServer, FlowyServerMocker};
|
||||
use flowy_dispatch::prelude::*;
|
||||
use module::build_modules;
|
||||
pub use module::*;
|
||||
use std::sync::{
|
||||
atomic::{AtomicBool, Ordering},
|
||||
Arc,
|
||||
};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
|
||||
static INIT_LOG: AtomicBool = AtomicBool::new(false);
|
||||
pub struct FlowySDK {
|
||||
root: String,
|
||||
server: ArcFlowyServer,
|
||||
}
|
||||
|
||||
impl FlowySDK {
|
||||
pub fn new(root: &str) -> Self {
|
||||
let server = Arc::new(FlowyServerMocker {});
|
||||
Self {
|
||||
root: root.to_owned(),
|
||||
server,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn construct(self) { FlowySDK::construct_with(&self.root, self.server.clone()) }
|
||||
pub fn construct(self) { FlowySDK::construct_with(&self.root) }
|
||||
|
||||
pub fn construct_with(root: &str, server: ArcFlowyServer) {
|
||||
pub fn construct_with(root: &str) {
|
||||
FlowySDK::init_log(root);
|
||||
|
||||
tracing::info!("🔥 Root path: {}", root);
|
||||
@ -36,7 +29,7 @@ impl FlowySDK {
|
||||
Ok(_) => {},
|
||||
Err(e) => tracing::error!("Init kv store failedL: {}", e),
|
||||
}
|
||||
FlowySDK::init_modules(root, server);
|
||||
FlowySDK::init_modules(root);
|
||||
}
|
||||
|
||||
fn init_log(directory: &str) {
|
||||
@ -45,15 +38,15 @@ impl FlowySDK {
|
||||
|
||||
let _ = flowy_log::Builder::new("flowy")
|
||||
.local(directory)
|
||||
.env_filter("Debug")
|
||||
.env_filter("info")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
fn init_modules(root: &str, server: ArcFlowyServer) {
|
||||
fn init_modules(root: &str) {
|
||||
let config = ModuleConfig {
|
||||
root: root.to_owned(),
|
||||
};
|
||||
EventDispatch::construct(|| build_modules(config, server));
|
||||
EventDispatch::construct(|| build_modules(config));
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,10 @@
|
||||
use crate::flowy_server::{ArcFlowyServer, FlowyServerMocker};
|
||||
use flowy_dispatch::prelude::Module;
|
||||
|
||||
use flowy_user::prelude::*;
|
||||
|
||||
use crate::deps_resolve::{
|
||||
EditorDatabaseImpl,
|
||||
EditorUserImpl,
|
||||
UserWorkspaceActionImpl,
|
||||
WorkspaceDatabaseImpl,
|
||||
WorkspaceUserImpl,
|
||||
};
|
||||
@ -15,11 +14,11 @@ pub struct ModuleConfig {
|
||||
pub root: String,
|
||||
}
|
||||
|
||||
pub fn build_modules(config: ModuleConfig, _server: ArcFlowyServer) -> Vec<Module> {
|
||||
pub fn build_modules(config: ModuleConfig) -> Vec<Module> {
|
||||
let user_session = Arc::new(
|
||||
UserSessionBuilder::new()
|
||||
.root_dir(&config.root)
|
||||
.build(Arc::new(FlowyServerMocker {})),
|
||||
.build(Arc::new(UserWorkspaceActionImpl {})),
|
||||
);
|
||||
|
||||
let workspace_user_impl = Arc::new(WorkspaceUserImpl {
|
||||
|
@ -3,7 +3,7 @@ mod helper;
|
||||
mod tester;
|
||||
|
||||
use crate::helper::root_dir;
|
||||
use flowy_sdk::{ArcFlowyServer, FlowySDK};
|
||||
use flowy_sdk::FlowySDK;
|
||||
use std::sync::Once;
|
||||
|
||||
pub mod prelude {
|
||||
@ -15,10 +15,10 @@ pub mod prelude {
|
||||
}
|
||||
|
||||
static INIT: Once = Once::new();
|
||||
pub fn init_test_sdk(server: ArcFlowyServer) {
|
||||
pub fn init_test_sdk() {
|
||||
let root_dir = root_dir();
|
||||
|
||||
INIT.call_once(|| {
|
||||
FlowySDK::construct_with(&root_dir, server);
|
||||
FlowySDK::construct_with(&root_dir);
|
||||
});
|
||||
}
|
||||
|
@ -13,14 +13,12 @@ use std::{
|
||||
convert::TryFrom,
|
||||
fmt::{Debug, Display},
|
||||
hash::Hash,
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
pub struct TesterContext {
|
||||
request: Option<ModuleRequest>,
|
||||
response: Option<EventResponse>,
|
||||
status_code: StatusCode,
|
||||
server: ArcFlowyServer,
|
||||
user_email: String,
|
||||
}
|
||||
|
||||
@ -38,7 +36,6 @@ impl std::default::Default for TesterContext {
|
||||
request: None,
|
||||
status_code: StatusCode::Ok,
|
||||
response: None,
|
||||
server: Arc::new(FlowyServerMocker {}),
|
||||
user_email: random_valid_email(),
|
||||
}
|
||||
}
|
||||
@ -59,7 +56,7 @@ pub trait TesterTrait {
|
||||
where
|
||||
E: Eq + Hash + Debug + Clone + Display,
|
||||
{
|
||||
init_test_sdk(self.context().server.clone());
|
||||
init_test_sdk();
|
||||
self.mut_context().request = Some(ModuleRequest::new(event));
|
||||
}
|
||||
|
||||
@ -99,7 +96,7 @@ pub trait TesterTrait {
|
||||
}
|
||||
|
||||
fn login(&self) -> UserDetail {
|
||||
init_test_sdk(self.context().server.clone());
|
||||
init_test_sdk();
|
||||
let payload = SignInRequest {
|
||||
email: self.context().user_email.clone(),
|
||||
password: valid_password(),
|
||||
@ -117,7 +114,7 @@ pub trait TesterTrait {
|
||||
}
|
||||
|
||||
fn login_if_need(&self) -> UserDetail {
|
||||
init_test_sdk(self.context().server.clone());
|
||||
init_test_sdk();
|
||||
match EventDispatch::sync_send(ModuleRequest::new(GetStatus))
|
||||
.parse::<UserDetail, UserError>()
|
||||
.unwrap()
|
||||
@ -128,7 +125,7 @@ pub trait TesterTrait {
|
||||
}
|
||||
|
||||
fn logout(&self) {
|
||||
init_test_sdk(self.context().server.clone());
|
||||
init_test_sdk();
|
||||
let _ = EventDispatch::sync_send(ModuleRequest::new(SignOut));
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ flowy-derive = { path = "../flowy-derive" }
|
||||
flowy-database = { path = "../flowy-database" }
|
||||
flowy-sqlite = { path = "../flowy-sqlite" }
|
||||
flowy-infra = { path = "../flowy-infra" }
|
||||
flowy-net = { path = "../flowy-net" }
|
||||
|
||||
tracing = { version = "0.1", features = ["log"] }
|
||||
bytes = "1.0"
|
||||
@ -40,4 +41,7 @@ claim = "0.4.0"
|
||||
flowy-test = { path = "../flowy-test" }
|
||||
tokio = { version = "1", features = ["full"] }
|
||||
futures = "0.3.15"
|
||||
serial_test = "0.5.1"
|
||||
serial_test = "0.5.1"
|
||||
|
||||
[features]
|
||||
http_server = []
|
@ -20,6 +20,18 @@ pub struct SignInParams {
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[derive(Default, ProtoBuf)]
|
||||
pub struct SignInResponse {
|
||||
#[pb(index = 1)]
|
||||
pub uid: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub name: String,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub email: String,
|
||||
}
|
||||
|
||||
impl TryInto<SignInParams> for SignInRequest {
|
||||
type Error = UserError;
|
||||
|
||||
|
@ -57,8 +57,11 @@ pub struct SignUpParams {
|
||||
#[derive(ProtoBuf, Debug, Default)]
|
||||
pub struct SignUpResponse {
|
||||
#[pb(index = 1)]
|
||||
pub name: bool,
|
||||
pub uid: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
pub name: String,
|
||||
|
||||
#[pb(index = 3)]
|
||||
pub email: String,
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{entities::*, errors::UserError, services::user_session::UserSession};
|
||||
use crate::{entities::*, errors::UserError, services::user::UserSession};
|
||||
use flowy_dispatch::prelude::*;
|
||||
use std::{convert::TryInto, sync::Arc};
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{entities::*, errors::UserError, services::user_session::UserSession};
|
||||
use crate::{entities::*, errors::UserError, services::user::UserSession};
|
||||
use flowy_dispatch::prelude::*;
|
||||
use std::{convert::TryInto, sync::Arc};
|
||||
|
||||
|
@ -11,5 +11,9 @@ pub mod sql_tables;
|
||||
extern crate flowy_database;
|
||||
|
||||
pub mod prelude {
|
||||
pub use crate::{entities::*, handlers::*, services::user_session::*};
|
||||
pub use crate::{
|
||||
entities::*,
|
||||
handlers::*,
|
||||
services::{user::*, workspace::*},
|
||||
};
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
use flowy_dispatch::prelude::*;
|
||||
|
||||
use crate::{event::UserEvent, handlers::*, services::user_session::UserSession};
|
||||
use crate::{event::UserEvent, handlers::*, services::user::UserSession};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub fn create(user_session: Arc<UserSession>) -> Module {
|
||||
|
@ -1,2 +1,4 @@
|
||||
|
||||
mod model;
|
||||
pub use model::*;
|
||||
|
@ -1,22 +1,22 @@
|
||||
// Auto-generated, do not edit
|
||||
// Auto-generated, do not edit
|
||||
|
||||
mod sign_up;
|
||||
pub use sign_up::*;
|
||||
mod sign_up;
|
||||
pub use sign_up::*;
|
||||
|
||||
mod sign_in;
|
||||
pub use sign_in::*;
|
||||
mod sign_in;
|
||||
pub use sign_in::*;
|
||||
|
||||
mod user_table;
|
||||
pub use user_table::*;
|
||||
mod user_table;
|
||||
pub use user_table::*;
|
||||
|
||||
mod errors;
|
||||
pub use errors::*;
|
||||
mod errors;
|
||||
pub use errors::*;
|
||||
|
||||
mod user_detail;
|
||||
pub use user_detail::*;
|
||||
mod user_detail;
|
||||
pub use user_detail::*;
|
||||
|
||||
mod user_update;
|
||||
pub use user_update::*;
|
||||
mod user_update;
|
||||
pub use user_update::*;
|
||||
|
||||
mod event;
|
||||
pub use event::*;
|
||||
mod event;
|
||||
pub use event::*;
|
||||
|
@ -425,25 +425,280 @@ impl ::protobuf::reflect::ProtobufValue for SignInParams {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq,Clone,Default)]
|
||||
pub struct SignInResponse {
|
||||
// message fields
|
||||
pub uid: ::std::string::String,
|
||||
pub name: ::std::string::String,
|
||||
pub email: ::std::string::String,
|
||||
// special fields
|
||||
pub unknown_fields: ::protobuf::UnknownFields,
|
||||
pub cached_size: ::protobuf::CachedSize,
|
||||
}
|
||||
|
||||
impl<'a> ::std::default::Default for &'a SignInResponse {
|
||||
fn default() -> &'a SignInResponse {
|
||||
<SignInResponse as ::protobuf::Message>::default_instance()
|
||||
}
|
||||
}
|
||||
|
||||
impl SignInResponse {
|
||||
pub fn new() -> SignInResponse {
|
||||
::std::default::Default::default()
|
||||
}
|
||||
|
||||
// string uid = 1;
|
||||
|
||||
|
||||
pub fn get_uid(&self) -> &str {
|
||||
&self.uid
|
||||
}
|
||||
pub fn clear_uid(&mut self) {
|
||||
self.uid.clear();
|
||||
}
|
||||
|
||||
// Param is passed by value, moved
|
||||
pub fn set_uid(&mut self, v: ::std::string::String) {
|
||||
self.uid = v;
|
||||
}
|
||||
|
||||
// Mutable pointer to the field.
|
||||
// If field is not initialized, it is initialized with default value first.
|
||||
pub fn mut_uid(&mut self) -> &mut ::std::string::String {
|
||||
&mut self.uid
|
||||
}
|
||||
|
||||
// Take field
|
||||
pub fn take_uid(&mut self) -> ::std::string::String {
|
||||
::std::mem::replace(&mut self.uid, ::std::string::String::new())
|
||||
}
|
||||
|
||||
// string name = 2;
|
||||
|
||||
|
||||
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 email = 3;
|
||||
|
||||
|
||||
pub fn get_email(&self) -> &str {
|
||||
&self.email
|
||||
}
|
||||
pub fn clear_email(&mut self) {
|
||||
self.email.clear();
|
||||
}
|
||||
|
||||
// Param is passed by value, moved
|
||||
pub fn set_email(&mut self, v: ::std::string::String) {
|
||||
self.email = v;
|
||||
}
|
||||
|
||||
// Mutable pointer to the field.
|
||||
// If field is not initialized, it is initialized with default value first.
|
||||
pub fn mut_email(&mut self) -> &mut ::std::string::String {
|
||||
&mut self.email
|
||||
}
|
||||
|
||||
// Take field
|
||||
pub fn take_email(&mut self) -> ::std::string::String {
|
||||
::std::mem::replace(&mut self.email, ::std::string::String::new())
|
||||
}
|
||||
}
|
||||
|
||||
impl ::protobuf::Message for SignInResponse {
|
||||
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.uid)?;
|
||||
},
|
||||
2 => {
|
||||
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.name)?;
|
||||
},
|
||||
3 => {
|
||||
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.email)?;
|
||||
},
|
||||
_ => {
|
||||
::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.uid.is_empty() {
|
||||
my_size += ::protobuf::rt::string_size(1, &self.uid);
|
||||
}
|
||||
if !self.name.is_empty() {
|
||||
my_size += ::protobuf::rt::string_size(2, &self.name);
|
||||
}
|
||||
if !self.email.is_empty() {
|
||||
my_size += ::protobuf::rt::string_size(3, &self.email);
|
||||
}
|
||||
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.uid.is_empty() {
|
||||
os.write_string(1, &self.uid)?;
|
||||
}
|
||||
if !self.name.is_empty() {
|
||||
os.write_string(2, &self.name)?;
|
||||
}
|
||||
if !self.email.is_empty() {
|
||||
os.write_string(3, &self.email)?;
|
||||
}
|
||||
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<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
|
||||
self
|
||||
}
|
||||
|
||||
fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
|
||||
Self::descriptor_static()
|
||||
}
|
||||
|
||||
fn new() -> SignInResponse {
|
||||
SignInResponse::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>(
|
||||
"uid",
|
||||
|m: &SignInResponse| { &m.uid },
|
||||
|m: &mut SignInResponse| { &mut m.uid },
|
||||
));
|
||||
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
|
||||
"name",
|
||||
|m: &SignInResponse| { &m.name },
|
||||
|m: &mut SignInResponse| { &mut m.name },
|
||||
));
|
||||
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
|
||||
"email",
|
||||
|m: &SignInResponse| { &m.email },
|
||||
|m: &mut SignInResponse| { &mut m.email },
|
||||
));
|
||||
::protobuf::reflect::MessageDescriptor::new_pb_name::<SignInResponse>(
|
||||
"SignInResponse",
|
||||
fields,
|
||||
file_descriptor_proto()
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
fn default_instance() -> &'static SignInResponse {
|
||||
static instance: ::protobuf::rt::LazyV2<SignInResponse> = ::protobuf::rt::LazyV2::INIT;
|
||||
instance.get(SignInResponse::new)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::protobuf::Clear for SignInResponse {
|
||||
fn clear(&mut self) {
|
||||
self.uid.clear();
|
||||
self.name.clear();
|
||||
self.email.clear();
|
||||
self.unknown_fields.clear();
|
||||
}
|
||||
}
|
||||
|
||||
impl ::std::fmt::Debug for SignInResponse {
|
||||
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
|
||||
::protobuf::text_format::fmt(self, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl ::protobuf::reflect::ProtobufValue for SignInResponse {
|
||||
fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef {
|
||||
::protobuf::reflect::ReflectValueRef::Message(self)
|
||||
}
|
||||
}
|
||||
|
||||
static file_descriptor_proto_data: &'static [u8] = b"\
|
||||
\n\rsign_in.proto\"A\n\rSignInRequest\x12\x14\n\x05email\x18\x01\x20\x01\
|
||||
(\tR\x05email\x12\x1a\n\x08password\x18\x02\x20\x01(\tR\x08password\"@\n\
|
||||
\x0cSignInParams\x12\x14\n\x05email\x18\x01\x20\x01(\tR\x05email\x12\x1a\
|
||||
\n\x08password\x18\x02\x20\x01(\tR\x08passwordJ\x9e\x02\n\x06\x12\x04\0\
|
||||
\0\t\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\x15\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\x18\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\x13\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04\x16\x17\n\
|
||||
\n\n\x02\x04\x01\x12\x04\x06\0\t\x01\n\n\n\x03\x04\x01\x01\x12\x03\x06\
|
||||
\x08\x14\n\x0b\n\x04\x04\x01\x02\0\x12\x03\x07\x04\x15\n\x0c\n\x05\x04\
|
||||
\x01\x02\0\x05\x12\x03\x07\x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\
|
||||
\x07\x0b\x10\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\x07\x13\x14\n\x0b\n\
|
||||
\x04\x04\x01\x02\x01\x12\x03\x08\x04\x18\n\x0c\n\x05\x04\x01\x02\x01\x05\
|
||||
\x12\x03\x08\x04\n\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\x08\x0b\x13\n\
|
||||
\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\x08\x16\x17b\x06proto3\
|
||||
\n\x08password\x18\x02\x20\x01(\tR\x08password\"L\n\x0eSignInResponse\
|
||||
\x12\x10\n\x03uid\x18\x01\x20\x01(\tR\x03uid\x12\x12\n\x04name\x18\x02\
|
||||
\x20\x01(\tR\x04name\x12\x14\n\x05email\x18\x03\x20\x01(\tR\x05emailJ\
|
||||
\xdb\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\x15\
|
||||
\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\x18\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\x13\n\x0c\n\x05\x04\0\x02\x01\x03\
|
||||
\x12\x03\x04\x16\x17\n\n\n\x02\x04\x01\x12\x04\x06\0\t\x01\n\n\n\x03\x04\
|
||||
\x01\x01\x12\x03\x06\x08\x14\n\x0b\n\x04\x04\x01\x02\0\x12\x03\x07\x04\
|
||||
\x15\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\x07\x04\n\n\x0c\n\x05\x04\x01\
|
||||
\x02\0\x01\x12\x03\x07\x0b\x10\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\x07\
|
||||
\x13\x14\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\x08\x04\x18\n\x0c\n\x05\x04\
|
||||
\x01\x02\x01\x05\x12\x03\x08\x04\n\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\
|
||||
\x03\x08\x0b\x13\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\x08\x16\x17\n\n\
|
||||
\n\x02\x04\x02\x12\x04\n\0\x0e\x01\n\n\n\x03\x04\x02\x01\x12\x03\n\x08\
|
||||
\x16\n\x0b\n\x04\x04\x02\x02\0\x12\x03\x0b\x04\x13\n\x0c\n\x05\x04\x02\
|
||||
\x02\0\x05\x12\x03\x0b\x04\n\n\x0c\n\x05\x04\x02\x02\0\x01\x12\x03\x0b\
|
||||
\x0b\x0e\n\x0c\n\x05\x04\x02\x02\0\x03\x12\x03\x0b\x11\x12\n\x0b\n\x04\
|
||||
\x04\x02\x02\x01\x12\x03\x0c\x04\x14\n\x0c\n\x05\x04\x02\x02\x01\x05\x12\
|
||||
\x03\x0c\x04\n\n\x0c\n\x05\x04\x02\x02\x01\x01\x12\x03\x0c\x0b\x0f\n\x0c\
|
||||
\n\x05\x04\x02\x02\x01\x03\x12\x03\x0c\x12\x13\n\x0b\n\x04\x04\x02\x02\
|
||||
\x02\x12\x03\r\x04\x15\n\x0c\n\x05\x04\x02\x02\x02\x05\x12\x03\r\x04\n\n\
|
||||
\x0c\n\x05\x04\x02\x02\x02\x01\x12\x03\r\x0b\x10\n\x0c\n\x05\x04\x02\x02\
|
||||
\x02\x03\x12\x03\r\x13\x14b\x06proto3\
|
||||
";
|
||||
|
||||
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;
|
||||
|
@ -512,7 +512,8 @@ impl ::protobuf::reflect::ProtobufValue for SignUpParams {
|
||||
#[derive(PartialEq,Clone,Default)]
|
||||
pub struct SignUpResponse {
|
||||
// message fields
|
||||
pub name: bool,
|
||||
pub uid: ::std::string::String,
|
||||
pub name: ::std::string::String,
|
||||
pub email: ::std::string::String,
|
||||
// special fields
|
||||
pub unknown_fields: ::protobuf::UnknownFields,
|
||||
@ -530,22 +531,59 @@ impl SignUpResponse {
|
||||
::std::default::Default::default()
|
||||
}
|
||||
|
||||
// bool name = 1;
|
||||
// string uid = 1;
|
||||
|
||||
|
||||
pub fn get_name(&self) -> bool {
|
||||
self.name
|
||||
pub fn get_uid(&self) -> &str {
|
||||
&self.uid
|
||||
}
|
||||
pub fn clear_name(&mut self) {
|
||||
self.name = false;
|
||||
pub fn clear_uid(&mut self) {
|
||||
self.uid.clear();
|
||||
}
|
||||
|
||||
// Param is passed by value, moved
|
||||
pub fn set_name(&mut self, v: bool) {
|
||||
pub fn set_uid(&mut self, v: ::std::string::String) {
|
||||
self.uid = v;
|
||||
}
|
||||
|
||||
// Mutable pointer to the field.
|
||||
// If field is not initialized, it is initialized with default value first.
|
||||
pub fn mut_uid(&mut self) -> &mut ::std::string::String {
|
||||
&mut self.uid
|
||||
}
|
||||
|
||||
// Take field
|
||||
pub fn take_uid(&mut self) -> ::std::string::String {
|
||||
::std::mem::replace(&mut self.uid, ::std::string::String::new())
|
||||
}
|
||||
|
||||
// string name = 2;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
// string email = 2;
|
||||
// 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 email = 3;
|
||||
|
||||
|
||||
pub fn get_email(&self) -> &str {
|
||||
@ -582,13 +620,12 @@ impl ::protobuf::Message for SignUpResponse {
|
||||
let (field_number, wire_type) = is.read_tag_unpack()?;
|
||||
match field_number {
|
||||
1 => {
|
||||
if wire_type != ::protobuf::wire_format::WireTypeVarint {
|
||||
return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));
|
||||
}
|
||||
let tmp = is.read_bool()?;
|
||||
self.name = tmp;
|
||||
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.uid)?;
|
||||
},
|
||||
2 => {
|
||||
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.name)?;
|
||||
},
|
||||
3 => {
|
||||
::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.email)?;
|
||||
},
|
||||
_ => {
|
||||
@ -603,11 +640,14 @@ impl ::protobuf::Message for SignUpResponse {
|
||||
#[allow(unused_variables)]
|
||||
fn compute_size(&self) -> u32 {
|
||||
let mut my_size = 0;
|
||||
if self.name != false {
|
||||
my_size += 2;
|
||||
if !self.uid.is_empty() {
|
||||
my_size += ::protobuf::rt::string_size(1, &self.uid);
|
||||
}
|
||||
if !self.name.is_empty() {
|
||||
my_size += ::protobuf::rt::string_size(2, &self.name);
|
||||
}
|
||||
if !self.email.is_empty() {
|
||||
my_size += ::protobuf::rt::string_size(2, &self.email);
|
||||
my_size += ::protobuf::rt::string_size(3, &self.email);
|
||||
}
|
||||
my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
|
||||
self.cached_size.set(my_size);
|
||||
@ -615,11 +655,14 @@ impl ::protobuf::Message for SignUpResponse {
|
||||
}
|
||||
|
||||
fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> {
|
||||
if self.name != false {
|
||||
os.write_bool(1, self.name)?;
|
||||
if !self.uid.is_empty() {
|
||||
os.write_string(1, &self.uid)?;
|
||||
}
|
||||
if !self.name.is_empty() {
|
||||
os.write_string(2, &self.name)?;
|
||||
}
|
||||
if !self.email.is_empty() {
|
||||
os.write_string(2, &self.email)?;
|
||||
os.write_string(3, &self.email)?;
|
||||
}
|
||||
os.write_unknown_fields(self.get_unknown_fields())?;
|
||||
::std::result::Result::Ok(())
|
||||
@ -659,7 +702,12 @@ impl ::protobuf::Message for SignUpResponse {
|
||||
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::ProtobufTypeBool>(
|
||||
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
|
||||
"uid",
|
||||
|m: &SignUpResponse| { &m.uid },
|
||||
|m: &mut SignUpResponse| { &mut m.uid },
|
||||
));
|
||||
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
|
||||
"name",
|
||||
|m: &SignUpResponse| { &m.name },
|
||||
|m: &mut SignUpResponse| { &mut m.name },
|
||||
@ -685,7 +733,8 @@ impl ::protobuf::Message for SignUpResponse {
|
||||
|
||||
impl ::protobuf::Clear for SignUpResponse {
|
||||
fn clear(&mut self) {
|
||||
self.name = false;
|
||||
self.uid.clear();
|
||||
self.name.clear();
|
||||
self.email.clear();
|
||||
self.unknown_fields.clear();
|
||||
}
|
||||
@ -709,34 +758,38 @@ static file_descriptor_proto_data: &'static [u8] = b"\
|
||||
\x08password\x18\x03\x20\x01(\tR\x08password\"T\n\x0cSignUpParams\x12\
|
||||
\x14\n\x05email\x18\x01\x20\x01(\tR\x05email\x12\x12\n\x04name\x18\x02\
|
||||
\x20\x01(\tR\x04name\x12\x1a\n\x08password\x18\x03\x20\x01(\tR\x08passwo\
|
||||
rd\":\n\x0eSignUpResponse\x12\x12\n\x04name\x18\x01\x20\x01(\x08R\x04nam\
|
||||
e\x12\x14\n\x05email\x18\x02\x20\x01(\tR\x05emailJ\x92\x04\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\x06\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x15\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\x18\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\
|
||||
\x13\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x16\x17\n\n\n\x02\x04\x01\
|
||||
\x12\x04\x07\0\x0b\x01\n\n\n\x03\x04\x01\x01\x12\x03\x07\x08\x14\n\x0b\n\
|
||||
\x04\x04\x01\x02\0\x12\x03\x08\x04\x15\n\x0c\n\x05\x04\x01\x02\0\x05\x12\
|
||||
\x03\x08\x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\x08\x0b\x10\n\x0c\n\
|
||||
\x05\x04\x01\x02\0\x03\x12\x03\x08\x13\x14\n\x0b\n\x04\x04\x01\x02\x01\
|
||||
\x12\x03\t\x04\x14\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\t\x04\n\n\x0c\
|
||||
\n\x05\x04\x01\x02\x01\x01\x12\x03\t\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x01\
|
||||
\x03\x12\x03\t\x12\x13\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\n\x04\x18\n\
|
||||
\x0c\n\x05\x04\x01\x02\x02\x05\x12\x03\n\x04\n\n\x0c\n\x05\x04\x01\x02\
|
||||
\x02\x01\x12\x03\n\x0b\x13\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\n\x16\
|
||||
\x17\n\n\n\x02\x04\x02\x12\x04\x0c\0\x0f\x01\n\n\n\x03\x04\x02\x01\x12\
|
||||
\x03\x0c\x08\x16\n\x0b\n\x04\x04\x02\x02\0\x12\x03\r\x04\x12\n\x0c\n\x05\
|
||||
\x04\x02\x02\0\x05\x12\x03\r\x04\x08\n\x0c\n\x05\x04\x02\x02\0\x01\x12\
|
||||
\x03\r\t\r\n\x0c\n\x05\x04\x02\x02\0\x03\x12\x03\r\x10\x11\n\x0b\n\x04\
|
||||
\x04\x02\x02\x01\x12\x03\x0e\x04\x15\n\x0c\n\x05\x04\x02\x02\x01\x05\x12\
|
||||
\x03\x0e\x04\n\n\x0c\n\x05\x04\x02\x02\x01\x01\x12\x03\x0e\x0b\x10\n\x0c\
|
||||
\n\x05\x04\x02\x02\x01\x03\x12\x03\x0e\x13\x14b\x06proto3\
|
||||
rd\"L\n\x0eSignUpResponse\x12\x10\n\x03uid\x18\x01\x20\x01(\tR\x03uid\
|
||||
\x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\x14\n\x05email\x18\
|
||||
\x03\x20\x01(\tR\x05emailJ\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\x06\x01\n\n\n\x03\x04\
|
||||
\0\x01\x12\x03\x02\x08\x15\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\x18\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\x13\n\x0c\n\x05\x04\0\x02\
|
||||
\x02\x03\x12\x03\x05\x16\x17\n\n\n\x02\x04\x01\x12\x04\x07\0\x0b\x01\n\n\
|
||||
\n\x03\x04\x01\x01\x12\x03\x07\x08\x14\n\x0b\n\x04\x04\x01\x02\0\x12\x03\
|
||||
\x08\x04\x15\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\x08\x04\n\n\x0c\n\x05\
|
||||
\x04\x01\x02\0\x01\x12\x03\x08\x0b\x10\n\x0c\n\x05\x04\x01\x02\0\x03\x12\
|
||||
\x03\x08\x13\x14\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\t\x04\x14\n\x0c\n\
|
||||
\x05\x04\x01\x02\x01\x05\x12\x03\t\x04\n\n\x0c\n\x05\x04\x01\x02\x01\x01\
|
||||
\x12\x03\t\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\t\x12\x13\n\
|
||||
\x0b\n\x04\x04\x01\x02\x02\x12\x03\n\x04\x18\n\x0c\n\x05\x04\x01\x02\x02\
|
||||
\x05\x12\x03\n\x04\n\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\n\x0b\x13\n\
|
||||
\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\n\x16\x17\n\n\n\x02\x04\x02\x12\
|
||||
\x04\x0c\0\x10\x01\n\n\n\x03\x04\x02\x01\x12\x03\x0c\x08\x16\n\x0b\n\x04\
|
||||
\x04\x02\x02\0\x12\x03\r\x04\x13\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03\r\
|
||||
\x04\n\n\x0c\n\x05\x04\x02\x02\0\x01\x12\x03\r\x0b\x0e\n\x0c\n\x05\x04\
|
||||
\x02\x02\0\x03\x12\x03\r\x11\x12\n\x0b\n\x04\x04\x02\x02\x01\x12\x03\x0e\
|
||||
\x04\x14\n\x0c\n\x05\x04\x02\x02\x01\x05\x12\x03\x0e\x04\n\n\x0c\n\x05\
|
||||
\x04\x02\x02\x01\x01\x12\x03\x0e\x0b\x0f\n\x0c\n\x05\x04\x02\x02\x01\x03\
|
||||
\x12\x03\x0e\x12\x13\n\x0b\n\x04\x04\x02\x02\x02\x12\x03\x0f\x04\x15\n\
|
||||
\x0c\n\x05\x04\x02\x02\x02\x05\x12\x03\x0f\x04\n\n\x0c\n\x05\x04\x02\x02\
|
||||
\x02\x01\x12\x03\x0f\x0b\x10\n\x0c\n\x05\x04\x02\x02\x02\x03\x12\x03\x0f\
|
||||
\x13\x14b\x06proto3\
|
||||
";
|
||||
|
||||
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;
|
||||
|
@ -8,3 +8,8 @@ message SignInParams {
|
||||
string email = 1;
|
||||
string password = 2;
|
||||
}
|
||||
message SignInResponse {
|
||||
string uid = 1;
|
||||
string name = 2;
|
||||
string email = 3;
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ message SignUpParams {
|
||||
string password = 3;
|
||||
}
|
||||
message SignUpResponse {
|
||||
bool name = 1;
|
||||
string email = 2;
|
||||
string uid = 1;
|
||||
string name = 2;
|
||||
string email = 3;
|
||||
}
|
||||
|
@ -1 +1,2 @@
|
||||
pub mod user_session;
|
||||
pub mod user;
|
||||
pub mod workspace;
|
||||
|
@ -1,4 +1,7 @@
|
||||
use crate::services::user_session::{user_server::UserServer, UserSession, UserSessionConfig};
|
||||
use crate::services::{
|
||||
user::{UserSession, UserSessionConfig},
|
||||
workspace::WorkspaceAction,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
pub struct UserSessionBuilder {
|
||||
@ -13,12 +16,12 @@ impl UserSessionBuilder {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build<S>(mut self, server: Arc<S>) -> UserSession
|
||||
pub fn build<S>(mut self, workspace: Arc<S>) -> UserSession
|
||||
where
|
||||
S: 'static + UserServer + Send + Sync,
|
||||
S: 'static + WorkspaceAction + Send + Sync,
|
||||
{
|
||||
let config = self.config.take().unwrap();
|
||||
|
||||
UserSession::new(config, server)
|
||||
UserSession::new(config, workspace)
|
||||
}
|
||||
}
|
91
rust-lib/flowy-user/src/services/user/user_server.rs
Normal file
91
rust-lib/flowy-user/src/services/user/user_server.rs
Normal file
@ -0,0 +1,91 @@
|
||||
use crate::{
|
||||
entities::{SignInParams, SignInResponse, SignUpParams, SignUpResponse, UserDetail},
|
||||
errors::{ErrorBuilder, UserErrCode, UserError},
|
||||
};
|
||||
|
||||
use flowy_infra::uuid;
|
||||
use flowy_net::future::ResultFuture;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub(crate) trait UserServer {
|
||||
fn sign_up(&self, params: SignUpParams) -> ResultFuture<SignUpResponse, UserError>;
|
||||
fn sign_in(&self, params: SignInParams) -> ResultFuture<SignInResponse, UserError>;
|
||||
fn sign_out(&self, user_id: &str) -> ResultFuture<(), UserError>;
|
||||
fn get_user_info(&self, user_id: &str) -> ResultFuture<UserDetail, UserError>;
|
||||
}
|
||||
|
||||
pub(crate) fn construct_server() -> Arc<dyn UserServer + Send + Sync> {
|
||||
if cfg!(feature = "http_server") {
|
||||
Arc::new(UserServerImpl {})
|
||||
} else {
|
||||
Arc::new(UserServerMock {})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UserServerImpl {}
|
||||
impl UserServerImpl {}
|
||||
|
||||
impl UserServer for UserServerImpl {
|
||||
fn sign_up(&self, _params: SignUpParams) -> ResultFuture<SignUpResponse, UserError> {
|
||||
ResultFuture::new(async {
|
||||
Ok(SignUpResponse {
|
||||
uid: "".to_string(),
|
||||
name: "".to_string(),
|
||||
email: "".to_string(),
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn sign_in(&self, _params: SignInParams) -> ResultFuture<SignInResponse, UserError> {
|
||||
// let user_id = params.email.clone();
|
||||
// Ok(UserTable::new(
|
||||
// user_id,
|
||||
// "".to_owned(),
|
||||
// params.email,
|
||||
// params.password,
|
||||
// ))
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn sign_out(&self, _user_id: &str) -> ResultFuture<(), UserError> {
|
||||
ResultFuture::new(async { Err(ErrorBuilder::new(UserErrCode::Unknown).build()) })
|
||||
}
|
||||
|
||||
fn get_user_info(&self, _user_id: &str) -> ResultFuture<UserDetail, UserError> {
|
||||
ResultFuture::new(async { Err(ErrorBuilder::new(UserErrCode::Unknown).build()) })
|
||||
}
|
||||
}
|
||||
|
||||
pub struct UserServerMock {}
|
||||
|
||||
impl UserServer for UserServerMock {
|
||||
fn sign_up(&self, params: SignUpParams) -> ResultFuture<SignUpResponse, UserError> {
|
||||
let uid = params.email.clone();
|
||||
ResultFuture::new(async {
|
||||
Ok(SignUpResponse {
|
||||
uid,
|
||||
name: params.name,
|
||||
email: params.email,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn sign_in(&self, params: SignInParams) -> ResultFuture<SignInResponse, UserError> {
|
||||
let uid = params.email.clone();
|
||||
ResultFuture::new(async {
|
||||
Ok(SignInResponse {
|
||||
uid,
|
||||
name: params.email.clone(),
|
||||
email: params.email,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn sign_out(&self, _user_id: &str) -> ResultFuture<(), UserError> {
|
||||
ResultFuture::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
fn get_user_info(&self, _user_id: &str) -> ResultFuture<UserDetail, UserError> {
|
||||
ResultFuture::new(async { Err(ErrorBuilder::new(UserErrCode::Unknown).build()) })
|
||||
}
|
||||
}
|
@ -1,3 +1,13 @@
|
||||
use crate::{
|
||||
entities::{SignInParams, SignUpParams, UpdateUserParams, UpdateUserRequest, UserDetail},
|
||||
errors::{ErrorBuilder, UserErrCode, UserError},
|
||||
event::UserEvent::*,
|
||||
services::{
|
||||
user::{construct_server, database::UserDB, UserServer},
|
||||
workspace::WorkspaceAction,
|
||||
},
|
||||
sql_tables::{UserTable, UserTableChangeset},
|
||||
};
|
||||
use flowy_database::{
|
||||
query_dsl::*,
|
||||
schema::{user_table, user_table::dsl},
|
||||
@ -5,18 +15,9 @@ use flowy_database::{
|
||||
ExpressionMethods,
|
||||
UserDatabaseConnection,
|
||||
};
|
||||
use flowy_infra::kv::KVStore;
|
||||
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
use crate::{
|
||||
entities::{SignInParams, SignUpParams, UpdateUserParams, UpdateUserRequest, UserDetail},
|
||||
errors::{ErrorBuilder, UserErrCode, UserError},
|
||||
event::UserEvent::*,
|
||||
services::user_session::{database::UserDB, user_server::UserServer},
|
||||
sql_tables::{UserTable, UserTableChangeset},
|
||||
};
|
||||
use flowy_dispatch::prelude::{EventDispatch, ModuleRequest, ToBytes};
|
||||
use flowy_infra::kv::KVStore;
|
||||
use std::sync::{Arc, RwLock};
|
||||
|
||||
const DEFAULT_WORKSPACE_NAME: &'static str = "My workspace";
|
||||
const DEFAULT_WORKSPACE_DESC: &'static str = "This is your first workspace";
|
||||
@ -37,19 +38,22 @@ impl UserSessionConfig {
|
||||
pub struct UserSession {
|
||||
database: UserDB,
|
||||
config: UserSessionConfig,
|
||||
workspace: Arc<dyn WorkspaceAction + Send + Sync>,
|
||||
server: Arc<dyn UserServer + Send + Sync>,
|
||||
user_id: RwLock<Option<String>>,
|
||||
}
|
||||
|
||||
impl UserSession {
|
||||
pub fn new<R>(config: UserSessionConfig, server: Arc<R>) -> Self
|
||||
pub fn new<R>(config: UserSessionConfig, workspace: Arc<R>) -> Self
|
||||
where
|
||||
R: 'static + UserServer + Send + Sync,
|
||||
R: 'static + WorkspaceAction + Send + Sync,
|
||||
{
|
||||
let db = UserDB::new(&config.root_dir);
|
||||
let server = construct_server();
|
||||
Self {
|
||||
database: db,
|
||||
config,
|
||||
workspace,
|
||||
server,
|
||||
user_id: RwLock::new(None),
|
||||
}
|
||||
@ -61,17 +65,17 @@ impl UserSession {
|
||||
}
|
||||
|
||||
pub async fn sign_in(&self, params: SignInParams) -> Result<UserTable, UserError> {
|
||||
let user = self.server.sign_in(params)?;
|
||||
let _ = self.set_user_id(Some(user.id.clone()))?;
|
||||
let user_table = self.save_user(user).await?;
|
||||
let resp = self.server.sign_in(params).await?;
|
||||
let _ = self.set_user_id(Some(resp.uid.clone()))?;
|
||||
let user_table = self.save_user(resp.into()).await?;
|
||||
|
||||
Ok(user_table)
|
||||
}
|
||||
|
||||
pub async fn sign_up(&self, params: SignUpParams) -> Result<UserTable, UserError> {
|
||||
let user = self.server.sign_up(params)?;
|
||||
let _ = self.set_user_id(Some(user.id.clone()))?;
|
||||
let user_table = self.save_user(user).await?;
|
||||
let resp = self.server.sign_up(params).await?;
|
||||
let _ = self.set_user_id(Some(resp.uid.clone()))?;
|
||||
let user_table = self.save_user(resp.into()).await?;
|
||||
|
||||
Ok(user_table)
|
||||
}
|
||||
@ -80,11 +84,7 @@ impl UserSession {
|
||||
let user_id = self.get_user_id()?;
|
||||
let conn = self.get_db_connection()?;
|
||||
let _ = diesel::delete(dsl::user_table.filter(dsl::id.eq(&user_id))).execute(&*conn)?;
|
||||
|
||||
match self.server.sign_out(&user_id) {
|
||||
Ok(_) => {},
|
||||
Err(_) => {},
|
||||
}
|
||||
let _ = self.server.sign_out(&user_id);
|
||||
let _ = self.database.close_user_db(&user_id)?;
|
||||
let _ = self.set_user_id(None)?;
|
||||
|
||||
@ -120,14 +120,7 @@ impl UserSession {
|
||||
.filter(user_table::id.eq(&user_id))
|
||||
.first::<UserTable>(&*(self.get_db_connection()?))?;
|
||||
|
||||
match self.server.get_user_info(&user_id) {
|
||||
Ok(_user_detail) => {
|
||||
// TODO: post latest user_detail to upper layer
|
||||
},
|
||||
Err(_e) => {
|
||||
// log::debug!("Get user details failed. {:?}", e);
|
||||
},
|
||||
}
|
||||
let _ = self.server.get_user_info(&user_id);
|
||||
|
||||
Ok(UserDetail::from(user))
|
||||
}
|
||||
@ -196,7 +189,7 @@ impl UserSession {
|
||||
KVStore::set_bool(&key, true);
|
||||
log::debug!("Create user:{} default workspace", user_id);
|
||||
let workspace_id = self
|
||||
.server
|
||||
.workspace
|
||||
.create_workspace(DEFAULT_WORKSPACE_NAME, DEFAULT_WORKSPACE_DESC, user_id)
|
||||
.await?;
|
||||
Ok(workspace_id)
|
@ -1,23 +0,0 @@
|
||||
use crate::{
|
||||
entities::{SignInParams, SignUpParams, UserDetail},
|
||||
errors::UserError,
|
||||
sql_tables::UserTable,
|
||||
};
|
||||
use flowy_dispatch::prelude::DispatchFuture;
|
||||
|
||||
pub trait UserServer {
|
||||
fn sign_up(&self, params: SignUpParams) -> Result<UserTable, UserError>;
|
||||
|
||||
fn sign_in(&self, params: SignInParams) -> Result<UserTable, UserError>;
|
||||
|
||||
fn sign_out(&self, user_id: &str) -> Result<(), UserError>;
|
||||
|
||||
fn get_user_info(&self, user_id: &str) -> Result<UserDetail, UserError>;
|
||||
|
||||
fn create_workspace(
|
||||
&self,
|
||||
name: &str,
|
||||
desc: &str,
|
||||
user_id: &str,
|
||||
) -> DispatchFuture<Result<String, UserError>>;
|
||||
}
|
11
rust-lib/flowy-user/src/services/workspace/action.rs
Normal file
11
rust-lib/flowy-user/src/services/workspace/action.rs
Normal file
@ -0,0 +1,11 @@
|
||||
use crate::errors::UserError;
|
||||
use flowy_dispatch::prelude::DispatchFuture;
|
||||
|
||||
pub trait WorkspaceAction {
|
||||
fn create_workspace(
|
||||
&self,
|
||||
name: &str,
|
||||
desc: &str,
|
||||
user_id: &str,
|
||||
) -> DispatchFuture<Result<String, UserError>>;
|
||||
}
|
3
rust-lib/flowy-user/src/services/workspace/mod.rs
Normal file
3
rust-lib/flowy-user/src/services/workspace/mod.rs
Normal file
@ -0,0 +1,3 @@
|
||||
mod action;
|
||||
|
||||
pub use action::*;
|
@ -1,4 +1,4 @@
|
||||
use crate::entities::UpdateUserParams;
|
||||
use crate::entities::{SignInResponse, SignUpResponse, UpdateUserParams};
|
||||
use flowy_database::schema::user_table;
|
||||
|
||||
#[derive(Clone, Default, Queryable, Identifiable, Insertable)]
|
||||
@ -28,6 +28,18 @@ impl UserTable {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<SignUpResponse> for UserTable {
|
||||
fn from(resp: SignUpResponse) -> Self {
|
||||
UserTable::new(resp.uid, resp.name, resp.email, "".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<SignInResponse> for UserTable {
|
||||
fn from(resp: SignInResponse) -> Self {
|
||||
UserTable::new(resp.uid, resp.name, resp.email, "".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(AsChangeset, Identifiable, Default, Debug)]
|
||||
#[table_name = "user_table"]
|
||||
pub struct UserTableChangeset {
|
||||
|
@ -1,2 +1,4 @@
|
||||
|
||||
mod model;
|
||||
pub use model::*;
|
||||
|
@ -1,49 +1,49 @@
|
||||
// Auto-generated, do not edit
|
||||
// Auto-generated, do not edit
|
||||
|
||||
mod view_update;
|
||||
pub use view_update::*;
|
||||
mod view_update;
|
||||
pub use view_update::*;
|
||||
|
||||
mod view_delete;
|
||||
pub use view_delete::*;
|
||||
mod view_delete;
|
||||
pub use view_delete::*;
|
||||
|
||||
mod app_query;
|
||||
pub use app_query::*;
|
||||
mod app_query;
|
||||
pub use app_query::*;
|
||||
|
||||
mod workspace_delete;
|
||||
pub use workspace_delete::*;
|
||||
mod workspace_delete;
|
||||
pub use workspace_delete::*;
|
||||
|
||||
mod observable;
|
||||
pub use observable::*;
|
||||
mod observable;
|
||||
pub use observable::*;
|
||||
|
||||
mod errors;
|
||||
pub use errors::*;
|
||||
mod errors;
|
||||
pub use errors::*;
|
||||
|
||||
mod workspace_update;
|
||||
pub use workspace_update::*;
|
||||
mod workspace_update;
|
||||
pub use workspace_update::*;
|
||||
|
||||
mod app_create;
|
||||
pub use app_create::*;
|
||||
mod app_create;
|
||||
pub use app_create::*;
|
||||
|
||||
mod workspace_query;
|
||||
pub use workspace_query::*;
|
||||
mod workspace_query;
|
||||
pub use workspace_query::*;
|
||||
|
||||
mod event;
|
||||
pub use event::*;
|
||||
mod event;
|
||||
pub use event::*;
|
||||
|
||||
mod view_create;
|
||||
pub use view_create::*;
|
||||
mod view_create;
|
||||
pub use view_create::*;
|
||||
|
||||
mod workspace_user_detail;
|
||||
pub use workspace_user_detail::*;
|
||||
mod workspace_user_detail;
|
||||
pub use workspace_user_detail::*;
|
||||
|
||||
mod workspace_create;
|
||||
pub use workspace_create::*;
|
||||
mod workspace_create;
|
||||
pub use workspace_create::*;
|
||||
|
||||
mod app_update;
|
||||
pub use app_update::*;
|
||||
mod app_update;
|
||||
pub use app_update::*;
|
||||
|
||||
mod view_query;
|
||||
pub use view_query::*;
|
||||
mod view_query;
|
||||
pub use view_query::*;
|
||||
|
||||
mod app_delete;
|
||||
pub use app_delete::*;
|
||||
mod app_delete;
|
||||
pub use app_delete::*;
|
||||
|
Loading…
Reference in New Issue
Block a user