add create workspace test

This commit is contained in:
appflowy 2021-07-14 08:07:25 +08:00
parent df1d84d43d
commit 0e26706176
28 changed files with 625 additions and 35 deletions

View File

@ -20,6 +20,7 @@
<sourceFolder url="file://$MODULE_DIR$/rust-lib/flowy-sqlite/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/rust-lib/flowy-sqlite/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/rust-lib/flowy-infra/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/rust-lib/flowy-infra/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/rust-lib/flowy-workspace/src" isTestSource="false" /> <sourceFolder url="file://$MODULE_DIR$/rust-lib/flowy-workspace/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/rust-lib/flowy-workspace/tests" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/app_flowy/packages/af_protobuf/.pub" /> <excludeFolder url="file://$MODULE_DIR$/app_flowy/packages/af_protobuf/.pub" />
<excludeFolder url="file://$MODULE_DIR$/app_flowy/packages/af_protobuf/.dart_tool" /> <excludeFolder url="file://$MODULE_DIR$/app_flowy/packages/af_protobuf/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/app_flowy/packages/af_protobuf/build" /> <excludeFolder url="file://$MODULE_DIR$/app_flowy/packages/af_protobuf/build" />

View File

@ -0,0 +1,11 @@
///
// Generated code. Do not modify.
// source: event.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;
export 'event.pbenum.dart';

View File

@ -0,0 +1,24 @@
///
// Generated code. Do not modify.
// source: event.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
// ignore_for_file: UNDEFINED_SHOWN_NAME
import 'dart:core' as $core;
import 'package:protobuf/protobuf.dart' as $pb;
class WorkspaceEvent extends $pb.ProtobufEnum {
static const WorkspaceEvent CreateWorkspace = WorkspaceEvent._(0, const $core.bool.fromEnvironment('protobuf.omit_enum_names') ? '' : 'CreateWorkspace');
static const $core.List<WorkspaceEvent> values = <WorkspaceEvent> [
CreateWorkspace,
];
static final $core.Map<$core.int, WorkspaceEvent> _byValue = $pb.ProtobufEnum.initByValue(values);
static WorkspaceEvent? valueOf($core.int value) => _byValue[value];
const WorkspaceEvent._($core.int v, $core.String n) : super(v, n);
}

View File

@ -0,0 +1,20 @@
///
// Generated code. Do not modify.
// source: event.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 workspaceEventDescriptor instead')
const WorkspaceEvent$json = const {
'1': 'WorkspaceEvent',
'2': const [
const {'1': 'CreateWorkspace', '2': 0},
],
};
/// Descriptor for `WorkspaceEvent`. Decode as a `google.protobuf.EnumDescriptorProto`.
final $typed_data.Uint8List workspaceEventDescriptor = $convert.base64Decode('Cg5Xb3Jrc3BhY2VFdmVudBITCg9DcmVhdGVXb3Jrc3BhY2UQAA==');

View File

@ -0,0 +1,9 @@
///
// Generated code. Do not modify.
// source: event.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 'event.pb.dart';

View File

@ -2,5 +2,6 @@
export './errors.pb.dart'; export './errors.pb.dart';
export './workspace_update.pb.dart'; export './workspace_update.pb.dart';
export './app_create.pb.dart'; export './app_create.pb.dart';
export './event.pb.dart';
export './workspace_create.pb.dart'; export './workspace_create.pb.dart';
export './app_update.pb.dart'; export './app_update.pb.dart';

View File

