AppFlowy/rust-lib/flowy-user/src/services/server/mod.rs

32 lines
1.1 KiB
Rust
Raw Normal View History

2021-08-31 15:01:46 +00:00
mod server_api;
mod server_api_mock;
pub use server_api::*;
pub use server_api_mock::*;
use std::sync::Arc;
2021-09-01 14:50:22 +00:00
pub(crate) type Server = Arc<dyn UserServerAPI + Send + Sync>;
use crate::{
2021-09-04 08:53:58 +00:00
entities::{SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserParams, UserProfile},
2021-09-01 14:50:22 +00:00
errors::UserError,
};
use flowy_infra::future::ResultFuture;
2021-09-27 15:23:23 +00:00
use flowy_net::config::ServerConfig;
2021-09-01 14:50:22 +00:00
pub trait UserServerAPI {
fn sign_up(&self, params: SignUpParams) -> ResultFuture<SignUpResponse, UserError>;
fn sign_in(&self, params: SignInParams) -> ResultFuture<SignInResponse, UserError>;
fn sign_out(&self, token: &str) -> ResultFuture<(), UserError>;
fn update_user(&self, token: &str, params: UpdateUserParams) -> ResultFuture<(), UserError>;
2021-09-04 08:53:58 +00:00
fn get_user(&self, token: &str) -> ResultFuture<UserProfile, UserError>;
2021-09-27 15:23:23 +00:00
fn ws_addr(&self) -> String;
2021-09-01 14:50:22 +00:00
}
2021-09-27 15:23:23 +00:00
pub(crate) fn construct_user_server(config: &ServerConfig) -> Arc<dyn UserServerAPI + Send + Sync> {
2021-09-04 07:12:53 +00:00
if cfg!(feature = "http_server") {
2021-09-27 15:23:23 +00:00
Arc::new(UserServer::new(config.clone()))
2021-09-04 07:12:53 +00:00
} else {
2021-09-27 15:23:23 +00:00
// Arc::new(UserServerMock {})
Arc::new(UserServer::new(config.clone()))
2021-09-03 04:44:48 +00:00
}
2021-08-31 15:01:46 +00:00
}