mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
chore: reanme flowy-user crate
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
use crate::{configuration::*, request::HttpRequestBuilder};
|
||||
use flowy_error::FlowyError;
|
||||
use flowy_user::entities::{
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfile,
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB,
|
||||
};
|
||||
use flowy_user::event_map::UserCloudService;
|
||||
use http_flowy::errors::ServerError;
|
||||
@ -51,7 +51,7 @@ impl UserCloudService for UserHttpCloudService {
|
||||
})
|
||||
}
|
||||
|
||||
fn get_user(&self, token: &str) -> FutureResult<UserProfile, FlowyError> {
|
||||
fn get_user(&self, token: &str) -> FutureResult<UserProfilePB, FlowyError> {
|
||||
let token = token.to_owned();
|
||||
let url = self.config.user_profile_url();
|
||||
FutureResult::new(async move {
|
||||
@ -92,7 +92,7 @@ pub async fn user_sign_out_request(token: &str, url: &str) -> Result<(), ServerE
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_user_profile_request(token: &str, url: &str) -> Result<UserProfile, ServerError> {
|
||||
pub async fn get_user_profile_request(token: &str, url: &str) -> Result<UserProfilePB, ServerError> {
|
||||
let user_profile = request_builder()
|
||||
.get(&url.to_owned())
|
||||
.header(HEADER_TOKEN, token)
|
||||
|
@ -263,7 +263,7 @@ use flowy_folder_data_model::revision::{
|
||||
};
|
||||
use flowy_text_block::BlockCloudService;
|
||||
use flowy_user::entities::{
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfile,
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB,
|
||||
};
|
||||
use flowy_user::event_map::UserCloudService;
|
||||
use lib_infra::{future::FutureResult, util::timestamp};
|
||||
@ -405,8 +405,8 @@ impl UserCloudService for LocalServer {
|
||||
FutureResult::new(async { Ok(()) })
|
||||
}
|
||||
|
||||
fn get_user(&self, _token: &str) -> FutureResult<UserProfile, FlowyError> {
|
||||
FutureResult::new(async { Ok(UserProfile::default()) })
|
||||
fn get_user(&self, _token: &str) -> FutureResult<UserProfilePB, FlowyError> {
|
||||
FutureResult::new(async { Ok(UserProfilePB::default()) })
|
||||
}
|
||||
|
||||
fn ws_addr(&self) -> String {
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::FlowySDKTest;
|
||||
use flowy_user::{entities::UserProfile, errors::FlowyError};
|
||||
use flowy_user::{entities::UserProfilePB, errors::FlowyError};
|
||||
use lib_dispatch::prelude::{EventDispatcher, EventResponse, FromBytes, ModuleRequest, StatusCode, ToBytes, *};
|
||||
use std::{
|
||||
convert::TryFrom,
|
||||
@ -14,7 +14,7 @@ impl FolderEventBuilder {
|
||||
pub fn new(sdk: FlowySDKTest) -> Self {
|
||||
EventBuilder::test(TestContext::new(sdk))
|
||||
}
|
||||
pub fn user_profile(&self) -> &Option<UserProfile> {
|
||||
pub fn user_profile(&self) -> &Option<UserProfilePB> {
|
||||
&self.user_profile
|
||||
}
|
||||
}
|
||||
@ -24,7 +24,7 @@ pub type UserModuleEventBuilder = FolderEventBuilder;
|
||||
#[derive(Clone)]
|
||||
pub struct EventBuilder<E> {
|
||||
context: TestContext,
|
||||
user_profile: Option<UserProfile>,
|
||||
user_profile: Option<UserProfilePB>,
|
||||
err_phantom: PhantomData<E>,
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,7 @@ use flowy_folder::{
|
||||
event_map::FolderEvent::{CreateWorkspace, OpenWorkspace, *},
|
||||
};
|
||||
use flowy_user::{
|
||||
entities::{SignInPayload, SignUpPayload, UserProfile},
|
||||
entities::{SignInPayloadPB, SignUpPayloadPB, UserProfilePB},
|
||||
errors::FlowyError,
|
||||
event_map::UserEvent::{InitUser, SignIn, SignOut, SignUp},
|
||||
};
|
||||
@ -138,13 +138,13 @@ pub fn login_password() -> String {
|
||||
}
|
||||
|
||||
pub struct SignUpContext {
|
||||
pub user_profile: UserProfile,
|
||||
pub user_profile: UserProfilePB,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
pub fn sign_up(dispatch: Arc<EventDispatcher>) -> SignUpContext {
|
||||
let password = login_password();
|
||||
let payload = SignUpPayload {
|
||||
let payload = SignUpPayloadPB {
|
||||
email: random_email(),
|
||||
name: "app flowy".to_string(),
|
||||
password: password.clone(),
|
||||
@ -154,7 +154,7 @@ pub fn sign_up(dispatch: Arc<EventDispatcher>) -> SignUpContext {
|
||||
|
||||
let request = ModuleRequest::new(SignUp).payload(payload);
|
||||
let user_profile = EventDispatcher::sync_send(dispatch, request)
|
||||
.parse::<UserProfile, FlowyError>()
|
||||
.parse::<UserProfilePB, FlowyError>()
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
@ -164,7 +164,7 @@ pub fn sign_up(dispatch: Arc<EventDispatcher>) -> SignUpContext {
|
||||
pub async fn async_sign_up(dispatch: Arc<EventDispatcher>) -> SignUpContext {
|
||||
let password = login_password();
|
||||
let email = random_email();
|
||||
let payload = SignUpPayload {
|
||||
let payload = SignUpPayloadPB {
|
||||
email,
|
||||
name: "app flowy".to_string(),
|
||||
password: password.clone(),
|
||||
@ -175,7 +175,7 @@ pub async fn async_sign_up(dispatch: Arc<EventDispatcher>) -> SignUpContext {
|
||||
let request = ModuleRequest::new(SignUp).payload(payload);
|
||||
let user_profile = EventDispatcher::async_send(dispatch.clone(), request)
|
||||
.await
|
||||
.parse::<UserProfile, FlowyError>()
|
||||
.parse::<UserProfilePB, FlowyError>()
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
|
||||
@ -189,8 +189,8 @@ pub async fn init_user_setting(dispatch: Arc<EventDispatcher>) {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn sign_in(dispatch: Arc<EventDispatcher>) -> UserProfile {
|
||||
let payload = SignInPayload {
|
||||
fn sign_in(dispatch: Arc<EventDispatcher>) -> UserProfilePB {
|
||||
let payload = SignInPayloadPB {
|
||||
email: login_email(),
|
||||
password: login_password(),
|
||||
name: "rust".to_owned(),
|
||||
@ -200,7 +200,7 @@ fn sign_in(dispatch: Arc<EventDispatcher>) -> UserProfile {
|
||||
|
||||
let request = ModuleRequest::new(SignIn).payload(payload);
|
||||
EventDispatcher::sync_send(dispatch, request)
|
||||
.parse::<UserProfile, FlowyError>()
|
||||
.parse::<UserProfilePB, FlowyError>()
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ pub mod helper;
|
||||
use crate::helper::*;
|
||||
use flowy_net::{get_client_server_configuration, ClientServerConfiguration};
|
||||
use flowy_sdk::{FlowySDK, FlowySDKConfig};
|
||||
use flowy_user::entities::UserProfile;
|
||||
use flowy_user::entities::UserProfilePB;
|
||||
use nanoid::nanoid;
|
||||
|
||||
pub mod prelude {
|
||||
@ -47,7 +47,7 @@ impl FlowySDKTest {
|
||||
context
|
||||
}
|
||||
|
||||
pub async fn init_user(&self) -> UserProfile {
|
||||
pub async fn init_user(&self) -> UserProfilePB {
|
||||
let context = async_sign_up(self.inner.dispatcher()).await;
|
||||
init_user_setting(self.inner.dispatcher()).await;
|
||||
context.user_profile
|
||||
|
@ -4,7 +4,7 @@ use flowy_derive::ProtoBuf;
|
||||
use std::convert::TryInto;
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct SignInPayload {
|
||||
pub struct SignInPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub email: String,
|
||||
|
||||
@ -42,7 +42,7 @@ pub struct SignInResponse {
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
impl TryInto<SignInParams> for SignInPayload {
|
||||
impl TryInto<SignInParams> for SignInPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<SignInParams, Self::Error> {
|
||||
@ -58,7 +58,7 @@ impl TryInto<SignInParams> for SignInPayload {
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct SignUpPayload {
|
||||
pub struct SignUpPayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub email: String,
|
||||
|
||||
@ -68,7 +68,7 @@ pub struct SignUpPayload {
|
||||
#[pb(index = 3)]
|
||||
pub password: String,
|
||||
}
|
||||
impl TryInto<SignUpParams> for SignUpPayload {
|
||||
impl TryInto<SignUpParams> for SignUpPayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<SignUpParams, Self::Error> {
|
||||
|
@ -7,13 +7,13 @@ use crate::{
|
||||
};
|
||||
|
||||
#[derive(Default, ProtoBuf)]
|
||||
pub struct UserToken {
|
||||
pub struct UserTokenPB {
|
||||
#[pb(index = 1)]
|
||||
pub token: String,
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default, Debug, PartialEq, Eq, Clone)]
|
||||
pub struct UserProfile {
|
||||
pub struct UserProfilePB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
@ -28,7 +28,7 @@ pub struct UserProfile {
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Default)]
|
||||
pub struct UpdateUserProfilePayload {
|
||||
pub struct UpdateUserProfilePayloadPB {
|
||||
#[pb(index = 1)]
|
||||
pub id: String,
|
||||
|
||||
@ -42,7 +42,7 @@ pub struct UpdateUserProfilePayload {
|
||||
pub password: Option<String>,
|
||||
}
|
||||
|
||||
impl UpdateUserProfilePayload {
|
||||
impl UpdateUserProfilePayloadPB {
|
||||
pub fn new(id: &str) -> Self {
|
||||
Self {
|
||||
id: id.to_owned(),
|
||||
@ -85,7 +85,9 @@ impl UpdateUserProfileParams {
|
||||
pub fn new(user_id: &str) -> Self {
|
||||
Self {
|
||||
id: user_id.to_owned(),
|
||||
..Default::default()
|
||||
name: None,
|
||||
email: None,
|
||||
password: None,
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +107,7 @@ impl UpdateUserProfileParams {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryInto<UpdateUserProfileParams> for UpdateUserProfilePayload {
|
||||
impl TryInto<UpdateUserProfileParams> for UpdateUserProfilePayloadPB {
|
||||
type Error = ErrorCode;
|
||||
|
||||
fn try_into(self) -> Result<UpdateUserProfileParams, Self::Error> {
|
||||
|
@ -2,22 +2,22 @@ use flowy_derive::ProtoBuf;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(ProtoBuf, Default, Debug, Clone)]
|
||||
pub struct UserPreferences {
|
||||
pub struct UserPreferencesPB {
|
||||
#[pb(index = 1)]
|
||||
user_id: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
appearance_setting: AppearanceSettings,
|
||||
appearance_setting: AppearanceSettingsPB,
|
||||
}
|
||||
|
||||
#[derive(ProtoBuf, Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct AppearanceSettings {
|
||||
pub struct AppearanceSettingsPB {
|
||||
#[pb(index = 1)]
|
||||
pub theme: String,
|
||||
|
||||
#[pb(index = 2)]
|
||||
#[serde(default)]
|
||||
pub locale: LocaleSettings,
|
||||
pub locale: LocaleSettingsPB,
|
||||
|
||||
#[pb(index = 3)]
|
||||
#[serde(default = "DEFAULT_RESET_VALUE")]
|
||||
@ -27,7 +27,7 @@ pub struct AppearanceSettings {
|
||||
const DEFAULT_RESET_VALUE: fn() -> bool = || APPEARANCE_RESET_AS_DEFAULT;
|
||||
|
||||
#[derive(ProtoBuf, Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct LocaleSettings {
|
||||
pub struct LocaleSettingsPB {
|
||||
#[pb(index = 1)]
|
||||
pub language_code: String,
|
||||
|
||||
@ -35,7 +35,7 @@ pub struct LocaleSettings {
|
||||
pub country_code: String,
|
||||
}
|
||||
|
||||
impl std::default::Default for LocaleSettings {
|
||||
impl std::default::Default for LocaleSettingsPB {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
language_code: "en".to_owned(),
|
||||
@ -47,11 +47,11 @@ impl std::default::Default for LocaleSettings {
|
||||
pub const APPEARANCE_DEFAULT_THEME: &str = "light";
|
||||
const APPEARANCE_RESET_AS_DEFAULT: bool = true;
|
||||
|
||||
impl std::default::Default for AppearanceSettings {
|
||||
impl std::default::Default for AppearanceSettingsPB {
|
||||
fn default() -> Self {
|
||||
AppearanceSettings {
|
||||
AppearanceSettingsPB {
|
||||
theme: APPEARANCE_DEFAULT_THEME.to_owned(),
|
||||
locale: LocaleSettings::default(),
|
||||
locale: LocaleSettingsPB::default(),
|
||||
reset_as_default: APPEARANCE_RESET_AS_DEFAULT,
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::entities::{
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfile,
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB,
|
||||
};
|
||||
use crate::{errors::FlowyError, handlers::*, services::UserSession};
|
||||
use lib_dispatch::prelude::*;
|
||||
@ -26,7 +26,7 @@ pub trait UserCloudService: Send + Sync {
|
||||
fn sign_in(&self, params: SignInParams) -> FutureResult<SignInResponse, FlowyError>;
|
||||
fn sign_out(&self, token: &str) -> FutureResult<(), FlowyError>;
|
||||
fn update_user(&self, token: &str, params: UpdateUserProfileParams) -> FutureResult<(), FlowyError>;
|
||||
fn get_user(&self, token: &str) -> FutureResult<UserProfile, FlowyError>;
|
||||
fn get_user(&self, token: &str) -> FutureResult<UserProfilePB, FlowyError>;
|
||||
fn ws_addr(&self) -> String;
|
||||
}
|
||||
|
||||
@ -39,27 +39,27 @@ pub enum UserEvent {
|
||||
#[event()]
|
||||
InitUser = 0,
|
||||
|
||||
#[event(input = "SignInPayload", output = "UserProfile")]
|
||||
#[event(input = "SignInPayloadPB", output = "UserProfilePB")]
|
||||
SignIn = 1,
|
||||
|
||||
#[event(input = "SignUpPayload", output = "UserProfile")]
|
||||
#[event(input = "SignUpPayloadPB", output = "UserProfilePB")]
|
||||
SignUp = 2,
|
||||
|
||||
#[event(passthrough)]
|
||||
SignOut = 3,
|
||||
|
||||
#[event(input = "UpdateUserProfilePayload")]
|
||||
#[event(input = "UpdateUserProfilePayloadPB")]
|
||||
UpdateUserProfile = 4,
|
||||
|
||||
#[event(output = "UserProfile")]
|
||||
#[event(output = "UserProfilePB")]
|
||||
GetUserProfile = 5,
|
||||
|
||||
#[event(output = "UserProfile")]
|
||||
#[event(output = "UserProfilePB")]
|
||||
CheckUser = 6,
|
||||
|
||||
#[event(input = "AppearanceSettings")]
|
||||
#[event(input = "AppearanceSettingsPB")]
|
||||
SetAppearanceSetting = 7,
|
||||
|
||||
#[event(output = "AppearanceSettings")]
|
||||
#[event(output = "AppearanceSettingsPB")]
|
||||
GetAppearanceSetting = 8,
|
||||
}
|
||||
|
@ -7,9 +7,9 @@ use std::{convert::TryInto, sync::Arc};
|
||||
// tracing instrument 👉🏻 https://docs.rs/tracing/0.1.26/tracing/attr.instrument.html
|
||||
#[tracing::instrument(level = "debug", name = "sign_in", skip(data, session), fields(email = %data.email), err)]
|
||||
pub async fn sign_in(
|
||||
data: Data<SignInPayload>,
|
||||
data: Data<SignInPayloadPB>,
|
||||
session: AppData<Arc<UserSession>>,
|
||||
) -> DataResult<UserProfile, FlowyError> {
|
||||
) -> DataResult<UserProfilePB, FlowyError> {
|
||||
let params: SignInParams = data.into_inner().try_into()?;
|
||||
let user_profile = session.sign_in(params).await?;
|
||||
data_result(user_profile)
|
||||
@ -26,9 +26,9 @@ pub async fn sign_in(
|
||||
err
|
||||
)]
|
||||
pub async fn sign_up(
|
||||
data: Data<SignUpPayload>,
|
||||
data: Data<SignUpPayloadPB>,
|
||||
session: AppData<Arc<UserSession>>,
|
||||
) -> DataResult<UserProfile, FlowyError> {
|
||||
) -> DataResult<UserProfilePB, FlowyError> {
|
||||
let params: SignUpParams = data.into_inner().try_into()?;
|
||||
let user_profile = session.sign_up(params).await?;
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::entities::{
|
||||
AppearanceSettings, UpdateUserProfileParams, UpdateUserProfilePayload, UserProfile, APPEARANCE_DEFAULT_THEME,
|
||||
AppearanceSettingsPB, UpdateUserProfileParams, UpdateUserProfilePayloadPB, UserProfilePB, APPEARANCE_DEFAULT_THEME,
|
||||
};
|
||||
use crate::{errors::FlowyError, services::UserSession};
|
||||
use flowy_database::kv::KV;
|
||||
@ -13,13 +13,13 @@ pub async fn init_user_handler(session: AppData<Arc<UserSession>>) -> Result<(),
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(session))]
|
||||
pub async fn check_user_handler(session: AppData<Arc<UserSession>>) -> DataResult<UserProfile, FlowyError> {
|
||||
pub async fn check_user_handler(session: AppData<Arc<UserSession>>) -> DataResult<UserProfilePB, FlowyError> {
|
||||
let user_profile = session.check_user().await?;
|
||||
data_result(user_profile)
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(session))]
|
||||
pub async fn get_user_profile_handler(session: AppData<Arc<UserSession>>) -> DataResult<UserProfile, FlowyError> {
|
||||
pub async fn get_user_profile_handler(session: AppData<Arc<UserSession>>) -> DataResult<UserProfilePB, FlowyError> {
|
||||
let user_profile = session.get_user_profile().await?;
|
||||
data_result(user_profile)
|
||||
}
|
||||
@ -32,7 +32,7 @@ pub async fn sign_out(session: AppData<Arc<UserSession>>) -> Result<(), FlowyErr
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data, session))]
|
||||
pub async fn update_user_profile_handler(
|
||||
data: Data<UpdateUserProfilePayload>,
|
||||
data: Data<UpdateUserProfilePayloadPB>,
|
||||
session: AppData<Arc<UserSession>>,
|
||||
) -> Result<(), FlowyError> {
|
||||
let params: UpdateUserProfileParams = data.into_inner().try_into()?;
|
||||
@ -43,7 +43,7 @@ pub async fn update_user_profile_handler(
|
||||
const APPEARANCE_SETTING_CACHE_KEY: &str = "appearance_settings";
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(data), err)]
|
||||
pub async fn set_appearance_setting(data: Data<AppearanceSettings>) -> Result<(), FlowyError> {
|
||||
pub async fn set_appearance_setting(data: Data<AppearanceSettingsPB>) -> Result<(), FlowyError> {
|
||||
let mut setting = data.into_inner();
|
||||
if setting.theme.is_empty() {
|
||||
setting.theme = APPEARANCE_DEFAULT_THEME.to_string();
|
||||
@ -55,15 +55,15 @@ pub async fn set_appearance_setting(data: Data<AppearanceSettings>) -> Result<()
|
||||
}
|
||||
|
||||
#[tracing::instrument(err)]
|
||||
pub async fn get_appearance_setting() -> DataResult<AppearanceSettings, FlowyError> {
|
||||
pub async fn get_appearance_setting() -> DataResult<AppearanceSettingsPB, FlowyError> {
|
||||
match KV::get_str(APPEARANCE_SETTING_CACHE_KEY) {
|
||||
None => data_result(AppearanceSettings::default()),
|
||||
None => data_result(AppearanceSettingsPB::default()),
|
||||
Some(s) => {
|
||||
let setting = match serde_json::from_str(&s) {
|
||||
Ok(setting) => setting,
|
||||
Err(e) => {
|
||||
tracing::error!("Deserialize AppearanceSettings failed: {:?}, fallback to default", e);
|
||||
AppearanceSettings::default()
|
||||
AppearanceSettingsPB::default()
|
||||
}
|
||||
};
|
||||
data_result(setting)
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::entities::{SignInResponse, SignUpResponse, UpdateUserProfileParams, UserProfile};
|
||||
use crate::entities::{SignInResponse, SignUpResponse, UpdateUserProfileParams, UserProfilePB};
|
||||
use flowy_database::ConnectionPool;
|
||||
use flowy_database::{schema::user_table, DBConnection, Database};
|
||||
use flowy_error::{ErrorCode, FlowyError};
|
||||
@ -113,9 +113,9 @@ impl std::convert::From<SignInResponse> for UserTable {
|
||||
}
|
||||
}
|
||||
|
||||
impl std::convert::From<UserTable> for UserProfile {
|
||||
impl std::convert::From<UserTable> for UserProfilePB {
|
||||
fn from(table: UserTable) -> Self {
|
||||
UserProfile {
|
||||
UserProfilePB {
|
||||
id: table.id,
|
||||
email: table.email,
|
||||
name: table.name,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::entities::UserProfile;
|
||||
use crate::entities::UserProfilePB;
|
||||
use tokio::sync::{broadcast, mpsc};
|
||||
|
||||
#[derive(Clone)]
|
||||
@ -14,7 +14,7 @@ pub enum UserStatus {
|
||||
token: String,
|
||||
},
|
||||
SignUp {
|
||||
profile: UserProfile,
|
||||
profile: UserProfilePB,
|
||||
ret: mpsc::Sender<()>,
|
||||
},
|
||||
}
|
||||
@ -42,7 +42,7 @@ impl UserNotifier {
|
||||
});
|
||||
}
|
||||
|
||||
pub(crate) fn notify_sign_up(&self, ret: mpsc::Sender<()>, user_profile: &UserProfile) {
|
||||
pub(crate) fn notify_sign_up(&self, ret: mpsc::Sender<()>, user_profile: &UserProfilePB) {
|
||||
let _ = self.user_status_notifier.send(UserStatus::SignUp {
|
||||
profile: user_profile.clone(),
|
||||
ret,
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::entities::{
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfile,
|
||||
SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserProfileParams, UserProfilePB,
|
||||
};
|
||||
use crate::{
|
||||
dart_notification::*,
|
||||
@ -80,7 +80,7 @@ impl UserSession {
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self))]
|
||||
pub async fn sign_in(&self, params: SignInParams) -> Result<UserProfile, FlowyError> {
|
||||
pub async fn sign_in(&self, params: SignInParams) -> Result<UserProfilePB, FlowyError> {
|
||||
if self.is_user_login(¶ms.email) {
|
||||
self.get_user_profile().await
|
||||
} else {
|
||||
@ -88,14 +88,14 @@ impl UserSession {
|
||||
let session: Session = resp.clone().into();
|
||||
let _ = self.set_session(Some(session))?;
|
||||
let user_table = self.save_user(resp.into()).await?;
|
||||
let user_profile: UserProfile = user_table.into();
|
||||
let user_profile: UserProfilePB = user_table.into();
|
||||
self.notifier.notify_login(&user_profile.token, &user_profile.id);
|
||||
Ok(user_profile)
|
||||
}
|
||||
}
|
||||
|
||||
#[tracing::instrument(level = "debug", skip(self))]
|
||||
pub async fn sign_up(&self, params: SignUpParams) -> Result<UserProfile, FlowyError> {
|
||||
pub async fn sign_up(&self, params: SignUpParams) -> Result<UserProfilePB, FlowyError> {
|
||||
if self.is_user_login(¶ms.email) {
|
||||
self.get_user_profile().await
|
||||
} else {
|
||||
@ -103,7 +103,7 @@ impl UserSession {
|
||||
let session: Session = resp.clone().into();
|
||||
let _ = self.set_session(Some(session))?;
|
||||
let user_table = self.save_user(resp.into()).await?;
|
||||
let user_profile: UserProfile = user_table.into();
|
||||
let user_profile: UserProfilePB = user_table.into();
|
||||
let (ret, mut tx) = mpsc::channel(1);
|
||||
self.notifier.notify_sign_up(ret, &user_profile);
|
||||
|
||||
@ -143,7 +143,7 @@ impl UserSession {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn check_user(&self) -> Result<UserProfile, FlowyError> {
|
||||
pub async fn check_user(&self) -> Result<UserProfilePB, FlowyError> {
|
||||
let (user_id, token) = self.get_session()?.into_part();
|
||||
|
||||
let user = dsl::user_table
|
||||
@ -154,7 +154,7 @@ impl UserSession {
|
||||
Ok(user.into())
|
||||
}
|
||||
|
||||
pub async fn get_user_profile(&self) -> Result<UserProfile, FlowyError> {
|
||||
pub async fn get_user_profile(&self) -> Result<UserProfilePB, FlowyError> {
|
||||
let (user_id, token) = self.get_session()?.into_part();
|
||||
let user = dsl::user_table
|
||||
.filter(user_table::id.eq(&user_id))
|
||||
|
@ -1,13 +1,13 @@
|
||||
use crate::helper::*;
|
||||
use flowy_test::{event_builder::UserModuleEventBuilder, FlowySDKTest};
|
||||
use flowy_user::entities::{SignInPayload, SignUpPayload, UserProfile};
|
||||
use flowy_user::entities::{SignInPayloadPB, SignUpPayloadPB, UserProfilePB};
|
||||
use flowy_user::{errors::ErrorCode, event_map::UserEvent::*};
|
||||
|
||||
#[tokio::test]
|
||||
async fn sign_up_with_invalid_email() {
|
||||
for email in invalid_email_test_case() {
|
||||
let sdk = FlowySDKTest::default();
|
||||
let request = SignUpPayload {
|
||||
let request = SignUpPayloadPB {
|
||||
email: email.to_string(),
|
||||
name: valid_name(),
|
||||
password: login_password(),
|
||||
@ -29,7 +29,7 @@ async fn sign_up_with_invalid_email() {
|
||||
async fn sign_up_with_invalid_password() {
|
||||
for password in invalid_password_test_case() {
|
||||
let sdk = FlowySDKTest::default();
|
||||
let request = SignUpPayload {
|
||||
let request = SignUpPayloadPB {
|
||||
email: random_email(),
|
||||
name: valid_name(),
|
||||
password,
|
||||
@ -50,7 +50,7 @@ async fn sign_in_success() {
|
||||
let _ = UserModuleEventBuilder::new(test.clone()).event(SignOut).sync_send();
|
||||
let sign_up_context = test.sign_up().await;
|
||||
|
||||
let request = SignInPayload {
|
||||
let request = SignInPayloadPB {
|
||||
email: sign_up_context.user_profile.email.clone(),
|
||||
password: sign_up_context.password.clone(),
|
||||
name: "".to_string(),
|
||||
@ -61,7 +61,7 @@ async fn sign_in_success() {
|
||||
.payload(request)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<UserProfile>();
|
||||
.parse::<UserProfilePB>();
|
||||
dbg!(&response);
|
||||
}
|
||||
|
||||
@ -69,7 +69,7 @@ async fn sign_in_success() {
|
||||
async fn sign_in_with_invalid_email() {
|
||||
for email in invalid_email_test_case() {
|
||||
let sdk = FlowySDKTest::default();
|
||||
let request = SignInPayload {
|
||||
let request = SignInPayloadPB {
|
||||
email: email.to_string(),
|
||||
password: login_password(),
|
||||
name: "".to_string(),
|
||||
@ -93,7 +93,7 @@ async fn sign_in_with_invalid_password() {
|
||||
for password in invalid_password_test_case() {
|
||||
let sdk = FlowySDKTest::default();
|
||||
|
||||
let request = SignInPayload {
|
||||
let request = SignInPayloadPB {
|
||||
email: random_email(),
|
||||
password,
|
||||
name: "".to_string(),
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::helper::*;
|
||||
use flowy_test::{event_builder::UserModuleEventBuilder, FlowySDKTest};
|
||||
use flowy_user::entities::{UpdateUserProfilePayload, UserProfile};
|
||||
use flowy_user::entities::{UpdateUserProfilePayloadPB, UserProfilePB};
|
||||
use flowy_user::{errors::ErrorCode, event_map::UserEvent::*};
|
||||
use nanoid::nanoid;
|
||||
|
||||
@ -24,7 +24,7 @@ async fn user_profile_get() {
|
||||
let user = UserModuleEventBuilder::new(test.clone())
|
||||
.event(GetUserProfile)
|
||||
.sync_send()
|
||||
.parse::<UserProfile>();
|
||||
.parse::<UserProfilePB>();
|
||||
assert_eq!(user_profile, user);
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ async fn user_update_with_name() {
|
||||
let sdk = FlowySDKTest::default();
|
||||
let user = sdk.init_user().await;
|
||||
let new_name = "hello_world".to_owned();
|
||||
let request = UpdateUserProfilePayload::new(&user.id).name(&new_name);
|
||||
let request = UpdateUserProfilePayloadPB::new(&user.id).name(&new_name);
|
||||
let _ = UserModuleEventBuilder::new(sdk.clone())
|
||||
.event(UpdateUserProfile)
|
||||
.payload(request)
|
||||
@ -43,7 +43,7 @@ async fn user_update_with_name() {
|
||||
.event(GetUserProfile)
|
||||
.assert_error()
|
||||
.sync_send()
|
||||
.parse::<UserProfile>();
|
||||
.parse::<UserProfilePB>();
|
||||
|
||||
assert_eq!(user_profile.name, new_name,);
|
||||
}
|
||||
@ -53,7 +53,7 @@ async fn user_update_with_email() {
|
||||
let sdk = FlowySDKTest::default();
|
||||
let user = sdk.init_user().await;
|
||||
let new_email = format!("{}@gmail.com", nanoid!(6));
|
||||
let request = UpdateUserProfilePayload::new(&user.id).email(&new_email);
|
||||
let request = UpdateUserProfilePayloadPB::new(&user.id).email(&new_email);
|
||||
let _ = UserModuleEventBuilder::new(sdk.clone())
|
||||
.event(UpdateUserProfile)
|
||||
.payload(request)
|
||||
@ -62,7 +62,7 @@ async fn user_update_with_email() {
|
||||
.event(GetUserProfile)
|
||||
.assert_error()
|
||||
.sync_send()
|
||||
.parse::<UserProfile>();
|
||||
.parse::<UserProfilePB>();
|
||||
|
||||
assert_eq!(user_profile.email, new_email,);
|
||||
}
|
||||
@ -72,7 +72,7 @@ async fn user_update_with_password() {
|
||||
let sdk = FlowySDKTest::default();
|
||||
let user = sdk.init_user().await;
|
||||
let new_password = "H123world!".to_owned();
|
||||
let request = UpdateUserProfilePayload::new(&user.id).password(&new_password);
|
||||
let request = UpdateUserProfilePayloadPB::new(&user.id).password(&new_password);
|
||||
|
||||
let _ = UserModuleEventBuilder::new(sdk.clone())
|
||||
.event(UpdateUserProfile)
|
||||
@ -86,7 +86,7 @@ async fn user_update_with_invalid_email() {
|
||||
let test = FlowySDKTest::default();
|
||||
let user = test.init_user().await;
|
||||
for email in invalid_email_test_case() {
|
||||
let request = UpdateUserProfilePayload::new(&user.id).email(&email);
|
||||
let request = UpdateUserProfilePayloadPB::new(&user.id).email(&email);
|
||||
assert_eq!(
|
||||
UserModuleEventBuilder::new(test.clone())
|
||||
.event(UpdateUserProfile)
|
||||
@ -104,7 +104,7 @@ async fn user_update_with_invalid_password() {
|
||||
let test = FlowySDKTest::default();
|
||||
let user = test.init_user().await;
|
||||
for password in invalid_password_test_case() {
|
||||
let request = UpdateUserProfilePayload::new(&user.id).password(&password);
|
||||
let request = UpdateUserProfilePayloadPB::new(&user.id).password(&password);
|
||||
|
||||
UserModuleEventBuilder::new(test.clone())
|
||||
.event(UpdateUserProfile)
|
||||
@ -118,7 +118,7 @@ async fn user_update_with_invalid_password() {
|
||||
async fn user_update_with_invalid_name() {
|
||||
let test = FlowySDKTest::default();
|
||||
let user = test.init_user().await;
|
||||
let request = UpdateUserProfilePayload::new(&user.id).name("");
|
||||
let request = UpdateUserProfilePayloadPB::new(&user.id).name("");
|
||||
UserModuleEventBuilder::new(test.clone())
|
||||
.event(UpdateUserProfile)
|
||||
.payload(request)
|
||||
|
Reference in New Issue
Block a user