@ -70,3 +70,78 @@ class CreateWorkspaceRequest extends $pb.GeneratedMessage {
void clearDesc() => clearField(2); void clearDesc() => clearField(2);
} }
class WorkspaceDetail extends $pb.GeneratedMessage {
static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'WorkspaceDetail', createEmptyInstance: create)
..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') ? '' : 'desc')
..hasRequiredFields = false
;
WorkspaceDetail._() : super();
factory WorkspaceDetail({
$core.String? id,
$core.String? name,
$core.String? desc,
}) {
final _result = create();
if (id != null) {
_result.id = id;
}
if (name != null) {
_result.name = name;
}
if (desc != null) {
_result.desc = desc;
}
return _result;
}
factory WorkspaceDetail.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
factory WorkspaceDetail.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')
WorkspaceDetail clone() => WorkspaceDetail()..mergeFromMessage(this);
@$core.Deprecated(
'Using this can add significant overhead to your binary. '
'Use [GeneratedMessageGenericExtensions.rebuild] instead. '
'Will be removed in next major version')
WorkspaceDetail copyWith(void Function(WorkspaceDetail) updates) => super.copyWith((message) => updates(message as WorkspaceDetail)) as WorkspaceDetail; // ignore: deprecated_member_use
$pb.BuilderInfo get info_ => _i;
@$core.pragma('dart2js:noInline')
static WorkspaceDetail create() => WorkspaceDetail._();
WorkspaceDetail createEmptyInstance() => create();
static $pb.PbList<WorkspaceDetail> createRepeated() => $pb.PbList<WorkspaceDetail>();
@$core.pragma('dart2js:noInline')
static WorkspaceDetail getDefault() => _defaultInstance ??= $pb.GeneratedMessage.$_defaultFor<WorkspaceDetail>(create);
static WorkspaceDetail? _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 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 desc => $_getSZ(2);
@$pb.TagNumber(3)
set desc($core.String v) { $_setString(2, v); }
@$pb.TagNumber(3)
$core.bool hasDesc() => $_has(2);
@$pb.TagNumber(3)
void clearDesc() => clearField(3);
}

View File

@ -19,3 +19,15 @@ const CreateWorkspaceRequest$json = const {
/// Descriptor for `CreateWorkspaceRequest`. Decode as a `google.protobuf.DescriptorProto`. /// Descriptor for `CreateWorkspaceRequest`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List createWorkspaceRequestDescriptor = $convert.base64Decode('ChZDcmVhdGVXb3Jrc3BhY2VSZXF1ZXN0EhIKBG5hbWUYASABKAlSBG5hbWUSEgoEZGVzYxgCIAEoCVIEZGVzYw=='); final $typed_data.Uint8List createWorkspaceRequestDescriptor = $convert.base64Decode('ChZDcmVhdGVXb3Jrc3BhY2VSZXF1ZXN0EhIKBG5hbWUYASABKAlSBG5hbWUSEgoEZGVzYxgCIAEoCVIEZGVzYw==');
@$core.Deprecated('Use workspaceDetailDescriptor instead')
const WorkspaceDetail$json = const {
'1': 'WorkspaceDetail',
'2': const [
const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'},
const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'},
const {'1': 'desc', '3': 3, '4': 1, '5': 9, '10': 'desc'},
],
};
/// Descriptor for `WorkspaceDetail`. Decode as a `google.protobuf.DescriptorProto`.
final $typed_data.Uint8List workspaceDetailDescriptor = $convert.base64Decode('Cg9Xb3Jrc3BhY2VEZXRhaWwSDgoCaWQYASABKAlSAmlkEhIKBG5hbWUYAiABKAlSBG5hbWUSEgoEZGVzYxgDIAEoCVIEZGVzYw==');

View File

@ -39,6 +39,6 @@ where
io::Error::new(io::ErrorKind::NotConnected, msg) io::Error::new(io::ErrorKind::NotConnected, msg)
} }
pub trait UserDatabaseConnection { pub trait UserDatabaseConnection: Send + Sync {
fn get_connection(&self) -> Result<DBConnection, String>; fn get_connection(&self) -> Result<DBConnection, String>;
} }

View File

