sign_up.rs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. use crate::{
  2. entities::parser::*,
  3. errors::{ErrorBuilder, UserErrCode, UserError},
  4. };
  5. use flowy_derive::ProtoBuf;
  6. use std::convert::TryInto;
  7. #[derive(ProtoBuf, Default)]
  8. pub struct SignUpRequest {
  9. #[pb(index = 1)]
  10. pub email: String,
  11. #[pb(index = 2)]
  12. pub name: String,
  13. #[pb(index = 3)]
  14. pub password: String,
  15. }
  16. impl TryInto<SignUpParams> for SignUpRequest {
  17. type Error = UserError;
  18. fn try_into(self) -> Result<SignUpParams, Self::Error> {
  19. let email = UserEmail::parse(self.email).map_err(|e| ErrorBuilder::new(e).build())?;
  20. let password =
  21. UserPassword::parse(self.password).map_err(|e| ErrorBuilder::new(e).build())?;
  22. let name = UserName::parse(self.name).map_err(|e| ErrorBuilder::new(e).build())?;
  23. Ok(SignUpParams {
  24. email: email.0,
  25. name: name.0,
  26. password: password.0,
  27. })
  28. }
  29. }
  30. #[derive(ProtoBuf, Default)]
  31. pub struct SignUpParams {
  32. #[pb(index = 1)]
  33. pub email: String,
  34. #[pb(index = 2)]
  35. pub name: String,
  36. #[pb(index = 3)]
  37. pub password: String,
  38. }
  39. #[derive(ProtoBuf, Debug, Default)]
  40. pub struct SignUpResponse {
  41. #[pb(index = 1)]
  42. pub uid: String,
  43. #[pb(index = 2)]
  44. pub name: String,
  45. #[pb(index = 3)]
  46. pub email: String,
  47. }