mod.rs 1.1 KB

123456789101112131415161718192021222324252627282930
  1. mod server_api;
  2. mod server_api_mock;
  3. pub use server_api::*;
  4. pub use server_api_mock::*;
  5. use std::sync::Arc;
  6. pub(crate) type Server = Arc<dyn UserServerAPI + Send + Sync>;
  7. use crate::{
  8. entities::{SignInParams, SignInResponse, SignUpParams, SignUpResponse, UpdateUserParams, UserProfile},
  9. errors::UserError,
  10. };
  11. use backend_service::configuration::ClientServerConfiguration;
  12. use lib_infra::future::ResultFuture;
  13. pub trait UserServerAPI {
  14. fn sign_up(&self, params: SignUpParams) -> ResultFuture<SignUpResponse, UserError>;
  15. fn sign_in(&self, params: SignInParams) -> ResultFuture<SignInResponse, UserError>;
  16. fn sign_out(&self, token: &str) -> ResultFuture<(), UserError>;
  17. fn update_user(&self, token: &str, params: UpdateUserParams) -> ResultFuture<(), UserError>;
  18. fn get_user(&self, token: &str) -> ResultFuture<UserProfile, UserError>;
  19. fn ws_addr(&self) -> String;
  20. }
  21. pub(crate) fn construct_user_server(config: &ClientServerConfiguration) -> Arc<dyn UserServerAPI + Send + Sync> {
  22. if cfg!(feature = "http_server") {
  23. Arc::new(UserHttpServer::new(config.clone()))
  24. } else {
  25. Arc::new(UserServerMock {})
  26. }
  27. }