@ -21,6 +21,7 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {
| "UpdateAppRequest" | "UpdateAppRequest"
| "UpdateWorkspaceRequest" | "UpdateWorkspaceRequest"
| "CreateWorkspaceRequest" | "CreateWorkspaceRequest"
| "WorkspaceDetail"
| "WorkspaceError" | "WorkspaceError"
| "FFIRequest" | "FFIRequest"
| "FFIResponse" | "FFIResponse"
@ -32,7 +33,8 @@ pub fn category_from_str(type_str: &str) -> TypeCategory {
| "SignInParams" | "SignInParams"
| "UserError" | "UserError"
=> TypeCategory::Protobuf, => TypeCategory::Protobuf,
"WorkspaceErrorCode" "WorkspaceEvent"
| "WorkspaceErrorCode"
| "FFIStatusCode" | "FFIStatusCode"
| "UserStatus" | "UserStatus"
| "UserEvent" | "UserEvent"

View File

@ -4,10 +4,7 @@ use diesel::{Connection, SqliteConnection};
use flowy_derive::ProtoBuf; use flowy_derive::ProtoBuf;
use flowy_sqlite::{DBConnection, Database, PoolConfig}; use flowy_sqlite::{DBConnection, Database, PoolConfig};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use std::{ use std::{path::Path, sync::RwLock};
path::Path,
sync::{RwLock, RwLockWriteGuard},
};
const DB_NAME: &str = "kv.db"; const DB_NAME: &str = "kv.db";
lazy_static! { lazy_static! {

View File

@ -4,9 +4,6 @@ extern crate diesel;
#[macro_use] #[macro_use]
extern crate diesel_derives; extern crate diesel_derives;
#[macro_use]
extern crate diesel_migrations;
pub mod kv; pub mod kv;
mod protobuf; mod protobuf;

View File

@ -10,8 +10,10 @@ pub struct ModuleConfig {
pub fn build_modules(config: ModuleConfig) -> Vec<Module> { pub fn build_modules(config: ModuleConfig) -> Vec<Module> {
let user_session = Arc::new(UserSessionBuilder::new().root_dir(&config.root).build()); let user_session = Arc::new(UserSessionBuilder::new().root_dir(&config.root).build());
let controller = Arc::new(WorkspaceController::new(user_session.clone()));
let workspace_controller = WorkspaceController::new(user_session.clone()); vec![
flowy_user::module::create(user_session),
vec![flowy_user::module::create(user_session)] flowy_workspace::module::create(controller),
]
} }

View File

@ -1,19 +1,11 @@
use flowy_database::schema::user_table; use flowy_database::schema::user_table;
use flowy_derive::ProtoBuf;
#[derive(ProtoBuf, Clone, Default, Queryable, Identifiable, Insertable)] #[derive(Clone, Default, Queryable, Identifiable, Insertable)]
#[table_name = "user_table"] #[table_name = "user_table"]
pub struct User { pub struct User {
#[pb(index = 1)]
pub(crate) id: String, pub(crate) id: String,
#[pb(index = 2)]
pub(crate) name: String, pub(crate) name: String,
#[pb(index = 3)]
password: String, password: String,
#[pb(index = 4)]
pub(crate) email: String, pub(crate) email: String,
} }

View File

@ -20,4 +20,7 @@ diesel_derives = {version = "1.4.1", features = ["sqlite"]}
lazy_static = "1.4.0" lazy_static = "1.4.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
derive_more = {version = "0.99", features = ["display"]} derive_more = {version = "0.99", features = ["display"]}
bincode = { version = "1.3"} bincode = { version = "1.3"}
[dev-dependencies]
flowy-test = { path = "../flowy-test" }

View File

@ -5,10 +5,10 @@ use std::convert::TryInto;
#[derive(ProtoBuf, Default)] #[derive(ProtoBuf, Default)]
pub struct CreateWorkspaceRequest { pub struct CreateWorkspaceRequest {
#[pb(index = 1)] #[pb(index = 1)]
name: String, pub name: String,
#[pb(index = 2)] #[pb(index = 2)]
desc: String, pub desc: String,
} }
pub struct CreateWorkspaceParams { pub struct CreateWorkspaceParams {
@ -32,3 +32,15 @@ impl TryInto<CreateWorkspaceParams> for CreateWorkspaceRequest {
}) })
} }
} }
#[derive(ProtoBuf, Default, Debug)]
pub struct WorkspaceDetail {
#[pb(index = 1)]
pub id: String,
#[pb(index = 2)]
pub name: String,
#[pb(index = 3)]
pub desc: String,
}

View File

