mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
fix flutter compile erros
This commit is contained in:
parent
3a12d5ae79
commit
b66b3b3dc2
@ -33,7 +33,7 @@ class UserRepo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<List<Workspace>, WorkspaceError>> fetchWorkspaces() {
|
Future<Either<List<Workspace>, WorkspaceError>> fetchWorkspaces() {
|
||||||
final request = QueryWorkspaceRequest.create()..userId = user.id;
|
final request = QueryWorkspaceRequest.create();
|
||||||
|
|
||||||
return WorkspaceEventReadWorkspaces(request).send().then((result) {
|
return WorkspaceEventReadWorkspaces(request).send().then((result) {
|
||||||
return result.fold(
|
return result.fold(
|
||||||
@ -44,9 +44,7 @@ class UserRepo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<Workspace, WorkspaceError>> openWorkspace(String workspaceId) {
|
Future<Either<Workspace, WorkspaceError>> openWorkspace(String workspaceId) {
|
||||||
final request = QueryWorkspaceRequest.create()
|
final request = QueryWorkspaceRequest.create()..workspaceId = workspaceId;
|
||||||
..userId = user.id
|
|
||||||
..workspaceId = workspaceId;
|
|
||||||
return WorkspaceEventOpenWorkspace(request).send().then((result) {
|
return WorkspaceEventOpenWorkspace(request).send().then((result) {
|
||||||
return result.fold(
|
return result.fold(
|
||||||
(workspace) => left(workspace),
|
(workspace) => left(workspace),
|
||||||
@ -58,7 +56,6 @@ class UserRepo {
|
|||||||
Future<Either<Workspace, WorkspaceError>> createWorkspace(
|
Future<Either<Workspace, WorkspaceError>> createWorkspace(
|
||||||
String name, String desc) {
|
String name, String desc) {
|
||||||
final request = CreateWorkspaceRequest.create()
|
final request = CreateWorkspaceRequest.create()
|
||||||
..userId = user.id
|
|
||||||
..name = name
|
..name = name
|
||||||
..desc = desc;
|
..desc = desc;
|
||||||
return WorkspaceEventCreateWorkspace(request).send().then((result) {
|
return WorkspaceEventCreateWorkspace(request).send().then((result) {
|
||||||
|
@ -40,9 +40,7 @@ class WorkspaceRepo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Either<Workspace, WorkspaceError>> getWorkspace() {
|
Future<Either<Workspace, WorkspaceError>> getWorkspace() {
|
||||||
final request = QueryWorkspaceRequest.create()
|
final request = QueryWorkspaceRequest.create()..workspaceId = workspaceId;
|
||||||
..userId = user.id
|
|
||||||
..workspaceId = workspaceId;
|
|
||||||
|
|
||||||
return WorkspaceEventReadWorkspaces(request).send().then((result) {
|
return WorkspaceEventReadWorkspaces(request).send().then((result) {
|
||||||
return result.fold(
|
return result.fold(
|
||||||
|
@ -8,16 +8,14 @@ use std::{path::Path, sync::RwLock};
|
|||||||
|
|
||||||
const DB_NAME: &str = "kv.db";
|
const DB_NAME: &str = "kv.db";
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref KV_HOLDER: RwLock<KVStore> = RwLock::new(KVStore::new());
|
static ref KV_HOLDER: RwLock<KV> = RwLock::new(KV { database: None });
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct KVStore {
|
pub struct KV {
|
||||||
database: Option<Database>,
|
database: Option<Database>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl KVStore {
|
impl KV {
|
||||||
fn new() -> Self { KVStore { database: None } }
|
|
||||||
|
|
||||||
fn set(item: KeyValue) -> Result<(), String> {
|
fn set(item: KeyValue) -> Result<(), String> {
|
||||||
let _ = diesel::replace_into(kv_table::table)
|
let _ = diesel::replace_into(kv_table::table)
|
||||||
.values(&item)
|
.values(&item)
|
||||||
@ -56,9 +54,7 @@ impl KVStore {
|
|||||||
let conn = database.get_connection().unwrap();
|
let conn = database.get_connection().unwrap();
|
||||||
SqliteConnection::execute(&*conn, KV_SQL).unwrap();
|
SqliteConnection::execute(&*conn, KV_SQL).unwrap();
|
||||||
|
|
||||||
let mut store = KV_HOLDER
|
let mut store = KV_HOLDER.write().map_err(|e| format!("KVStore write failed: {:?}", e))?;
|
||||||
.write()
|
|
||||||
.map_err(|e| format!("KVStore write failed: {:?}", e))?;
|
|
||||||
store.database = Some(database);
|
store.database = Some(database);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -70,10 +66,10 @@ macro_rules! impl_get_func {
|
|||||||
$func_name:ident,
|
$func_name:ident,
|
||||||
$get_method:ident=>$target:ident
|
$get_method:ident=>$target:ident
|
||||||
) => {
|
) => {
|
||||||
impl KVStore {
|
impl KV {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn $func_name(k: &str) -> Option<$target> {
|
pub fn $func_name(k: &str) -> Option<$target> {
|
||||||
match KVStore::get(k) {
|
match KV::get(k) {
|
||||||
Ok(item) => item.$get_method,
|
Ok(item) => item.$get_method,
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
}
|
}
|
||||||
@ -84,12 +80,12 @@ macro_rules! impl_get_func {
|
|||||||
|
|
||||||
macro_rules! impl_set_func {
|
macro_rules! impl_set_func {
|
||||||
($func_name:ident,$set_method:ident,$key_type:ident) => {
|
($func_name:ident,$set_method:ident,$key_type:ident) => {
|
||||||
impl KVStore {
|
impl KV {
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn $func_name(key: &str, value: $key_type) {
|
pub fn $func_name(key: &str, value: $key_type) {
|
||||||
let mut item = KeyValue::new(key);
|
let mut item = KeyValue::new(key);
|
||||||
item.$set_method = Some(value);
|
item.$set_method = Some(value);
|
||||||
match KVStore::set(item) {
|
match KV::set(item) {
|
||||||
Ok(_) => {},
|
Ok(_) => {},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("{:?}", e)
|
log::error!("{:?}", e)
|
||||||
@ -166,7 +162,7 @@ impl KeyValue {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::kv::KVStore;
|
use crate::kv::KV;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn kv_store_test() {
|
fn kv_store_test() {
|
||||||
@ -175,16 +171,16 @@ mod tests {
|
|||||||
std::fs::create_dir_all(dir).unwrap();
|
std::fs::create_dir_all(dir).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
KVStore::init(dir).unwrap();
|
KV::init(dir).unwrap();
|
||||||
|
|
||||||
KVStore::set_str("1", "hello".to_string());
|
KV::set_str("1", "hello".to_string());
|
||||||
assert_eq!(KVStore::get_str("1").unwrap(), "hello");
|
assert_eq!(KV::get_str("1").unwrap(), "hello");
|
||||||
|
|
||||||
assert_eq!(KVStore::get_str("2"), None);
|
assert_eq!(KV::get_str("2"), None);
|
||||||
|
|
||||||
KVStore::set_bool("1", true);
|
KV::set_bool("1", true);
|
||||||
assert_eq!(KVStore::get_bool("1").unwrap(), true);
|
assert_eq!(KV::get_bool("1").unwrap(), true);
|
||||||
|
|
||||||
assert_eq!(KVStore::get_bool("2"), None);
|
assert_eq!(KV::get_bool("2"), None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,7 @@ pub struct FlowySDK {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl FlowySDK {
|
impl FlowySDK {
|
||||||
pub fn new(root: &str) -> Self {
|
pub fn new(root: &str) -> Self { Self { root: root.to_owned() } }
|
||||||
Self {
|
|
||||||
root: root.to_owned(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn construct(self) { FlowySDK::construct_with(&self.root) }
|
pub fn construct(self) { FlowySDK::construct_with(&self.root) }
|
||||||
|
|
||||||
@ -25,7 +21,7 @@ impl FlowySDK {
|
|||||||
FlowySDK::init_log(root);
|
FlowySDK::init_log(root);
|
||||||
|
|
||||||
tracing::info!("🔥 Root path: {}", root);
|
tracing::info!("🔥 Root path: {}", root);
|
||||||
match flowy_infra::kv::KVStore::init(root) {
|
match flowy_infra::kv::KV::init(root) {
|
||||||
Ok(_) => {},
|
Ok(_) => {},
|
||||||
Err(e) => tracing::error!("Init kv store failedL: {}", e),
|
Err(e) => tracing::error!("Init kv store failedL: {}", e),
|
||||||
}
|
}
|
||||||
@ -36,17 +32,12 @@ impl FlowySDK {
|
|||||||
if !INIT_LOG.load(Ordering::SeqCst) {
|
if !INIT_LOG.load(Ordering::SeqCst) {
|
||||||
INIT_LOG.store(true, Ordering::SeqCst);
|
INIT_LOG.store(true, Ordering::SeqCst);
|
||||||
|
|
||||||
let _ = flowy_log::Builder::new("flowy")
|
let _ = flowy_log::Builder::new("flowy").local(directory).env_filter("info").build();
|
||||||
.local(directory)
|
|
||||||
.env_filter("info")
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_modules(root: &str) {
|
fn init_modules(root: &str) {
|
||||||
let config = ModuleConfig {
|
let config = ModuleConfig { root: root.to_owned() };
|
||||||
root: root.to_owned(),
|
|
||||||
};
|
|
||||||
EventDispatch::construct(|| build_modules(config));
|
EventDispatch::construct(|| build_modules(config));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,19 +41,11 @@ impl<T> Builder<T>
|
|||||||
where
|
where
|
||||||
T: TesterTrait,
|
T: TesterTrait,
|
||||||
{
|
{
|
||||||
fn test(tester: Box<T>) -> Self {
|
fn test(tester: Box<T>) -> Self { Self { tester, user_detail: None } }
|
||||||
Self {
|
|
||||||
tester,
|
|
||||||
user_detail: None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn sign_up(self) -> SignUpContext {
|
pub fn sign_up(self) -> SignUpContext {
|
||||||
let (user_detail, password) = self.tester.sign_up();
|
let (user_detail, password) = self.tester.sign_up();
|
||||||
SignUpContext {
|
SignUpContext { user_detail, password }
|
||||||
user_detail,
|
|
||||||
password,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sign_in(mut self) -> Self {
|
pub fn sign_in(mut self) -> Self {
|
||||||
@ -67,11 +59,6 @@ where
|
|||||||
self.user_detail = Some(user_detail);
|
self.user_detail = Some(user_detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn logout(self) -> Self {
|
|
||||||
// self.tester.logout();
|
|
||||||
self
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn request<P>(mut self, request: P) -> Self
|
pub fn request<P>(mut self, request: P) -> Self
|
||||||
where
|
where
|
||||||
P: ToBytes,
|
P: ToBytes,
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use flowy_dispatch::prelude::{DispatchError, EventDispatch, ModuleRequest, ToBytes};
|
use flowy_dispatch::prelude::{DispatchError, EventDispatch, ModuleRequest, ToBytes};
|
||||||
use flowy_infra::{kv::KVStore, uuid};
|
use flowy_infra::{kv::KV, uuid};
|
||||||
use flowy_user::errors::{ErrorBuilder, ErrorCode, UserError};
|
use flowy_user::errors::{ErrorBuilder, ErrorCode, UserError};
|
||||||
use flowy_workspace::{
|
use flowy_workspace::{
|
||||||
entities::workspace::{CreateWorkspaceRequest, QueryWorkspaceRequest, Workspace},
|
entities::workspace::{CreateWorkspaceRequest, QueryWorkspaceRequest, Workspace},
|
||||||
@ -36,10 +36,10 @@ const DEFAULT_WORKSPACE: &'static str = "Default_Workspace";
|
|||||||
|
|
||||||
pub(crate) fn create_default_workspace_if_need(user_id: &str) -> Result<(), UserError> {
|
pub(crate) fn create_default_workspace_if_need(user_id: &str) -> Result<(), UserError> {
|
||||||
let key = format!("{}{}", user_id, DEFAULT_WORKSPACE);
|
let key = format!("{}{}", user_id, DEFAULT_WORKSPACE);
|
||||||
if KVStore::get_bool(&key).unwrap_or(false) {
|
if KV::get_bool(&key).unwrap_or(false) {
|
||||||
return Err(ErrorBuilder::new(ErrorCode::DefaultWorkspaceAlreadyExist).build());
|
return Err(ErrorBuilder::new(ErrorCode::DefaultWorkspaceAlreadyExist).build());
|
||||||
}
|
}
|
||||||
KVStore::set_bool(&key, true);
|
KV::set_bool(&key, true);
|
||||||
|
|
||||||
let payload: Bytes = CreateWorkspaceRequest {
|
let payload: Bytes = CreateWorkspaceRequest {
|
||||||
name: DEFAULT_WORKSPACE_NAME.to_string(),
|
name: DEFAULT_WORKSPACE_NAME.to_string(),
|
||||||
|
@ -18,12 +18,7 @@ pub struct UserError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl UserError {
|
impl UserError {
|
||||||
fn new(code: ErrorCode, msg: &str) -> Self {
|
pub(crate) fn new(code: ErrorCode, msg: &str) -> Self { Self { code, msg: msg.to_owned() } }
|
||||||
Self {
|
|
||||||
code,
|
|
||||||
msg: msg.to_owned(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, ProtoBuf_Enum, Display, PartialEq, Eq)]
|
#[derive(Clone, ProtoBuf_Enum, Display, PartialEq, Eq)]
|
||||||
@ -66,9 +61,7 @@ pub enum ErrorCode {
|
|||||||
PasswordTooLong = 31,
|
PasswordTooLong = 31,
|
||||||
#[display(fmt = "Password contains forbidden characters.")]
|
#[display(fmt = "Password contains forbidden characters.")]
|
||||||
PasswordContainsForbidCharacters = 32,
|
PasswordContainsForbidCharacters = 32,
|
||||||
#[display(
|
#[display(fmt = "Password should contain a minimum of 6 characters with 1 special 1 letter and 1 numeric")]
|
||||||
fmt = "Password should contain a minimum of 6 characters with 1 special 1 letter and 1 numeric"
|
|
||||||
)]
|
|
||||||
PasswordFormatInvalid = 33,
|
PasswordFormatInvalid = 33,
|
||||||
#[display(fmt = "Password not match")]
|
#[display(fmt = "Password not match")]
|
||||||
PasswordNotMatch = 34,
|
PasswordNotMatch = 34,
|
||||||
@ -106,19 +99,11 @@ impl std::default::Default for ErrorCode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl std::convert::From<flowy_database::result::Error> for UserError {
|
impl std::convert::From<flowy_database::result::Error> for UserError {
|
||||||
fn from(error: flowy_database::result::Error) -> Self {
|
fn from(error: flowy_database::result::Error) -> Self { ErrorBuilder::new(ErrorCode::UserDatabaseInternalError).error(error).build() }
|
||||||
ErrorBuilder::new(ErrorCode::UserDatabaseInternalError)
|
|
||||||
.error(error)
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::convert::From<::r2d2::Error> for UserError {
|
impl std::convert::From<::r2d2::Error> for UserError {
|
||||||
fn from(error: r2d2::Error) -> Self {
|
fn from(error: r2d2::Error) -> Self { ErrorBuilder::new(ErrorCode::DatabaseConnectError).error(error).build() }
|
||||||
ErrorBuilder::new(ErrorCode::DatabaseConnectError)
|
|
||||||
.error(error)
|
|
||||||
.build()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// use diesel::result::{Error, DatabaseErrorKind};
|
// use diesel::result::{Error, DatabaseErrorKind};
|
||||||
@ -153,23 +138,15 @@ impl std::convert::From<flowy_sqlite::Error> for UserError {
|
|||||||
// ErrorKind::__Nonexhaustive { .. } => {},
|
// ErrorKind::__Nonexhaustive { .. } => {},
|
||||||
// }
|
// }
|
||||||
|
|
||||||
ErrorBuilder::new(ErrorCode::SqlInternalError)
|
ErrorBuilder::new(ErrorCode::SqlInternalError).error(error).build()
|
||||||
.error(error)
|
|
||||||
.build()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::convert::From<flowy_net::errors::ServerError> for UserError {
|
impl std::convert::From<flowy_net::errors::ServerError> for UserError {
|
||||||
fn from(error: flowy_net::errors::ServerError) -> Self {
|
fn from(error: flowy_net::errors::ServerError) -> Self {
|
||||||
match error.code {
|
match error.code {
|
||||||
flowy_net::errors::ErrorCode::PasswordNotMatch => {
|
flowy_net::errors::ErrorCode::PasswordNotMatch => ErrorBuilder::new(ErrorCode::PasswordNotMatch).error(error.msg).build(),
|
||||||
ErrorBuilder::new(ErrorCode::PasswordNotMatch)
|
_ => ErrorBuilder::new(ErrorCode::ServerError).error(error.msg).build(),
|
||||||
.error(error.msg)
|
|
||||||
.build()
|
|
||||||
},
|
|
||||||
_ => ErrorBuilder::new(ErrorCode::ServerError)
|
|
||||||
.error(error.msg)
|
|
||||||
.build(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -185,11 +162,7 @@ pub type ErrorBuilder = flowy_infra::errors::Builder<ErrorCode, UserError>;
|
|||||||
|
|
||||||
impl flowy_infra::errors::Build<ErrorCode> for UserError {
|
impl flowy_infra::errors::Build<ErrorCode> for UserError {
|
||||||
fn build(code: ErrorCode, msg: String) -> Self {
|
fn build(code: ErrorCode, msg: String) -> Self {
|
||||||
let msg = if msg.is_empty() {
|
let msg = if msg.is_empty() { format!("{}", code) } else { msg };
|
||||||
format!("{}", code)
|
|
||||||
} else {
|
|
||||||
msg
|
|
||||||
};
|
|
||||||
UserError::new(code, &msg)
|
UserError::new(code, &msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,7 @@ use flowy_dispatch::prelude::*;
|
|||||||
use std::{convert::TryInto, sync::Arc};
|
use std::{convert::TryInto, sync::Arc};
|
||||||
|
|
||||||
#[tracing::instrument(name = "get_user_status", skip(session))]
|
#[tracing::instrument(name = "get_user_status", skip(session))]
|
||||||
pub async fn user_status_handler(
|
pub async fn user_profile_handler(session: Unit<Arc<UserSession>>) -> DataResult<UserDetail, UserError> {
|
||||||
session: Unit<Arc<UserSession>>,
|
|
||||||
) -> DataResult<UserDetail, UserError> {
|
|
||||||
let user_detail = session.user_detail().await?;
|
let user_detail = session.user_detail().await?;
|
||||||
data_result(user_detail)
|
data_result(user_detail)
|
||||||
}
|
}
|
||||||
@ -18,10 +16,7 @@ pub async fn sign_out(session: Unit<Arc<UserSession>>) -> Result<(), UserError>
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(name = "update_user", skip(data, session))]
|
#[tracing::instrument(name = "update_user", skip(data, session))]
|
||||||
pub async fn update_user_handler(
|
pub async fn update_user_handler(data: Data<UpdateUserRequest>, session: Unit<Arc<UserSession>>) -> Result<(), UserError> {
|
||||||
data: Data<UpdateUserRequest>,
|
|
||||||
session: Unit<Arc<UserSession>>,
|
|
||||||
) -> Result<(), UserError> {
|
|
||||||
let params: UpdateUserParams = data.into_inner().try_into()?;
|
let params: UpdateUserParams = data.into_inner().try_into()?;
|
||||||
session.update_user(params).await?;
|
session.update_user(params).await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -9,7 +9,7 @@ pub fn create(user_session: Arc<UserSession>) -> Module {
|
|||||||
.data(user_session)
|
.data(user_session)
|
||||||
.event(UserEvent::SignIn, sign_in)
|
.event(UserEvent::SignIn, sign_in)
|
||||||
.event(UserEvent::SignUp, sign_up)
|
.event(UserEvent::SignUp, sign_up)
|
||||||
.event(UserEvent::GetUserProfile, user_status_handler)
|
.event(UserEvent::GetUserProfile, user_profile_handler)
|
||||||
.event(UserEvent::SignOut, sign_out)
|
.event(UserEvent::SignOut, sign_out)
|
||||||
.event(UserEvent::UpdateUser, update_user_handler)
|
.event(UserEvent::UpdateUser, update_user_handler)
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,9 @@ pub trait UserServerAPI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn construct_user_server() -> Arc<dyn UserServerAPI + Send + Sync> {
|
pub(crate) fn construct_user_server() -> Arc<dyn UserServerAPI + Send + Sync> {
|
||||||
// if cfg!(feature = "http_server") {
|
if cfg!(feature = "http_server") {
|
||||||
// Arc::new(UserServer {})
|
Arc::new(UserServer {})
|
||||||
// } else {
|
} else {
|
||||||
// Arc::new(UserServerMock {})
|
Arc::new(UserServerMock {})
|
||||||
// }
|
}
|
||||||
Arc::new(UserServer {})
|
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ use flowy_database::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crate::services::server::Server;
|
use crate::services::server::Server;
|
||||||
use flowy_infra::kv::KVStore;
|
use flowy_infra::kv::KV;
|
||||||
use flowy_sqlite::ConnectionPool;
|
use flowy_sqlite::ConnectionPool;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
@ -164,22 +164,16 @@ impl UserSession {
|
|||||||
fn set_session(&self, session: Option<Session>) -> Result<(), UserError> {
|
fn set_session(&self, session: Option<Session>) -> Result<(), UserError> {
|
||||||
log::trace!("Update user session: {:?}", session);
|
log::trace!("Update user session: {:?}", session);
|
||||||
match &session {
|
match &session {
|
||||||
None => KVStore::set_str(SESSION_CACHE_KEY, "".to_string()),
|
None => KV::remove(SESSION_CACHE_KEY).map_err(|e| UserError::new(ErrorCode::SqlInternalError, &e))?,
|
||||||
Some(session) => KVStore::set_str(SESSION_CACHE_KEY, session.clone().into()),
|
Some(session) => KV::set_str(SESSION_CACHE_KEY, session.clone().into()),
|
||||||
}
|
}
|
||||||
|
*self.session.write() = session;
|
||||||
let mut write_guard = self.session.write();
|
|
||||||
*write_guard = session;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
fn get_session(&self) -> Result<Session, UserError> {
|
fn get_session(&self) -> Result<Session, UserError> {
|
||||||
let mut session = {
|
let mut session = { (*self.session.read()).clone() };
|
||||||
let read_guard = self.session.read();
|
|
||||||
(*read_guard).clone()
|
|
||||||
};
|
|
||||||
|
|
||||||
if session.is_none() {
|
if session.is_none() {
|
||||||
match KVStore::get_str(SESSION_CACHE_KEY) {
|
match KV::get_str(SESSION_CACHE_KEY) {
|
||||||
None => {},
|
None => {},
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
session = Some(Session::from(s));
|
session = Some(Session::from(s));
|
||||||
@ -203,7 +197,7 @@ pub async fn update_user(_server: Server, pool: Arc<ConnectionPool>, params: Upd
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_user_id() -> Result<String, UserError> {
|
pub fn current_user_id() -> Result<String, UserError> {
|
||||||
match KVStore::get_str(SESSION_CACHE_KEY) {
|
match KV::get_str(SESSION_CACHE_KEY) {
|
||||||
None => Err(ErrorBuilder::new(ErrorCode::UserNotLoginYet).build()),
|
None => Err(ErrorBuilder::new(ErrorCode::UserNotLoginYet).build()),
|
||||||
Some(user_id) => Ok(user_id),
|
Some(user_id) => Ok(user_id),
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,7 @@ use crate::{
|
|||||||
sql_tables::workspace::{WorkspaceSql, WorkspaceTable, WorkspaceTableChangeset},
|
sql_tables::workspace::{WorkspaceSql, WorkspaceTable, WorkspaceTableChangeset},
|
||||||
};
|
};
|
||||||
use flowy_dispatch::prelude::DispatchFuture;
|
use flowy_dispatch::prelude::DispatchFuture;
|
||||||
use flowy_infra::kv::KVStore;
|
use flowy_infra::kv::KV;
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
@ -202,10 +202,10 @@ impl WorkspaceController {
|
|||||||
|
|
||||||
const CURRENT_WORKSPACE_ID: &str = "current_workspace_id";
|
const CURRENT_WORKSPACE_ID: &str = "current_workspace_id";
|
||||||
|
|
||||||
fn set_current_workspace(workspace: &str) { KVStore::set_str(CURRENT_WORKSPACE_ID, workspace.to_owned()); }
|
fn set_current_workspace(workspace: &str) { KV::set_str(CURRENT_WORKSPACE_ID, workspace.to_owned()); }
|
||||||
|
|
||||||
fn get_current_workspace() -> Result<String, WorkspaceError> {
|
fn get_current_workspace() -> Result<String, WorkspaceError> {
|
||||||
match KVStore::get_str(CURRENT_WORKSPACE_ID) {
|
match KV::get_str(CURRENT_WORKSPACE_ID) {
|
||||||
None => Err(ErrorBuilder::new(ErrorCode::CurrentWorkspaceNotFound).build()),
|
None => Err(ErrorBuilder::new(ErrorCode::CurrentWorkspaceNotFound).build()),
|
||||||
Some(workspace_id) => Ok(workspace_id),
|
Some(workspace_id) => Ok(workspace_id),
|
||||||
}
|
}
|
||||||
|
@ -12,13 +12,16 @@ pub(crate) fn invalid_workspace_name_test_case() -> Vec<String> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_workspace(name: &str, desc: &str) -> Workspace {
|
pub fn create_workspace(name: &str, desc: &str) -> Workspace {
|
||||||
let builder = AnnieTestBuilder::new();
|
|
||||||
let request = CreateWorkspaceRequest {
|
let request = CreateWorkspaceRequest {
|
||||||
name: name.to_owned(),
|
name: name.to_owned(),
|
||||||
desc: desc.to_owned(),
|
desc: desc.to_owned(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let workspace = builder.event(CreateWorkspace).request(request).sync_send().parse::<Workspace>();
|
let workspace = AnnieTestBuilder::new()
|
||||||
|
.event(CreateWorkspace)
|
||||||
|
.request(request)
|
||||||
|
.sync_send()
|
||||||
|
.parse::<Workspace>();
|
||||||
workspace
|
workspace
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user