mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
44 lines
1.5 KiB
Rust
44 lines
1.5 KiB
Rust
mod server_api;
|
|
mod server_api_mock;
|
|
|
|
// #[cfg(feature = "http_server")]
|
|
pub(crate) mod ws_mock;
|
|
|
|
pub use server_api::*;
|
|
pub use server_api_mock::*;
|
|
|
|
use std::sync::Arc;
|
|
pub(crate) type Server = Arc<dyn UserServerAPI + Send + Sync>;
|
|
use crate::{
|
|
entities::{SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserParams, UserProfile},
|
|
errors::UserError,
|
|
services::user::ws_manager::FlowyWebSocket,
|
|
};
|
|
use backend_service::configuration::ClientServerConfiguration;
|
|
use lib_infra::future::ResultFuture;
|
|
|
|
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>;
|
|
fn get_user(&self, token: &str) -> ResultFuture<UserProfile, UserError>;
|
|
fn ws_addr(&self) -> String;
|
|
}
|
|
|
|
pub(crate) fn construct_user_server(config: &ClientServerConfiguration) -> Arc<dyn UserServerAPI + Send + Sync> {
|
|
if cfg!(feature = "http_server") {
|
|
Arc::new(UserHttpServer::new(config.clone()))
|
|
} else {
|
|
Arc::new(UserServerMock {})
|
|
}
|
|
}
|
|
|
|
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()))
|
|
}
|
|
}
|