@ -0,0 +1,10 @@
use derive_more::Display;
use flowy_derive::{Flowy_Event, ProtoBuf_Enum};
#[derive(Clone, Copy, PartialEq, Eq, Debug, Display, Hash, ProtoBuf_Enum, Flowy_Event)]
#[event_err = "WorkspaceError"]
pub enum WorkspaceEvent {
#[display(fmt = "Create workspace")]
#[event(input = "CreateSpaceRequest", output = "WorkspaceDetail")]
CreateWorkspace = 0,
}

View File

@ -1 +1,16 @@
use crate::{
entities::workspace::{CreateWorkspaceParams, CreateWorkspaceRequest, WorkspaceDetail},
errors::WorkspaceError,
services::WorkspaceController,
};
use flowy_dispatch::prelude::{response_ok, Data, ModuleData, ResponseResult};
use std::{convert::TryInto, sync::Arc};
pub async fn create_workspace(
data: Data<CreateWorkspaceRequest>,
controller: ModuleData<Arc<WorkspaceController>>,
) -> ResponseResult<WorkspaceDetail, WorkspaceError> {
let params: CreateWorkspaceParams = data.into_inner().try_into()?;
let detail = controller.save_workspace(params)?;
response_ok(detail)
}

View File

@ -0,0 +1,11 @@
use flowy_dispatch::prelude::*;
use crate::{event::WorkspaceEvent, handlers::create_workspace, services::WorkspaceController};
use std::sync::Arc;
pub fn create(controller: Arc<WorkspaceController>) -> Module {
Module::new()
.name("Flowy-Workspace")
.data(controller)
.event(WorkspaceEvent::CreateWorkspace, create_workspace)
}

View File

@ -0,0 +1,92 @@
// 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 `event.proto`
/// Generated files are compatible only with the same version
/// of protobuf runtime.
// const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_22_1;
#[derive(Clone,PartialEq,Eq,Debug,Hash)]
pub enum WorkspaceEvent {
CreateWorkspace = 0,
}
impl ::protobuf::ProtobufEnum for WorkspaceEvent {
fn value(&self) -> i32 {
*self as i32
}
fn from_i32(value: i32) -> ::std::option::Option<WorkspaceEvent> {
match value {
0 => ::std::option::Option::Some(WorkspaceEvent::CreateWorkspace),
_ => ::std::option::Option::None
}
}
fn values() -> &'static [Self] {
static values: &'static [WorkspaceEvent] = &[
WorkspaceEvent::CreateWorkspace,
];
values
}
fn enum_descriptor_static() -> &'static ::protobuf::reflect::EnumDescriptor {
static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::EnumDescriptor> = ::protobuf::rt::LazyV2::INIT;
descriptor.get(|| {
::protobuf::reflect::EnumDescriptor::new_pb_name::<WorkspaceEvent>("WorkspaceEvent", file_descriptor_proto())
})
}
}
impl ::std::marker::Copy for WorkspaceEvent {
}
impl ::std::default::Default for WorkspaceEvent {
fn default() -> Self {
WorkspaceEvent::CreateWorkspace
}
}
impl ::protobuf::reflect::ProtobufValue for WorkspaceEvent {
fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef {
::protobuf::reflect::ReflectValueRef::Enum(::protobuf::ProtobufEnum::descriptor(self))
}
}
static file_descriptor_proto_data: &'static [u8] = b"\
\n\x0bevent.proto*%\n\x0eWorkspaceEvent\x12\x13\n\x0fCreateWorkspace\x10\
\0JS\n\x06\x12\x04\0\0\x04\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\
\x05\0\x12\x04\x02\0\x04\x01\n\n\n\x03\x05\0\x01\x12\x03\x02\x05\x13\n\
\x0b\n\x04\x05\0\x02\0\x12\x03\x03\x04\x18\n\x0c\n\x05\x05\0\x02\0\x01\
\x12\x03\x03\x04\x13\n\x0c\n\x05\x05\0\x02\0\x02\x12\x03\x03\x16\x17b\
\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()
})
}

View File

@ -9,6 +9,9 @@ pub use workspace_update::*;
mod app_create; mod app_create;
pub use app_create::*; pub use app_create::*;
mod event;
pub use event::*;
mod workspace_create; mod workspace_create;
pub use workspace_create::*; pub use workspace_create::*;

