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

44 lines
1.5 KiB
Rust
Raw Normal View History

2021-08-31 15:01:46 +00:00
mod server_api;
mod server_api_mock;
// #[cfg(feature = "http_server")]
pub(crate) mod ws_mock;
2021-08-31 15:01:46 +00:00
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,
services::user::ws_manager::FlowyWebSocket,
2021-09-01 14:50:22 +00:00
};
2021-12-05 08:39:41 +00:00
use backend_service::configuration::ClientServerConfiguration;
use lib_infra::future::ResultFuture;
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-12-05 08:39:41 +00:00
pub(crate) fn construct_user_server(config: &ClientServerConfiguration) -> Arc<dyn UserServerAPI + Send + Sync> {
2021-09-04 07:12:53 +00:00
if cfg!(feature = "http_server") {
2021-12-06 13:47:21 +00:00
Arc::new(UserHttpServer::new(config.clone()))
2021-09-04 07:12:53 +00:00
} else {
Arc::new(UserServerMock {})
2021-09-03 04:44:48 +00:00
}
2021-08-31 15:01:46 +00:00
}
pub(crate) fn local_web_socket() -> Arc<dyn FlowyWebSocket> {
if cfg!(debug_assertions) {
Arc::new(Arc::new(ws_mock::MockWebSocket::default()))
} else {
Arc::new(Arc::new(ws_mock::LocalWebSocket::default()))
}
}