View File

@ -224,17 +224,272 @@ impl ::protobuf::reflect::ProtobufValue for CreateWorkspaceRequest {
} }
} }
#[derive(PartialEq,Clone,Default)]
pub struct WorkspaceDetail {
// message fields
pub 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 WorkspaceDetail {
fn default() -> &'a WorkspaceDetail {
<WorkspaceDetail as ::protobuf::Message>::default_instance()
}
}
impl WorkspaceDetail {
pub fn new() -> WorkspaceDetail {
::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 {
&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 = 3;
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 WorkspaceDetail {
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.name)?;
},
3 => {
::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.name.is_empty() {
my_size += ::protobuf::rt::string_size(2, &self.name);
}
if !self.desc.is_empty() {
my_size += ::protobuf::rt::string_size(3, &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.name.is_empty() {
os.write_string(2, &self.name)?;
}
if !self.desc.is_empty() {
os.write_string(3, &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<Self>) -> ::std::boxed::Box<dyn (::std::any::Any)> {
self
}
fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor {
Self::descriptor_static()
}
fn new() -> WorkspaceDetail {
WorkspaceDetail::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: &WorkspaceDetail| { &m.id },
|m: &mut WorkspaceDetail| { &mut m.id },
));
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
"name",
|m: &WorkspaceDetail| { &m.name },
|m: &mut WorkspaceDetail| { &mut m.name },
));
fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
"desc",
|m: &WorkspaceDetail| { &m.desc },
|m: &mut WorkspaceDetail| { &mut m.desc },
));
::protobuf::reflect::MessageDescriptor::new_pb_name::<WorkspaceDetail>(
"WorkspaceDetail",
fields,
file_descriptor_proto()
)
})
}
fn default_instance() -> &'static WorkspaceDetail {
static instance: ::protobuf::rt::LazyV2<WorkspaceDetail> = ::protobuf::rt::LazyV2::INIT;
instance.get(WorkspaceDetail::new)
}
}
impl ::protobuf::Clear for WorkspaceDetail {
fn clear(&mut self) {
self.id.clear();
self.name.clear();
self.desc.clear();
self.unknown_fields.clear();
}
}
impl ::std::fmt::Debug for WorkspaceDetail {
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
::protobuf::text_format::fmt(self, f)
}
}
impl ::protobuf::reflect::ProtobufValue for WorkspaceDetail {
fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef {
::protobuf::reflect::ReflectValueRef::Message(self)
}
}
static file_descriptor_proto_data: &'static [u8] = b"\ static file_descriptor_proto_data: &'static [u8] = b"\
\n\x16workspace_create.proto\"@\n\x16CreateWorkspaceRequest\x12\x12\n\ \n\x16workspace_create.proto\"@\n\x16CreateWorkspaceRequest\x12\x12\n\
\x04name\x18\x01\x20\x01(\tR\x04name\x12\x12\n\x04desc\x18\x02\x20\x01(\ \x04name\x18\x01\x20\x01(\tR\x04name\x12\x12\n\x04desc\x18\x02\x20\x01(\
\tR\x04descJ\x98\x01\n\x06\x12\x04\0\0\x05\x01\n\x08\n\x01\x0c\x12\x03\0\ \tR\x04desc\"I\n\x0fWorkspaceDetail\x12\x0e\n\x02id\x18\x01\x20\x01(\tR\
\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\x04\0\x01\x12\x03\ \x02id\x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\x12\n\x04desc\
\x02\x08\x1e\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x14\n\x0c\n\x05\x04\ \x18\x03\x20\x01(\tR\x04descJ\xd5\x02\n\x06\x12\x04\0\0\n\x01\n\x08\n\
\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\ \x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x05\x01\n\n\n\x03\
\x0b\x0f\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x12\x13\n\x0b\n\x04\x04\ \x04\0\x01\x12\x03\x02\x08\x1e\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\
\0\x02\x01\x12\x03\x04\x04\x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\ \x14\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\
\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0f\n\x0c\n\x05\x04\ \0\x01\x12\x03\x03\x0b\x0f\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x12\
\0\x02\x01\x03\x12\x03\x04\x12\x13b\x06proto3\ \x13\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\n\n\x02\x04\x01\
\x12\x04\x06\0\n\x01\n\n\n\x03\x04\x01\x01\x12\x03\x06\x08\x17\n\x0b\n\
\x04\x04\x01\x02\0\x12\x03\x07\x04\x12\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\r\n\x0c\n\
\x05\x04\x01\x02\0\x03\x12\x03\x07\x10\x11\n\x0b\n\x04\x04\x01\x02\x01\
\x12\x03\x08\x04\x14\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\x0f\n\x0c\n\x05\x04\x01\
\x02\x01\x03\x12\x03\x08\x12\x13\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\t\
\x04\x14\n\x0c\n\x05\x04\x01\x02\x02\x05\x12\x03\t\x04\n\n\x0c\n\x05\x04\
\x01\x02\x02\x01\x12\x03\t\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\
\x03\t\x12\x13b\x06proto3\
"; ";
static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

View File

@ -0,0 +1,5 @@
syntax = "proto3";
enum WorkspaceEvent {
CreateWorkspace = 0;
}

View File

@ -4,3 +4,8 @@ message CreateWorkspaceRequest {
string name = 1; string name = 1;
string desc = 2; string desc = 2;
} }
message WorkspaceDetail {
string id = 1;
string name = 2;
string desc = 3;
}

View File

@ -35,14 +35,19 @@ pub struct WorkspaceController {
impl WorkspaceController { impl WorkspaceController {
pub fn new(db: Arc<dyn UserDatabaseConnection>) -> Self { Self { db } } pub fn new(db: Arc<dyn UserDatabaseConnection>) -> Self { Self { db } }
pub fn save_workspace(&self, params: CreateWorkspaceParams) -> Result<(), WorkspaceError> { pub fn save_workspace(
&self,
params: CreateWorkspaceParams,
) -> Result<WorkspaceDetail, WorkspaceError> {
let workspace = Workspace::new(params); let workspace = Workspace::new(params);
let conn = self.get_connection()?; let conn = self.get_connection()?;
let detail: WorkspaceDetail = workspace.clone().into();
let _ = diesel::insert_into(workspace_table::table) let _ = diesel::insert_into(workspace_table::table)
.values(workspace) .values(workspace)
.execute(&*conn)?; .execute(&*conn)?;
Ok(()) Ok(detail)
} }
pub fn update_workspace(&self, params: UpdateWorkspaceParams) -> Result<(), WorkspaceError> { pub fn update_workspace(&self, params: UpdateWorkspaceParams) -> Result<(), WorkspaceError> {

View File

@ -1,5 +1,5 @@
use crate::{ use crate::{
entities::workspace::{CreateWorkspaceParams, UpdateWorkspaceParams}, entities::workspace::{CreateWorkspaceParams, UpdateWorkspaceParams, WorkspaceDetail},
sql_tables::app::App, sql_tables::app::App,
}; };
use flowy_database::schema::{workspace_table, workspace_table::dsl}; use flowy_database::schema::{workspace_table, workspace_table::dsl};
@ -61,3 +61,13 @@ impl WorkspaceChangeset {
} }
} }
} }
impl std::convert::Into<WorkspaceDetail> for Workspace {
fn into(self) -> WorkspaceDetail {
WorkspaceDetail {
id: self.id,
name: self.name,
desc: self.desc,
}
}
}

View File

@ -0,0 +1 @@
mod workspace_test;

View File

@ -0,0 +1,20 @@
use flowy_test::EventTester;
use flowy_workspace::{
entities::workspace::{CreateWorkspaceRequest, WorkspaceDetail},
event::WorkspaceEvent::*,
prelude::*,
};
#[test]
fn workspace_create_test() {
let request = CreateWorkspaceRequest {
name: "123workspace".to_owned(),
desc: "".to_owned(),
};
let response = EventTester::new(CreateWorkspace)
.request(request)
.sync_send()
.parse::<WorkspaceDetail>();
dbg!(&response);
}